royston_parmar() fits a flexible parametric model: a restricted cubic spline in log time on a
transformed survival scale, with the covariate effects added to it. With
\(u = \log t\), the model is
$$\eta(t \mid x) = s(u; \gamma) + x^\top \beta,$$
and the survival function is \(S(t \mid x) = g(\eta)\) for the link \(g\) of the scale.
Arguments
- formula
A formula with a right-censored
Surv()response on the left and the covariates on the right, such asSurv(time, status) ~ age + sex, or~ 1for no covariates. Factors are coded with treatment contrasts. The spline's intercept takes the place of the formula's.- data
A data frame holding the variables in
formula.- weights
Optional case weights, a column of
dataor a numeric vector.- subset
An optional expression selecting the rows of
datato use.- na.action
What to do with rows that have missing values. The default drops them.
- df
The spline's degrees of freedom, a whole number of at least 1: one more than the number of internal knots. The default is
3.- scale
"hazard"(the default, proportional hazards) or"odds"(proportional odds).- conf_level
The confidence level, between 0 and 1. The default is
0.95.- max_iter
The largest number of Newton-Raphson iterations. The default is
100.- tol
The convergence tolerance: iterations stop once the log-likelihood changes by less than
toltimes its size. The default is1e-10.
Value
A royston_parmar object. Use as.data.frame() for the coefficient table, coef() and
vcov() for the estimates and their variance, and predict() for survival, hazard, and
cumulative hazard curves, quantiles, and restricted means. logLik(), AIC(), BIC(), and
nobs() work as usual, with the number of events as the number of observations, as for
cox_ph().
The object also holds knots (on the log-time scale), scale, df, loglik, n,
n_event, iterations, and converged.
Details
scale = "hazard"(the default): \(S = \exp(-\exp(\eta))\), so \(\eta\) is the log cumulative hazard and \(\exp(\beta_j)\) is a hazard ratio, constant over time.scale = "odds": \(S = 1 / (1 + \exp(\eta))\), so \(\eta\) is the log odds of having had the event and \(\exp(\beta_j)\) is an odds ratio, constant over time. This suits groups whose survival curves converge rather than stay apart.
The spline has boundary knots at the smallest and largest log event times, and df - 1 internal
knots at evenly spaced quantiles of the log event times between them. It has df + 1 terms:
gamma0 (the intercept), gamma1 (the coefficient of \(u\)), and one term per internal knot.
With df = 1 the spline is linear in \(u\), so the model is a Weibull model on the hazard
scale and a log-logistic model on the odds scale. A larger df lets the baseline take more
shapes while the curves stay smooth.
The parameters are estimated by maximum likelihood with Newton-Raphson iterations, halving the
step whenever it lowers the likelihood or makes the spline decrease in time at an observed time.
The iterations start from a least squares fit of the spline to the Nelson-Aalen log cumulative
hazard (or the Kaplan-Meier log odds). The variance is the inverse of the observed information.
The log-likelihood is on the time scale, so it's comparable with aft() and parametric().
Examples
lung <- data.frame(
time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654, 728, 71, 567, 144,
613, 707, 61, 88),
status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2),
age = c(74, 68, 56, 57, 60, 74, 68, 71, 53, 61, 57, 68, 68, 60, 57, 67, 70, 63, 56, 57),
sex = c(1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1)
)
fit <- royston_parmar(Surv(time, status) ~ age + sex, data = lung, df = 2)
fit
#> <royston_parmar> Surv(time, status) ~ age + sex
#> Hazard scale (exp(coef) is a hazard ratio), df = 2. n = 20, events = 18
#>
#> estimate std_error statistic p_value
#> gamma0 -7.42769 3.94425 -1.8832 0.059678
#> gamma1 1.72830 0.63253 2.7324 0.006288
#> gamma2 0.13371 0.16345 0.8180 0.413331
#> age -0.04683 0.04176 -1.1213 0.262164
#> sex 0.17392 0.63920 0.2721 0.785550
#>
#> Knots (log time): 4.11, 5.73, 6.78
#> Log-likelihood: -127.668
# Survival curves for two new subjects
newdata <- data.frame(age = c(55, 70), sex = c(1, 2))
predict(fit, newdata = newdata, type = "survival", times = c(200, 400))
#> subject time estimate std_error conf_low conf_high
#> 1 1 200 0.6266311 0.1365864 0.31165862 0.8291258
#> 2 1 400 0.3029305 0.1508931 0.06688832 0.5901891
#> 3 2 200 0.7591790 0.1183871 0.43367697 0.9131450
#> 4 2 400 0.4946137 0.1793585 0.14485105 0.7737491
# A proportional odds model
royston_parmar(Surv(time, status) ~ age + sex, data = lung, df = 2, scale = "odds")
#> <royston_parmar> Surv(time, status) ~ age + sex
#> Odds scale (exp(coef) is an odds ratio), df = 2. n = 20, events = 18
#>
#> estimate std_error statistic p_value
#> gamma0 -4.27081 5.08143 -0.84047 0.400643
#> gamma1 2.02672 0.75932 2.66912 0.007605
#> gamma2 0.02094 0.22532 0.09294 0.925949
#> age -0.11281 0.07108 -1.58709 0.112492
#> sex -0.20667 0.99851 -0.20698 0.836029
#>
#> Knots (log time): 4.11, 5.73, 6.78
#> Log-likelihood: -126.825