survParamSim v0.1.0

0

Monthly downloads

0th

Percentile

Parametric Survival Simulation with Parameter Uncertainty

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.

Readme

survParamSim

Travis build
status

The goal of survParamSim is to 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, in order to capture uncertainty in model parameters.

Installation

You can install the package from GitHub using devtools.

install.packages("devtools")
devtools::install_git("https://github.com/yoshidk6/survParamSim")

Example

This GitHub pages contains function references and vignette. The example below is a sneak peek of example outputs.

First, run survreg to fit parametric survival model:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggplot2)
library(survival)
library(survParamSim)

set.seed(12345)

# ref for dataset https://vincentarelbundock.github.io/Rdatasets/doc/survival/colon.html
colon2 <- 
  as_tibble(colon) %>% 
  # recurrence only and not including Lev alone arm
  filter(rx != "Lev",
         etype == 1) %>% 
  # Same definition as Lin et al, 1994
  mutate(rx = factor(rx, levels = c("Obs", "Lev+5FU")),
         depth = as.numeric(extent <= 2))
fit.colon <- survreg(Surv(time, status) ~ rx + node4 + depth, 
                     data = colon2, dist = "lognormal")

Next, run parametric bootstrap simulation:

sim <- 
  surv_param_sim(object = fit.colon, newdata = colon2, 
                 censor.dur = c(1800, 3000),
                 # Simulating only 100 times to make the example go fast
                 n.rep = 100)

sim
#> ---- Simulated survival data with the following model ----
#> survreg(formula = Surv(time, status) ~ rx + node4 + depth, data = colon2, 
#>     dist = "lognormal")
#> 
#> * Use `extract_sim()` function to extract individual simulated survivals
#> * Use `calc_km_pi()` function to get survival curves and median survival time
#> * Use `calc_hr_pi()` function to get hazard ratio
#> 
#> * Settings:
#>     #simulations: 100 
#>     #subjects: 619 (without NA in model variables)

Calculate survival curves with prediction intervals:

km.pi <- calc_km_pi(sim, trt = "rx", group = c("node4", "depth"))

km.pi
#> ---- Simulated and observed (if calculated) survival curves ----
#> * Use `extract_median_surv()` to extract median survival times
#> * Use `extract_km_pi()` to extract prediction intervals of K-M curves
#> * Use `plot_km_pi()` to draw survival curves
#> 
#> * Settings:
#>     trt: rx 
#>     group: node4 
#>     pi.range: 0.95 
#>     calc.obs: TRUE
plot_km_pi(km.pi) +
  theme(legend.position = "bottom") +
  labs(y = "Recurrence free rate") +
  expand_limits(y = 0)

Calculate hazard ratios with prediction intervals:

hr.pi <- calc_hr_pi(sim, trt = "rx", group = c("depth"))

hr.pi
#> ---- Simulated and observed (if calculated) hazard ratio ----
#> * Use `extract_hr_pi()` to extract prediction intervals and observed HR
#> * Use `extract_hr()` to extract individual simulated HRs
#> * Use `plot_hr_pi()` to draw histogram of predicted HR
#> 
#> * Settings:
#>     trt: rx
#>          (Lev+5FU as test trt, Obs as control)
#>     group: depth 
#>     pi.range: 0.95 
#>     calc.obs: TRUE
plot_hr_pi(hr.pi)

Functions in survParamSim

Name Description
plot_km_pi Plot Kaplan-Meier curves with prediction intervals from parametric bootstrap simulation
extract_sim Functions to extract raw simulated samples
extract_km_pi Functions to extract prediction intervals and observed data
calc_hr_pi Generate hazard ratio with prediction intervals from parametric bootstrap simulation
print.survparamsim.hrpi Methods for S3 objects in the package
%>% Pipe operator
plot_hr_pi Plot HR
calc_km_pi Generate Kaplan-Meier curves with prediction intervals from parametric bootstrap simulation
surv_param_sim Simulation of parametric survival model
No Results!

Vignettes of survParamSim

Name
survParamSim.Rmd
No Results!

Last month downloads

Details

Type Package
License GPL-3
Encoding UTF-8
LazyData true
RoxygenNote 7.0.2
Language en-US
URL https://github.com/yoshidk6/survParamSim
BugReports https://github.com/yoshidk6/survParamSim/issues
VignetteBuilder knitr
NeedsCompilation no
Packaged 2020-01-11 05:29:55 UTC; rokuk
Repository CRAN
Date/Publication 2020-01-13 17:00:02 UTC

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/survParamSim)](http://www.rdocumentation.org/packages/survParamSim)