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.
- 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
.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 plot 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.
Examples
library(dplyr)
# Example 1
sim_pw_surv(n = 20)
#> stratum enroll_time treatment fail_time dropout_time cte fail
#> 1 All 0.07871071 experimental 0.8537303 3814.4049 0.9324410 1
#> 2 All 0.47026321 experimental 14.4602565 1299.4046 14.9305197 1
#> 3 All 0.47994086 control 0.1330972 1008.1076 0.6130381 1
#> 4 All 0.48952155 control 24.1670368 922.0742 24.6565583 1
#> 5 All 0.53471429 experimental 38.9716282 1607.3073 39.5063425 1
#> 6 All 0.59386888 control 42.5781553 3317.0719 43.1720242 1
#> 7 All 0.78455146 control 22.0439755 965.5532 22.8285270 1
#> 8 All 0.84011530 experimental 15.0846482 2413.7393 15.9247635 1
#> 9 All 0.85965653 experimental 19.1110751 1714.4159 19.9707317 1
#> 10 All 0.93337303 control 17.8959969 124.9380 18.8293699 1
#> 11 All 1.05113537 control 10.4688811 717.6797 11.5200164 1
#> 12 All 1.16178034 experimental 1.6215705 421.1552 2.7833509 1
#> 13 All 1.25624680 control 27.7475045 322.8267 29.0037513 1
#> 14 All 1.34969344 experimental 5.4383655 729.7809 6.7880589 1
#> 15 All 1.38160544 control 19.9963748 34.9122 21.3779803 1
#> 16 All 1.70322101 experimental 74.4891447 1457.0016 76.1923657 1
#> 17 All 1.96431347 control 24.6891265 569.9275 26.6534400 1
#> 18 All 2.02746120 experimental 2.6682724 234.8326 4.6957335 1
#> 19 All 2.02883625 experimental 20.3642611 3707.3776 22.3930973 1
#> 20 All 2.07483249 control 41.2064449 1929.5912 43.2812774 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.3394074 control 8.6798252 4679.0284 9.019233 1
#> 2 All 0.3514369 experimental 79.5996476 1328.2675 79.951085 1
#> 3 All 0.3928878 experimental 38.5427341 1922.6176 38.935622 1
#> 4 All 0.5034569 experimental 8.2467060 1033.8370 8.750163 1
#> 5 All 0.6262564 experimental 2.6286523 2438.6836 3.254909 1
#> 6 All 0.7785300 experimental 3.1935522 5787.6327 3.972082 1
#> 7 All 0.8784108 experimental 34.4718123 130.0677 35.350223 1
#> 8 All 0.8899508 control 5.3450682 1342.8364 6.235019 1
#> 9 All 0.9266900 experimental 26.0590347 1435.6105 26.985725 1
#> 10 All 0.9963989 control 0.8252429 428.1238 1.821642 1
#> 11 All 1.1710287 experimental 31.8069029 611.7869 32.977932 1
#> 12 All 1.4501068 experimental 87.7351564 4007.8564 89.185263 1
#> 13 All 1.5755139 control 34.5970358 680.3976 36.172550 1
#> 14 All 1.9586947 experimental 52.3140237 1314.4830 54.272718 1
#> 15 All 1.9733837 experimental 2.1468786 418.7007 4.120262 1
#> 16 All 2.1825953 experimental 113.6812780 783.3458 115.863873 1
#> 17 All 2.2419764 experimental 21.9996164 314.7699 24.241593 1
#> 18 All 2.8708139 experimental 1.6705914 129.1783 4.541405 1
#> 19 All 2.9452748 experimental 2.8462729 686.4160 5.791548 1
#> 20 All 2.9607731 control 3.2725614 777.8008 6.233334 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.07492052 control 5.887847 947.53200 5.962767 1
#> 2 Low 0.13502778 experimental 48.059320 1575.46191 48.194348 1
#> 3 High 0.39865660 control 6.385581 594.65722 6.784238 1
#> 4 High 0.46889497 experimental 6.502192 101.48532 6.971086 1
#> 5 Low 0.60455860 experimental 70.910494 11.30581 11.910371 0
#> 6 High 0.62445322 experimental 7.129680 1745.49713 7.754133 1
#> 7 High 0.62488209 experimental 11.743456 140.48715 12.368338 1
#> 8 High 0.82976440 control 4.701781 534.03903 5.531546 1
#> 9 Low 0.99732749 control 8.650039 1618.77424 9.647367 1
#> 10 Low 1.02977227 control 8.232462 298.39988 9.262234 1
#> 11 Low 1.11813466 control 1.170722 338.56170 2.288857 1
#> 12 High 1.21201118 control 6.176228 798.42951 7.388239 1
#> 13 Low 1.30547882 control 2.371753 471.61170 3.677232 1
#> 14 High 1.31769324 experimental 83.296196 120.75608 84.613889 1
#> 15 High 1.33028083 experimental 18.983368 556.32841 20.313649 1
#> 16 Low 1.39432486 experimental 7.980584 265.74101 9.374909 1
#> 17 Low 1.41875001 experimental 23.774258 290.84161 25.193008 1
#> 18 High 1.68017410 experimental 2.134892 2312.44321 3.815066 1
#> 19 High 1.82422589 control 26.390533 2039.00719 28.214759 1
#> 20 High 1.86734381 control 4.553985 1228.14940 6.421329 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.3303511 control 29.302363 541.68921 29.632714 1
#> 2 High 0.3558160 experimental 19.482764 1141.96183 19.838580 1
#> 3 High 0.3805044 control 3.984188 17.81142 4.364693 1
#> 4 Low 0.4365653 experimental 35.101857 246.42432 35.538422 1
#> 5 High 0.4482662 experimental 40.290596 323.49290 40.738862 1
#> 6 High 0.6482421 control 9.217221 1753.59986 9.865463 1
#> 7 High 0.6498981 experimental 47.942699 1429.39814 48.592597 1
#> 8 High 0.7809772 control 5.105759 611.20351 5.886737 1
#> 9 High 0.7835750 experimental 31.775029 156.08091 32.558604 1
#> 10 High 0.8084417 control 45.218498 398.01563 46.026939 1
#> 11 High 0.8454368 control 4.826850 2369.46680 5.672287 1
#> 12 High 0.8853096 control 12.108700 1231.07715 12.994010 1