Skip to contents

simPWSurv 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 distribtuion 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

simPWSurv(
  n = 100,
  strata = tibble(Stratum = "All", p = 1),
  block = c(rep("Control", 2), rep("Experimental", 2)),
  enroll_rate = tibble(rate = 9, duration = 1),
  failRates = tibble(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)),
  dropoutRates = tibble(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.

strata

A tibble with strata specified in Stratum, probability (incidence) of each stratum in p

block

Vector of treatments to be included in each block

enroll_rate

Enrollment rates; see details and examples

failRates

Failure rates; see details and examples; note that treatments need to be the same as input in block

dropoutRates

Dropout rates; see details and examples; note that treatments need to be the same as input in block

Value

a tibble 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 input block), failTime (failure time generated using rpwexp()), dropoutTime (dropout time generated using rpwexp()), cte (calendar time of enrollment plot the minimum of failure time and dropout time), fail (indicator that cte was set using failure time; i.e., 1 is a failure, 0 is a dropout).

Examples

library(dplyr)
library(tibble)

# example 1
simPWSurv(n = 20)
#> # A tibble: 20 × 7
#> # Groups:   Stratum, Treatment [2]
#>    Stratum enroll_time Treatment    failTime dropoutTime   cte  fail
#>    <chr>         <dbl> <chr>           <dbl>       <dbl> <dbl> <dbl>
#>  1 All         0.00680 Experimental    4.82        153.   4.83     1
#>  2 All         0.112   Control        28.6        1909.  28.7      1
#>  3 All         0.117   Experimental   62.0         557.  62.2      1
#>  4 All         0.229   Control         3.61        373.   3.84     1
#>  5 All         0.644   Experimental    0.732      1445.   1.38     1
#>  6 All         0.708   Experimental   92.0         751.  92.7      1
#>  7 All         0.892   Control         7.18        297.   8.07     1
#>  8 All         0.994   Control         8.04        231.   9.04     1
#>  9 All         1.04    Control         3.57       2096.   4.61     1
#> 10 All         1.11    Experimental    0.901        70.9  2.01     1
#> 11 All         1.22    Experimental   70.8        1985.  72.0      1
#> 12 All         1.30    Control        17.4         277.  18.7      1
#> 13 All         1.33    Control         7.98       2216.   9.31     1
#> 14 All         1.37    Experimental   64.5         668.  65.9      1
#> 15 All         1.46    Control        11.0         921.  12.4      1
#> 16 All         1.54    Experimental    3.50       1061.   5.04     1
#> 17 All         1.72    Experimental    3.27        931.   4.98     1
#> 18 All         1.91    Experimental   21.8          55.1 23.7      1
#> 19 All         1.92    Control         1.45        640.   3.37     1
#> 20 All         1.97    Control         4.51        208.   6.48     1

# example 2
# 3:1 randomization
simPWSurv(n = 20,
          block = c(rep("Experimental",3), "Control"))
#> # A tibble: 20 × 7
#> # Groups:   Stratum, Treatment [2]
#>    Stratum enroll_time Treatment    failTime dropoutTime   cte  fail
#>    <chr>         <dbl> <chr>           <dbl>       <dbl> <dbl> <dbl>
#>  1 All          0.0278 Experimental   25.3        1524.  25.3      1
#>  2 All          0.0779 Experimental   57.9        1299.  58.0      1
#>  3 All          0.456  Control         6.68        270.   7.13     1
#>  4 All          0.498  Experimental    2.78        567.   3.27     1
#>  5 All          0.596  Experimental   68.7        1856.  69.3      1
#>  6 All          0.645  Control         8.25         65.0  8.89     1
#>  7 All          0.769  Experimental   16.5         450.  17.3      1
#>  8 All          0.812  Experimental   14.7        1039.  15.5      1
#>  9 All          1.06   Experimental   19.6        1159.  20.6      1
#> 10 All          1.08   Control        10.7          92.3 11.8      1
#> 11 All          1.11   Experimental   96.8         251.  97.9      1
#> 12 All          1.18   Experimental    1.36        174.   2.54     1
#> 13 All          1.21   Experimental   39.3          19.3 20.5      0
#> 14 All          1.41   Control         7.86        966.   9.28     1
#> 15 All          1.42   Experimental   14.9          20.0 16.3      1
#> 16 All          1.44   Experimental    1.47         73.9  2.91     1
#> 17 All          1.44   Experimental    0.434      2016.   1.88     1
#> 18 All          1.83   Experimental   25.0        4048.  26.8      1
#> 19 All          1.96   Control        11.3        1787.  13.3      1
#> 20 All          1.99   Experimental    0.934       452.   2.92     1

