Learn R Programming

flexsurv (version 0.6)

flexsurvreg: Flexible parametric regression for time-to-event data

Description

Parametric modelling or regression for time-to-event data. Several built-in distributions are available, and users may supply their own.

Usage

flexsurvreg(formula, anc=NULL, data, weights, bhazard, subset,
            na.action, dist, inits, fixedpars=NULL, dfns=NULL, aux=NULL,
            cl=0.95, integ.opts, sr.control=survreg.control(), ...)

Arguments

formula
A formula expression in conventional R linear modelling syntax. The response must be a survival object as returned by the Surv function, and any covariates are given on the right-hand side. For
anc
An alternative and safer way to model covariates on ancillary parameters, that is, parameters other than the main location parameter of the distribution. This is a named list of formulae, with the name of each component giving the paramete
data
A data frame in which to find variables supplied in formula. If not given, the variables should be in the working environment.
weights
Optional variable giving case weights.
bhazard
Optional variable giving expected hazards for relative survival models.
subset
Vector of integer or logicals specifying the subset of the observations to be used in the fit.
na.action
a missing-data filter function, applied after any 'subset' argument has been used. Default is options()$na.action.
dist
Typically, one of the strings in the first column of the following table, identifying a built-in distribution. This table also identifies the location parameters, and whether covariates on these parameters represent a proportional hazards (
inits
An optional numeric vector giving initial values for each unknown parameter. These are numbered in the order: baseline parameters (in the order they appear in the distribution function, e.g. shape before scale in the Weibull), covariate eff
fixedpars
Vector of indices of parameters whose values will be fixed at their initial values during the optimisation. The indices are ordered as in inits. For example, in a stable generalized Gamma model with two covariates, to fi
dfns
An alternative way to define a custom survival distribution (see section ``Custom distributions'' below). A list whose components may include "d", "p", "h", or "H" containing th
aux
A named list of other arguments to pass to custom distribution functions. This is used, for example, by flexsurvspline to supply the knot locations and modelling scale (e.g. hazard o
cl
Width of symmetric confidence intervals for maximum likelihood estimates, by default 0.95.
integ.opts
List of named arguments to pass to integrate, if a custom density or hazard is provided without its cumulative version. For example, integ.opts = list(rel.tol=1e-12)
sr.control
For the models which use survreg to find the maximum likelihood estimates (Weibull, exponential, log-normal), this list is passed as the control argument to
...
Optional arguments to the general-purpose Roptimisation routine optim. For example, the BFGS optimisation algorithm is the default in flexsurvreg,

Value

  • A list of class "flexsurvreg" containing information about the fitted model. Components of interest to users may include:
  • callA copy of the function call, for use in post-processing.
  • dlistList defining the survival distribution used.
  • resMatrix of maximum likelihood estimates and confidence limits, with parameters on their natural scales.
  • res.tMatrix of maximum likelihood estimates and confidence limits, with parameters all transformed to the real line. The coef, vcov and confint methods for flexsurvreg objects work on this scale.
  • loglikLog-likelihood
  • AICAkaike's information criterion (-2*log likelihood + 2*number of estimated parameters)
  • covCovariance matrix of the parameters, on the real-line scale (e.g. log scale), which can be extracted with vcov.
  • dataData used in the model fit. To extract this in the standard R formats, use use model.frame.flexsurvreg or model.matrix.flexsurvreg.

encoding

latin1

Details

Parameters are estimated by maximum likelihood using the algorithms available in the standard R optim function. Parameters defined to be positive are estimated on the log scale. Confidence intervals are estimated from the Hessian at the maximum, and transformed back to the original scale of the parameters. The usage of flexsurvreg is intended to be similar to survreg in the survival package.

References

Jackson, C. H. and Sharples, L. D. and Thompson, S. G. (2010) Survival models in health economic evaluations: balancing fit and parsimony to improve prediction. International Journal of Biostatistics 6(1):Article 34. Cox, C. (2008) The generalized $F$ distribution: An umbrella for parametric survival analysis. Statistics in Medicine 27:4301-4312. Cox, C., Chu, H., Schneider, M. F. and Mu�oz, A. (2007) Parametric survival analysis and taxonomy of hazard functions for the generalized gamma distribution. Statistics in Medicine 26:4252-4374

See Also

flexsurvspline for flexible survival modelling using the spline model of Royston and Parmar. plot.flexsurvreg and lines.flexsurvreg to plot fitted survival, hazards and cumulative hazards from models fitted by flexsurvreg and flexsurvspline.

Examples

Run this code
data(ovarian)
## Compare generalized gamma fit with Weibull
fitg <- flexsurvreg(formula = Surv(futime, fustat) ~ 1, data = ovarian, dist="gengamma")
fitg
fitw <- flexsurvreg(formula = Surv(futime, fustat) ~ 1, data = ovarian, dist="weibull")
fitw
plot(fitg)
lines(fitw, col="blue", lwd.ci=1, lty.ci=1)
## Identical AIC, probably not enough data in this simple example for a
## very flexible model to be worthwhile.

## Custom distribution
library(eha)  ## make "dEV" and "pEV" available to the working environment
custom.ev <- list(name="EV",
                      pars=c("shape","scale"),
                      location="scale",
                      transforms=c(log, log),
                      inv.transforms=c(exp, exp),
                      inits=function(t){ c(1, median(t)) })
fitev <- flexsurvreg(formula = Surv(futime, fustat) ~ 1, data = ovarian,
                    dist=custom.ev)
fitev
lines(fitev, col="purple", col.ci="purple")

## Custom distribution: supply the hazard function only
hexp2 <- function(x, rate=1){ rate } # exponential distribution
hexp2 <- Vectorize(hexp2)
custom.exp2 <- list(name="exp2", pars=c("rate"), location="rate",
                    transforms=c(log), inv.transforms=c(exp),
                    inits=function(t)1/mean(t))
flexsurvreg(Surv(futime, fustat) ~ 1, data = ovarian, dist=custom.exp2)
flexsurvreg(Surv(futime, fustat) ~ 1, data = ovarian, dist="exp")
## should give same answer

Run the code above in your browser using DataLab