The main function(s) to generate predicted survival using a model object
generated with survival::survreg()
function.
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
)
A survreg
class object. Currently accept exponential,
lognormal, weibull, loglogistic, and gaussian distributions.
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.
An integer defining numbers of parametric bootstrap runs
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.
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.
Boolean specifying whether warning will be shown if
newdata
contain subjects with missing model variables.
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.
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()
A survparamsim
object that contains the original survreg
class
object, newdata, and a data frame for predicted survival profiles with the
following columns:
event: event status, 0=censored, 1=event
rep: ID for parametric bootstrap runs
subj: ID for subjects in newdata (currently original ID is not retained and subj is sequentially assigned as 1:nrow(newdata))
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.
# NOT RUN {
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)
# }
Run the code above in your browser using DataLab