survparamsim {survParamSim}R Documentation

Simulation of parametric survival model

Description

The main function(s) to generate predicted survival using a model object generated with survival::survreg() function.

Usage

surv_param_sim(
  object,
  newdata,
  n.rep = 1000,
  censor.dur = NULL,
  coef.var = TRUE,
  na.warning = TRUE
)

surv_param_sim_resample(
  object,
  newdata,
  n.rep = 1000,
  censor.dur = NULL,
  n.resample,
  strat.resample = NULL,
  coef.var = TRUE,
  na.warning = TRUE
)

Arguments

object

A survreg class object. Currently accept exponential, lognormal, weibull, loglogistic, and gaussian distributions.

newdata

A required data frame for simulation that contain covariates in the survival model. It is required even if this is the same as the one used for survival::survreg function.

It also has to contain columns for survival information. These can be used in plot_km_pi() and plot_hr_pi() function as observed data. Survival information can be dummy data, but time need to be long enough so that simulated KM plot will be long enough for plot_km_pi() to draw simulated survival curves.

Subjects with NA for covariates in survreg model will be removed from the simulation and subsequent plotting of observed data.

n.rep

An integer defining numbers of parametric bootstrap runs

censor.dur

A two elements vector specifying duration of events censoring. Censoring time will be calculated with uniform distribution between two numbers. No censoring will be applied if NULL is provided.

coef.var

Boolean specifying whether parametric bootstrap are performed on survival model coefficients, based on variance-covariance matrix. If FALSE, prediction interval only reflects inherent variability from survival events.

na.warning

Boolean specifying whether warning will be shown if newdata contain subjects with missing model variables.

n.resample

Number of subjects for resampled simulations. If strat.resample is provided, this needs to be a vector of the length equal to the number of categories in the stratification variable.

strat.resample

String specifying stratification variable for resampling. Currently only one variable is allowed. If you need more than one, create a new variable e.g. by base::interaction()

Details

surv_param_sim() returns simulation using the provided subject in newdata as it is, while surv_param_sim_resample perform simulation based on resampled subjects from the dataset. The latter allows more flexibility in terms of simulating future trials with different number of subjects. Note that with surv_param_sim_resample(), there is no automatic safeguard to ensure certain number of subjects in each subgroup or treatment groups, which may result in inconsistent number of subjects per simulation or leads to Cox regression instability due to small N. Consider using stratified resampling in this case.

Currently we have not tested whether this function work for a survreg model with stratification variables.

Value

A survparamsim object that contains the original survreg class object, newdata, and a data frame for predicted survival profiles with the following columns:

Examples

library(survival)

fit.lung <- survreg(Surv(time, status) ~ sex + ph.ecog, data = lung)

object <- fit.lung
n.rep  <-  30
newdata <-
  tibble::as_tibble(dplyr::select(lung, time, status, sex, ph.ecog)) %>%
  tidyr::drop_na()
censor.dur <- c(200, 1100)

sim <- surv_param_sim(object, newdata, n.rep, censor.dur)




[Package survParamSim version 0.1.6 Index]