
Survival Curves and Median Survival Times for the Levels of a Term
Source:R/survmeans.R
survmeans.RdFor a Cox model (survival::coxph) or an accelerated failure time model (survival::survreg), the
survival curve S(t) of each level of modelterm with pointwise confidence limits, and the median survival
time with its limits.
Arguments
- model
A
coxphorsurvregfit, or abrmsfitof a survival family.- modelterm
A factor of the model, or an interaction of factors (
"A:B"), whose levels get a curve.- at
A named list: levels of the other factors (one each), or values of numeric covariates.
- times
The times at which to give S(t). Default:
coxph, every time of the data (events and censorings) up to the last;survreg, 101 points from 0 to the largest time.- conf_level
The confidence level of the limits.
- data
The data the model was fitted to, when they cannot be found.
- marginal
Bayesian fits only (
brmswith aweibull(),lognormal()orexponential()family):FALSEgives the curves of a typical cluster (random effects at zero),TRUEthe curves averaged over the random effects of each draw (the survival of the population). A Bayesian fit's curves and medians are posterior medians of each draw's S(t) and median, with equal-tailed pointwise limits. brmscox(): S(t) = exp(-H0(t) exp(eta)) with H0 the integrated spline baseline hazard of each draw (the curves stop at the spline's upper boundary); medians whose draws partly lie beyond it are given when fewer than half do, with their share in columnbeyond. Not available: a shape or sigma modelled by predictors. With random slopes the variance at each pattern row is z' Sigma z. The average over the random effects is the checked quadrature ofbias_adjust(Gauss-Hermite, then the trapezoid rule in z, then adaptive integration, until two rules agree to 1e-8).- object
A
survmeans()result.- limits
Draw the pointwise limits as bands.
- ...
Not used.
- x
A
survmeans()result, forplot(): it drawsautoplot()and returns it invisibly.
Value
An object of class pm_survmeans: curves (the levels, time, surv,
conf.low, conf.high), medians (the levels, median, conf.low,
conf.high; NA when the curve does not fall to 0.5) and settings (the pattern of the other
variables, the method). autoplot() draws the curves.
Details
Each curve is that of one covariate pattern: the level of modelterm, numeric covariates at their means
(as predictmeans), and the other factors at the levels in at (by default their first
level, with a message). A curve averaged over the levels of another factor would need the covariance between
curves; it is not given, so that no limits are approximate. Give the factor in modelterm to see a curve
for each of its levels.
coxph:survival::survfit()with that pattern asnewdata(the Breslow or Efron estimate of the baseline hazard of the fit, and its variance); in a stratified model the strata factor is one of the pattern (inmodeltermorat), and each curve uses the baseline hazard of its stratum. The curves stop (NA) after the last follow-up time of the data (of the stratum). The median and its limits are those ofquantile()of the curve.survreg: S(t) = 1 - F((log t - eta) / sigma) for the fitted distribution, with the delta method over the coefficients and log(sigma); the median is exp(eta + sigma q50). Distributions on the log-time scale only, and one scale (nostrata()).
The limits are on the log survival scale (conf.type = "log", as survfit()'s default), at
conf_level; they are pointwise, not a band for the whole curve.
See also
predictmeans for hazard ratios and time ratios between the levels.
Examples
library(survival)
lung2 <- na.omit(lung[, c("time", "status", "ph.ecog", "sex", "age")])
lung2$ecog <- factor(lung2$ph.ecog)
lung2$sex <- factor(lung2$sex)
sm <- survmeans(coxph(Surv(time, status) ~ ecog + sex + age, data = lung2), "ecog",
at = list(sex = "2"))
sm$medians
#> ecog median conf.low conf.high
#> 1 0 567 433 814
#> 2 1 394 337 567
#> 3 2 288 218 426
#> 4 3 147 60 NA
ggplot2::autoplot(sm)