chjackson / flexsurv

The flexsurv R package for flexible parametric survival and multi-state modelling
http://chjackson.github.io/flexsurv/
54 stars 28 forks source link

support for broom #71

Closed kkmann closed 4 years ago

kkmann commented 4 years ago

Hi Chris,

I find the broom package tremendously useful for model comparisons etc.

Would be very helpful to implement methods for the glance etc generics for flexsurvreg objects.

chjackson commented 4 years ago

Been meaning to do this for ages. Do these look OK?

tidy.flexsurvreg <- function(x, transform=FALSE, ...){
    res <- if (transform) x$res.t else x$res
    broom::fix_data_frame(res, newnames=c("estimate","conf.low","conf.high","std.error"))
}

glance.flexsurvreg <- function(x, ...){
    data.frame(
    logLik = x$loglik,
    df = x$npars,
    nobs = x$N,
    AIC = x$AIC,
    BIC = -2*x$loglik + log(x$N)*x$npars
    )
}

Not sure what to do about augment, the concept of predict() for survival models is not obvious, see work in progress.

The output from summary.flexsurvreg functions can already be returned in a somewhat tidy format but maybe it could be improved.

kkmann commented 4 years ago

I'll try to understand the problem a bit better and whisk together a PR, might be better to discuss specifics there.

chjackson commented 4 years ago

Merged with #75