flexsurvspline  R Documentation 
Flexible parametric modelling of timetoevent data using the spline model of Royston and Parmar (2002).
flexsurvspline( formula, data, weights, bhazard, rtrunc, subset, k = 0, knots = NULL, bknots = NULL, scale = "hazard", timescale = "log", ... )
formula 
A formula expression in conventional R linear modelling
syntax. The response must be a survival object as returned by the
specifies a model where the log cumulative hazard (by default, see
If there are no covariates, specify Timevarying covariate effects can be specified using the method described
in Therefore a model with one internal spline knot, where the equivalents of
the Weibull shape and scale parameters, but not the higherorder term
or alternatively (and more safely, see

data 
A data frame in which to find variables supplied in

weights 
Optional variable giving case weights. 
bhazard 
Optional variable giving expected hazards for relative survival models. 
rtrunc 
Optional variable giving individual righttruncation times (see 
subset 
Vector of integers or logicals specifying the subset of the observations to be used in the fit. 
k 
Number of knots in the spline. The default 
knots 
Locations of knots on the axis of log time (or time, see

bknots 
Locations of boundary knots, on the axis of log time (or
time, see 
scale 
If If If 
timescale 
If 
... 
Any other arguments to be passed to or through

This function works as a wrapper around flexsurvreg
by
dynamically constructing a custom distribution using
dsurvspline
, psurvspline
and
unroll.function
.
In the splinebased survival model of Royston and Parmar (2002), a transformation g(S(t,z)) of the survival function is modelled as a natural cubic spline function of log time x = log(t) plus linear effects of covariates z.
g(S(t,z)) = s(x, gamma) + beta^T z
The proportional hazards model (scale="hazard"
) defines
g(S(t,z)) = log(log(S(t,z))) = log(H(t,z)), the
log cumulative hazard.
The proportional odds model (scale="odds"
) defines
g(S(t,z)) = log(1/S(t,z)  1)g(S(t,z)) = log(1/S(t,z)  1), the log
cumulative odds.
The probit model (scale="normal"
) defines g(S(t,z)) = InvPhi(S(t,z))g(S(t,z))
= InvPhi(S(t,z)), where InvPhi() is the inverse normal
distribution function qnorm
.
With no knots, the spline reduces to a linear function, and these models are equivalent to Weibull, loglogistic and lognormal models respectively.
The spline coefficients gamma_j: j=1, 2 …, which are called the "ancillary parameters" above, may also be modelled as linear functions of covariates \mathbf{z}, as
gamma_j(z) = γ_{j0} + γ_{j1}z_1 + γ_{j2}z_2 + ...
giving a model where the effects of covariates are arbitrarily flexible functions of time: a nonproportional hazards or odds model.
Natural cubic splines are cubic splines constrained to be linear beyond boundary knots kmin,kmax. The spline function is defined as
s(x,gamma) = gamma0 + gamma1 x + gamma2 v1(x) + ... + gamma_{m+1} vm(x)
s(x,gamma) = gamma0 + gamma1 x + gamma2 v1(x) + ... + gamma_{m+1} vm(x)
where vj(x) is the jth basis function
vj(x) = (x  kj)^3_+  λ_j(x  kmin)^3_+  (1 λ_j) (x  kmax)^3_+
vj(x) = (x  kj)^3_+  λ_j(x  kmin)^3_+  (1 λ_j) (x  kmax)^3_+
λ_j = (kmax  kj) / (kmax  kmin)
and (x  a)_+ = max(0, x  a).
A list of class "flexsurvreg"
with the same elements as
described in flexsurvreg
, and including extra components
describing the spline model. See in particular:
k 
Number of knots. 
knots 
Location of knots on the log time axis. 
scale 
The 
res 
Matrix of maximum likelihood estimates and confidence limits.
Spline coefficients are labelled Coefficients In the Weibull model, for example, In the loglogistic model with shape In the lognormal model with logscale mean 
loglik 
The maximised loglikelihood. This will differ from Stata, where the sum of the log uncensored survival times is added to the loglikelihood in survival models, to remove dependency on the time scale. 
Christopher Jackson <chris.jackson@mrcbsu.cam.ac.uk>
Royston, P. and Parmar, M. (2002). Flexible parametric proportionalhazards and proportionalodds models for censored survival data, with application to prognostic modelling and estimation of treatment effects. Statistics in Medicine 21(1):21752197.
Jackson, C. (2016). flexsurv: A Platform for Parametric Survival Modeling in R. Journal of Statistical Software, 70(8), 133. doi:10.18637/jss.v070.i08
flexsurvreg
for flexible survival modelling using
general parametric distributions.
plot.flexsurvreg
and lines.flexsurvreg
to plot
fitted survival, hazards and cumulative hazards from models fitted by
flexsurvspline
and flexsurvreg
.
## Bestfitting model to breast cancer data from Royston and Parmar (2002) ## One internal knot (2 df) and cumulative odds scale spl < flexsurvspline(Surv(recyrs, censrec) ~ group, data=bc, k=1, scale="odds") ## Fitted survival plot(spl, lwd=3, ci=FALSE) ## Simple Weibull model fits much less well splw < flexsurvspline(Surv(recyrs, censrec) ~ group, data=bc, k=0, scale="hazard") lines(splw, col="blue", ci=FALSE) ## Alternative way of fitting the Weibull ## Not run: splw2 < flexsurvreg(Surv(recyrs, censrec) ~ group, data=bc, dist="weibull") ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.