Skip to contents

Constructs a prediction function that estimates the survival probability at a specified time horizon \(\tau\) from a fitted model, and computes its standard error and Wald confidence interval using the delta method.

Usage

deltamethod_from_model(model, tau, naive = FALSE)

Arguments

model

A fitted model object. Supported types are survival::survreg() with log-logistic distribution and mets::logitIPCW().

tau

Numeric scalar. The time horizon at which the survival probability is to be estimated.

naive

Logical. If TRUE, use the naive variance estimator for binreg models. If FALSE (default), use the robust variance estimator.

Value

A function(df, z = 1.96) that takes a data frame of covariates df and returns a data frame with columns for the prediction prediction, lower lower and upper upper Wald confidence intervals, and standard error se. The function can also take an optional argument z for the z-score used in confidence interval calculation (default is 1.96 for 95% confidence intervals).

Details

The function supports models of from survival::survreg() (Therneau 2024) with log-logistic distribution and models of class binreg (such as those fitted by mets::logitIPCW()) (Blanche et al. 2023; Holst et al. 2016; Scheike et al. 2014) . For binreg models, the function can use either the naive or the robust variance estimator, depending on the value of the naive argument.

References

Blanche PF, Holt A, Scheike T (2023). “On logistic regression with right censored data, with or without competing risks, and its use for estimating treatment effects.” Lifetime Data Analysis, 29(2), 441–482. ISSN 1380-7870, doi:10.1007/s10985-022-09564-6 .

Holst KK, Scheike TH, Hjelmborg JB (2016). “The Liability Threshold Model for Censored Twin Data.” Computational Statistics and Data Analysis, 93, 324-335. doi:10.1016/j.csda.2015.01.014 .

Scheike TH, Holst KK, B.Hjelmborg J (2014). “Estimating heritability for cause specific mortality based on twin studies.” Lifetime Data Analysis, 20(2), 210-233. doi:10.1007/s10985-013-9244-x .

Therneau TM (2024). A Package for Survival Analysis in R. R package version 3.8-3.

See also

deltamethod_pred_function() for the underlying implementation and IPCWJK for confidence interval calculation

Examples

library(survival)
tau <- 100
df <- veteran[, c("time", "status", "trt")]
newdata <- data.frame(trt = c(1, 2))

# Fit a log-logistic survival model
survreg_fit <- survreg(Surv(time, status) ~ trt,
  data = df,
  dist = "loglogistic"
)
pred_fun <- deltamethod_from_model(survreg_fit, tau = tau)
pred_fun(newdata)
#>   prediction     lower     upper         se
#> 1  0.4132020 0.3125587 0.5138454 0.05134864
#> 2  0.3461551 0.2489699 0.4433402 0.04958424

# Fit a logitIPCW model
library(mets)
logipcw_fit <- logitIPCW(Event(time, status) ~ trt, time = tau, data = df)
predfun_logit <- deltamethod_from_model(logipcw_fit, tau = tau)
pred_fun(newdata)
#>   prediction     lower     upper         se
#> 1  0.4132020 0.3125587 0.5138454 0.05134864
#> 2  0.3461551 0.2489699 0.4433402 0.04958424