# example 3
# Simulate 2 strata; will use defaults for blocking and enroll_rate
simPWSurv(n = 20,
          # 2 strata,30% and 70% prevalence
          strata = tibble(Stratum = c("Low","High"), p = c(.3, .7)),
          failRates = tibble(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)),
          dropoutRates = tibble(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)))
#> # A tibble: 20 × 7
#> # Groups:   Stratum, Treatment [4]
#>    Stratum enroll_time Treatment    failTime dropoutTime    cte  fail
#>    <chr>         <dbl> <chr>           <dbl>       <dbl>  <dbl> <dbl>
#>  1 Low          0.0140 Control         0.325      437.    0.339     1
#>  2 High         0.262  Control         3.04       933.    3.30      1
#>  3 High         0.299  Experimental    9.48      1223.    9.77      1
#>  4 High         0.314  Experimental    2.57       428.    2.88      1
#>  5 Low          0.316  Control        17.7       2022.   18.1       1
#>  6 High         0.321  Control        17.5       1484.   17.8       1
#>  7 High         0.326  Control         3.71      1302.    4.03      1
#>  8 High         0.778  Experimental    4.46       761.    5.24      1
#>  9 Low          0.803  Experimental   13.9        266.   14.7       1
#> 10 High         1.17   Experimental    6.47       368.    7.64      1
#> 11 High         1.21   Control        20.1        172.   21.3       1
#> 12 High         1.21   Control        44.8        320.   46.1       1
#> 13 Low          1.30   Experimental   21.6        320.   22.9       1
#> 14 High         1.55   Experimental   77.1       1104.   78.7       1
#> 15 High         1.82   Control        10.7          7.97  9.79      0
#> 16 High         1.83   Experimental    9.91       168.   11.7       1
#> 17 High         1.86   Control        43.9        282.   45.8       1
#> 18 High         2.21   Experimental    9.89       233.   12.1       1
#> 19 High         2.25   Experimental   35.9       1860.   38.2       1
#> 20 High         2.36   Control         8.80        34.3  11.2       1
# example 4
# If you want a more rectangular entry for a tibble
failRates <- bind_rows(
  tibble(Stratum = "Low" , period = 1, Treatment = "Control"     , duration = 3, rate = .03),
  tibble(Stratum = "Low" , period = 1, Treatment = "Experimental", duration = 3, rate = .03),
  tibble(Stratum = "Low" , period = 2, Treatment = "Experimental", duration = 3, rate = .02),
  tibble(Stratum = "High", period = 1, Treatment = "Control"     , duration = 3, rate = .05),
  tibble(Stratum = "High", period = 1, Treatment = "Experimental", duration = 3, rate = .06),
  tibble(Stratum = "High", period = 2, Treatment = "Experimental", duration = 3, rate = .03))

dropoutRates <- bind_rows(
  tibble(Stratum = "Low" , period=1, Treatment = "Control"     , duration = 3, rate = .001),
  tibble(Stratum = "Low" , period=1, Treatment = "Experimental", duration = 3, rate = .001),
  tibble(Stratum = "High", period=1, Treatment = "Control"     , duration = 3, rate = .001),
  tibble(Stratum = "High", period=1, Treatment = "Experimental", duration = 3, rate = .001))

simPWSurv(n = 12,
         strata = tibble(Stratum = c("Low","High"), p = c(.3, .7)),
         failRates = failRates,
         dropoutRates = dropoutRates)
#> # A tibble: 12 × 7
#> # Groups:   Stratum, Treatment [4]
#>    Stratum enroll_time Treatment    failTime dropoutTime   cte  fail
#>    <chr>         <dbl> <chr>           <dbl>       <dbl> <dbl> <dbl>
#>  1 Low         0.00555 Control          5.89       950.   5.90     1
#>  2 Low         0.0413  Experimental    19.5        298.  19.5      1
#>  3 High        0.219   Experimental     8.41       740.   8.63     1
#>  4 High        0.298   Experimental     8.22        95.1  8.52     1
#>  5 High        0.393   Control         12.4       1303.  12.8      1
#>  6 High        0.423   Control         19.6        717.  20.0      1
#>  7 High        0.498   Control          1.88       869.   2.38     1
#>  8 Low         0.589   Experimental    28.5       1741.  29.1      1
#>  9 High        0.667   Control         10.2         18.5 10.9      1
#> 10 Low         0.720   Control         16.6        681.  17.3      1
#> 11 Low         0.724   Control         28.0         92.2 28.7      1
#> 12 High        0.888   Experimental     3.39       583.   4.28     1