sim_pw_surv()
enables simulation of a clinical trial with
essentially arbitrary patterns of enrollment, failure rates and censoring.
The piecewise exponential distribution allows a simple method to specify
a distribution and enrollment pattern where the enrollment, failure,
and dropout rate changes over time.
While the main purpose may be to generate a trial that can be analyzed
at a single point in time or using group sequential methods,
the routine can also be used to simulate an adaptive trial design.
Enrollment, failure, and dropout rates are specified by treatment group,
stratum and time period.
Fixed block randomization is used; blocks must include treatments provided
in failure and dropout specification.
Default arguments are set up to allow very simple implementation of
a non-proportional hazards assumption for an unstratified design.
Usage
sim_pw_surv(
n = 100,
stratum = data.frame(stratum = "All", p = 1),
block = c(rep("control", 2), rep("experimental", 2)),
enroll_rate = data.frame(rate = 9, duration = 1),
fail_rate = data.frame(stratum = rep("All", 4), period = rep(1:2, 2), treatment =
c(rep("control", 2), rep("experimental", 2)), duration = rep(c(3, 1), 2), rate =
log(2)/c(9, 9, 9, 18)),
dropout_rate = data.frame(stratum = rep("All", 2), period = rep(1, 2), treatment =
c("control", "experimental"), duration = rep(100, 2), rate = rep(0.001, 2))
)
Arguments
- n
Number of observations. If length(n) > 1, the length is taken to be the number required.
- stratum
A data frame with stratum specified in
stratum
, probability (incidence) of each stratum inp
.- block
Vector of treatments to be included in each block. Also used to calculate the attribute "ratio" (for more details see the section Value below).
- enroll_rate
Enrollment rates; see details and examples.
- fail_rate
Failure rates; see details and examples; note that treatments need to be the same as input in block.
- dropout_rate
Dropout rates; see details and examples; note that treatments need to be the same as input in block.
Value
A data frame with the following variables for each observation:
stratum
: Stratum for the observation.enroll_time
: Enrollment time for the observation.treatment
: Treatment group; this will be one of the values in the inputblock
.fail_time
: Failure time generated usingrpwexp()
.dropout_time
: Dropout time generated usingrpwexp()
.cte
: Calendar time of enrollment plus the minimum of failure time and dropout time.fail
: Indicator thatcte
was set using failure time; i.e., 1 is a failure, 0 is a dropout.
The data frame also has the attribute "ratio", which is calculated as the
number of "experimental" treatments divided by the number of "control"
treatments from the input argument block
.
Examples
library(dplyr)
# Example 1
sim_pw_surv(n = 20)
#> stratum enroll_time treatment fail_time dropout_time cte fail
#> 1 All 0.04809163 control 0.2659009 293.80946 0.3139925 1
#> 2 All 0.07430006 control 1.9729803 1089.95618 2.0472804 1
#> 3 All 0.21098484 experimental 12.3655734 424.86428 12.5765582 1
#> 4 All 0.42674243 experimental 24.8934865 3601.37946 25.3202289 1
#> 5 All 0.44817082 experimental 8.9691062 951.20200 9.4172770 1
#> 6 All 0.45065963 experimental 9.4852510 2118.15209 9.9359106 1
#> 7 All 0.54806466 control 18.4483802 434.31466 18.9964449 1
#> 8 All 0.76396119 control 5.9717512 125.93169 6.7357124 1
#> 9 All 0.77362508 control 3.8388328 847.48951 4.6124578 1
#> 10 All 0.83323863 experimental 1.0412043 1901.83435 1.8744429 1
#> 11 All 0.90493326 control 3.3195804 58.16193 4.2245137 1
#> 12 All 1.04492977 experimental 4.2301976 160.37688 5.2751273 1
#> 13 All 1.18205700 experimental 32.7491726 197.03324 33.9312296 1
#> 14 All 1.19812943 experimental 2.2875405 804.91681 3.4856700 1
#> 15 All 1.21239102 control 5.1065099 1375.31437 6.3189010 1
#> 16 All 1.29442227 control 3.7912304 11.34259 5.0856526 1
#> 17 All 1.40714335 control 0.3408276 98.58106 1.7479710 1
#> 18 All 1.51996598 experimental 18.3949403 126.02694 19.9149063 1
#> 19 All 1.80408757 control 25.7471549 3940.42836 27.5512425 1
#> 20 All 1.84719724 experimental 21.5735772 222.00638 23.4207744 1
# Example 2
# 3:1 randomization
sim_pw_surv(
n = 20,
block = c(rep("experimental", 3), "control")
)
#> stratum enroll_time treatment fail_time dropout_time cte fail
#> 1 All 0.1941141 control 6.7831275 189.732031 6.977242 1
#> 2 All 0.3150796 experimental 3.5338628 255.836968 3.848942 1
#> 3 All 0.3267101 experimental 9.4928294 742.229574 9.819540 1
#> 4 All 0.3282019 experimental 12.4943694 685.656819 12.822571 1
#> 5 All 0.4126848 experimental 41.0686377 1134.605316 41.481322 1
#> 6 All 0.4318898 control 2.6178723 699.637074 3.049762 1
#> 7 All 0.7536140 experimental 116.8281381 1848.415820 117.581752 1
#> 8 All 0.7884568 experimental 1.1196077 162.507928 1.908065 1
#> 9 All 0.8149227 experimental 44.2434604 4.963087 5.778010 0
#> 10 All 0.8563849 control 3.2042041 706.781454 4.060589 1
#> 11 All 0.9081685 experimental 4.5214569 456.380132 5.429625 1
#> 12 All 0.9206597 experimental 6.9775576 276.484136 7.898217 1
#> 13 All 1.0454991 experimental 14.8730426 426.240944 15.918542 1
#> 14 All 1.1210343 control 2.3365045 1101.256078 3.457539 1
#> 15 All 1.2213323 experimental 0.1715598 30.568471 1.392892 1
#> 16 All 1.4507374 experimental 10.0687941 3025.328402 11.519532 1
#> 17 All 1.4528345 experimental 17.4354083 1147.682266 18.888243 1
#> 18 All 1.7192530 experimental 99.0519123 76.763221 78.482474 0
#> 19 All 1.8418805 control 20.8075822 1447.017415 22.649463 1
#> 20 All 1.8787512 experimental 19.0166778 440.688450 20.895429 1
# Example 3
# Simulate 2 stratum; will use defaults for blocking and enrollRates
sim_pw_surv(
n = 20,
# 2 stratum,30% and 70% prevalence
stratum = data.frame(stratum = c("Low", "High"), p = c(.3, .7)),
fail_rate = data.frame(
stratum = c(rep("Low", 4), rep("High", 4)),
period = rep(1:2, 4),
treatment = rep(c(
rep("control", 2),
rep("experimental", 2)
), 2),
duration = rep(c(3, 1), 4),
rate = c(.03, .05, .03, .03, .05, .08, .07, .04)
),
dropout_rate = data.frame(
stratum = c(rep("Low", 2), rep("High", 2)),
period = rep(1, 4),
treatment = rep(c("control", "experimental"), 2),
duration = rep(1, 4),
rate = rep(.001, 4)
)
)
#> stratum enroll_time treatment fail_time dropout_time cte fail
#> 1 High 0.1036777 experimental 20.2331348 4174.94331 20.336813 1
#> 2 High 0.1343389 experimental 4.1098911 465.29175 4.244230 1
#> 3 High 0.2064661 control 17.5605004 1004.53947 17.766967 1
#> 4 High 0.2796553 control 23.0282302 494.34540 23.307885 1
#> 5 Low 0.3086204 control 11.4731163 23.72062 11.781737 1
#> 6 High 0.3111598 experimental 1.8322780 2189.41244 2.143438 1
#> 7 High 0.9270572 control 11.6284285 21.84553 12.555486 1
#> 8 Low 0.9797810 experimental 15.8387307 3407.82733 16.818512 1
#> 9 High 1.0627224 control 6.7833167 699.12197 7.846039 1
#> 10 High 1.1896626 experimental 0.8167457 361.39980 2.006408 1
#> 11 Low 1.2618837 control 24.4847066 661.56404 25.746590 1
#> 12 High 1.4095626 control 29.7332577 788.59361 31.142820 1
#> 13 Low 1.6101124 experimental 54.1703944 1135.55339 55.780507 1
#> 14 High 1.7441575 experimental 8.6834669 3357.73901 10.427624 1
#> 15 High 1.9973926 experimental 0.6192459 238.07083 2.616639 1
#> 16 Low 2.3403839 control 45.4400769 2356.38747 47.780461 1
#> 17 High 2.5440934 control 11.0088796 382.11254 13.552973 1
#> 18 High 2.5440974 control 6.0942686 134.13149 8.638366 1
#> 19 High 2.6168482 control 10.6131452 485.16067 13.229993 1
#> 20 Low 2.6640095 experimental 49.5705882 2008.07518 52.234598 1
# Example 4
# If you want a more rectangular entry for a data.frame
fail_rate <- bind_rows(
data.frame(stratum = "Low", period = 1, treatment = "control", duration = 3, rate = .03),
data.frame(stratum = "Low", period = 1, treatment = "experimental", duration = 3, rate = .03),
data.frame(stratum = "Low", period = 2, treatment = "experimental", duration = 3, rate = .02),
data.frame(stratum = "High", period = 1, treatment = "control", duration = 3, rate = .05),
data.frame(stratum = "High", period = 1, treatment = "experimental", duration = 3, rate = .06),
data.frame(stratum = "High", period = 2, treatment = "experimental", duration = 3, rate = .03)
)
dropout_rate <- bind_rows(
data.frame(stratum = "Low", period = 1, treatment = "control", duration = 3, rate = .001),
data.frame(stratum = "Low", period = 1, treatment = "experimental", duration = 3, rate = .001),
data.frame(stratum = "High", period = 1, treatment = "control", duration = 3, rate = .001),
data.frame(stratum = "High", period = 1, treatment = "experimental", duration = 3, rate = .001)
)
sim_pw_surv(
n = 12,
stratum = data.frame(stratum = c("Low", "High"), p = c(.3, .7)),
fail_rate = fail_rate,
dropout_rate = dropout_rate
)
#> stratum enroll_time treatment fail_time dropout_time cte fail
#> 1 Low 0.2572800 control 37.602886 465.177813 37.860166 1
#> 2 High 0.4370483 control 20.546177 1352.219300 20.983226 1
#> 3 Low 0.4944613 experimental 78.619566 338.976877 79.114027 1
#> 4 Low 0.5673761 experimental 15.853988 347.672350 16.421364 1
#> 5 Low 1.1069423 control 2.195484 723.838025 3.302426 1
#> 6 High 1.1680008 experimental 10.451312 633.099389 11.619313 1
#> 7 Low 1.2875002 experimental 38.684903 2506.432402 39.972403 1
#> 8 High 1.4881602 control 9.463377 1250.153280 10.951537 1
#> 9 High 1.5505213 experimental 15.439429 1193.758523 16.989950 1
#> 10 Low 1.6826246 experimental 11.089760 645.756427 12.772384 1
#> 11 Low 1.8512677 control 29.195486 8.994333 10.845600 0
#> 12 High 2.0465840 control 31.254707 2963.649460 33.301291 1