simfix2simPWSurv: Conversion of enrollment and failure rates from sim_fixed_n()...

View source: R/simfix2simPWSurv.R

simfix2simPWSurvR Documentation

Conversion of enrollment and failure rates from sim_fixed_n() to sim_pw_surv() format

Description

simfix2simPWSurv() converts failure rates and dropout rates entered in the simpler format for sim_fixed_n() to that used for simtrial::sim_pw_surv(). The fail_rate argument for sim_fixed_n() requires enrollment rates, failure rates hazard ratios and dropout rates by strata for a 2-arm trial, simtrial::sim_pw_surv() is in a more flexible but less obvious but more flexible format. Since sim_fixed_n() automatically analyzes data and simtrial::sim_pw_surv() just produces a simulation dataset, the latter provides additional options to analyze or otherwise evaluate individual simulations in ways that sim_fixed_n() does not.

Usage

simfix2simPWSurv(
  fail_rate = tibble(Stratum = "All", duration = c(3, 100), fail_rate = log(2)/c(9, 18),
    hr = c(0.9, 0.6), dropoutRate = rep(0.001, 2))
)

Arguments

fail_rate

Piecewise constant control group failure rates, hazard ratio for experimental vs control, and dropout rates by stratum and time period.

Value

A list of two tibble components formatted for simtrial::sim_pw_surv(): fail_rate and dropoutRates.

Examples

library(tidyr)
library(dplyr)
library(tibble)

# example 1
# Convert standard input
simfix2simPWSurv()

# Stratified example
fail_rate <- tibble(Stratum = c(rep("Low", 3),rep("High", 3)),
                    duration = rep(c(4, 10, 100), 2),
                    fail_rate = c(.04, .1, .06,
                                 .08,.16,.12),
                    hr = c(1.5, .5, 2/3,
                           2, 10/16, 10/12),
                    dropoutRate =.01)

x <- simfix2simPWSurv(fail_rate)

# Do a single simulation with the above rates
# Enroll 300 patients in ~12 months at constant rate
sim <- sim_pw_surv(n = 300,
                 strata = tibble(Stratum = c("Low","High"), p = c(.6, .4)),
                 enroll_rate = tibble(duration = 12, rate = 300 / 12),
                 fail_rate = x$fail_rate,
                 dropoutRates = x$dropoutRates)

# Cut after 200 events and do a stratified logrank test
dat <- sim %>%
  cut_data_by_event(200) %>%              # cut data
  counting_process(arm = "Experimental") %>%  # convert format for wlr
  wlr(rg = tibble(rho=0,gamma=0))    # stratified logrank


keaven/simtrial documentation built on April 17, 2023, 4:03 a.m.