Title: | Parametric Survival Simulation with Parameter Uncertainty |
---|---|
Description: | Perform survival simulation with parametric survival model generated from 'survreg' function in 'survival' package. In each simulation coefficients are resampled from variance-covariance matrix of parameter estimates to capture uncertainty in model parameters. Prediction intervals of Kaplan-Meier estimates and hazard ratio of treatment effect can be further calculated using simulated survival data. |
Authors: | Kenta Yoshida [aut, cre] |
Maintainer: | Kenta Yoshida <[email protected]> |
License: | GPL-3 |
Version: | 0.1.6.9000 |
Built: | 2025-02-15 04:41:50 UTC |
Source: | https://github.com/yoshidk6/survparamsim |
Generate hazard ratio with prediction intervals from parametric bootstrap simulation
calc_ave_hr_pi( sim, trt, group = NULL, pi.range = 0.95, calc.obs = TRUE, trt.assign = c("default", "reverse"), simtimelast = NULL, boot.subj = TRUE ) calc_hr_pi( sim, trt, group = NULL, pi.range = 0.95, calc.obs = TRUE, trt.assign = c("default", "reverse") )
calc_ave_hr_pi( sim, trt, group = NULL, pi.range = 0.95, calc.obs = TRUE, trt.assign = c("default", "reverse"), simtimelast = NULL, boot.subj = TRUE ) calc_hr_pi( sim, trt, group = NULL, pi.range = 0.95, calc.obs = TRUE, trt.assign = c("default", "reverse") )
sim |
A |
trt |
A string to specify which column define treatment status to calculate HR. |
group |
Optional string(s) to specify grouping variable(s).
You will have faceted histograms for these variables in |
pi.range |
Prediction interval for simulated HR. |
calc.obs |
A logical to specify whether to calculate HR for the observed data.
Need be set as FALSE if survival information in the |
trt.assign |
Specify which of the categories of |
simtimelast |
An optional numeric to specify duration for average HR calculation.
If NULL (default), the last observation time in the |
boot.subj |
Boolean to specify whether bootstrapping of subjects are performed before calculating HR. Default TRUE. |
calc_hr_pi()
calculate hazard ratio using the simulated survival times with Cox proportional hazard
model, while calc_ave_hr_pi()
calculate "average" hazard ratio using the mean survival & probability
density function per treatment groups.
If your trt
has more than two categories/levels and want to specify which one to use as a
reference group, you can convert the column into a factor in the newdata
input for
surv_param_sim()
. The first level will be used as a reference group.
Generate Kaplan-Meier curves with prediction intervals using simulated survival time
calc_ave_km_pi( sim, trt = NULL, group = NULL, pi.range = 0.95, calc.obs = TRUE, simtimelast = NULL, trt.assign = c("default", "reverse"), boot.subj = TRUE, calc.median.surv = FALSE ) calc_km_pi( sim, trt = NULL, group = NULL, pi.range = 0.95, calc.obs = TRUE, simtimelast = NULL, trt.assign = c("default", "reverse") )
calc_ave_km_pi( sim, trt = NULL, group = NULL, pi.range = 0.95, calc.obs = TRUE, simtimelast = NULL, trt.assign = c("default", "reverse"), boot.subj = TRUE, calc.median.surv = FALSE ) calc_km_pi( sim, trt = NULL, group = NULL, pi.range = 0.95, calc.obs = TRUE, simtimelast = NULL, trt.assign = c("default", "reverse") )
sim |
A |
trt |
An optional string to specify which column define treatment status.
You will have survival curves with different colors in |
group |
Optional string(s) to specify grouping variable(s).
You will have faceted survival curves for these variables in |
pi.range |
Prediction interval for simulated survival curves. |
calc.obs |
A logical to specify whether KM estimates will be performed
for the observed data. Need be set as FALSE if survival information in the |
simtimelast |
An optional numeric to specify last simulation time for survival curve.
If NULL (default), the last observation time in the |
trt.assign |
Specify which of the categories of |
boot.subj |
Boolean to specify whether bootstrapping of subjects are performed before calculating HR. Default TRUE. |
calc.median.surv |
Whether to calculate median survival time for
|
calc_km_pi()
calculate survival profile using the simulated survival times with
Kaplan-Meier estimates, while calc_ave_km_pi()
calculate "average" survival
using the mean survival function per treatment groups. calc_ave_km_pi()
actually
does not rely on Kaplan-Meier estimates as it directly uses the underlying
parametric survival model, however the function has km
for naming consistency.
If your trt
has more than two categories/levels and want to specify which one to use as a
reference group, you can convert the column into a factor in the newdata
input for
surv_param_sim()
. The first level will be used as a reference group.
extract_median_surv(km.pi, outtype = c("long", "wide"))
extract_median_surv(km.pi, outtype = c("long", "wide"))
km.pi |
A return object from |
outtype |
Specifies whether output will be in long or wide format. |
extract_median_surv()
was renamed to extract_medsurv_pi()
for function name consistency.
extract_median_surv()
extracts prediction intervals of
median survival times and and the corresponding observed values.
Functions to extract prediction intervals and observed data
extract_hr_pi(hr.pi, outtype = c("long", "wide")) extract_km_pi(km.pi, trunc.sim.censor = TRUE) extract_medsurv_pi(km.pi, outtype = c("long", "wide")) extract_medsurv_delta_pi(km.pi, outtype = c("long", "wide"))
extract_hr_pi(hr.pi, outtype = c("long", "wide")) extract_km_pi(km.pi, trunc.sim.censor = TRUE) extract_medsurv_pi(km.pi, outtype = c("long", "wide")) extract_medsurv_delta_pi(km.pi, outtype = c("long", "wide"))
hr.pi |
a return object from |
outtype |
Specifies whether output will be in long or wide format. |
km.pi |
A return object from |
trunc.sim.censor |
A logical specifying whether to truncate the simulated
curve at the last time of |
extract_hr_pi()
extracts prediction intervals of simulated
hazard ratios and the corresponding observed values.
extract_km_pi()
extracts prediction intervals of simulated Kaplan-Meier curves.
extract_medsurv_pi()
extracts prediction intervals of
median survival times and and the corresponding observed values.
extract_medsurv_delta_pi()
extracts prediction intervals of
delta of median survival times between treatment groups
Functions to extract raw simulated samples
extract_sim(sim) extract_hr(hr.pi) extract_km_obs(km.pi) extract_medsurv(km.pi) extract_medsurv_delta(km.pi)
extract_sim(sim) extract_hr(hr.pi) extract_km_obs(km.pi) extract_medsurv(km.pi) extract_medsurv_delta(km.pi)
sim |
A |
hr.pi |
a return object from |
km.pi |
A return object from |
extract_sim()
extracts raw survival time & event status for all simulated subjects.
extract_hr()
extracts simulated HR for all repeated simulations.
If HR was calculated based on simulated survival times with
calc_hr_pi()
function, it also returns p values for Cox regression
fits, one for each group
based on Wald test and another for the overall significance of the
coefficient based on logrank test. The latter has the same values
across treatment groups when >2 levels in treatment
extract_km_obs()
extracts observed Kaplan-Meier curves.
extract_medsurv()
extracts simulated median survival times for all repeated simulations
extract_medsurv_delta()
extracts delta of median survival times between treatment groups
Plot simulated HR histogram(s) overlayed with prediction intervals
plot_hr_pi(hr.pi, show.obs = TRUE)
plot_hr_pi(hr.pi, show.obs = TRUE)
hr.pi |
a return object from |
show.obs |
A logical specifying whether to show observed HR on the plot.
This will have no effect if |
Need to think about how to apply this for subgroups
plot_km_pi(km.pi, show.obs = TRUE, trunc.sim.censor = TRUE)
plot_km_pi(km.pi, show.obs = TRUE, trunc.sim.censor = TRUE)
km.pi |
an output from |
show.obs |
A logical specifying whether to show observed K-M curve on the plot.
This will have no effect if |
trunc.sim.censor |
A logical specifying whether to truncate the simulated
curve at the last time of |
Methods for S3 objects in the package
## S3 method for class 'survparamsim.hrpi' print(x, ...) ## S3 method for class 'survparamsim.hrpi' summary(object, ...) ## S3 method for class 'survparamsim.kmpi' print(x, ...) ## S3 method for class 'survparamsim.kmpi' summary(object, ...) ## S3 method for class 'survparamsim' print(x, ...)
## S3 method for class 'survparamsim.hrpi' print(x, ...) ## S3 method for class 'survparamsim.hrpi' summary(object, ...) ## S3 method for class 'survparamsim.kmpi' print(x, ...) ## S3 method for class 'survparamsim.kmpi' summary(object, ...) ## S3 method for class 'survparamsim' print(x, ...)
x |
An object of the corresponding class |
... |
Additional arguments passed to methods. |
object |
An object of the corresponding class |
Simulation of parametric survival model with an already-resampled dataset
surv_param_sim_pre_resampled( object, newdata.resampled, newdata.orig = NULL, censor.dur = NULL, coef.var = TRUE, na.warning = TRUE )
surv_param_sim_pre_resampled( object, newdata.resampled, newdata.orig = NULL, censor.dur = NULL, coef.var = TRUE, na.warning = TRUE )
object |
A |
newdata.resampled |
A required input, the already resampled dataset for simulation.
This dataset must have: (a) |
newdata.orig |
An optional input needed for calculating KM and HR for the observed data. |
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
|
See surv_param_sim()
for additional details.
A survparamsim
object that contains the original survreg
class
object, newdata, and a data frame for predicted survival profiles.
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 )
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 )
object |
A |
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 Subjects with NA for covariates in |
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
|
n.resample |
Number of subjects for resampled simulations.
If |
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 |
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.
A survparamsim
object that contains the original survreg
class
object, newdata, and a data frame for predicted survival profiles with the
following columns:
time: predicted event or censor time
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))
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)
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)