sim_pw_surv | R Documentation |

`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 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.

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

`n` |
Number of observations. If length(n) > 1, the length is taken to be the number required. |

`strata` |
A tibble with strata specified in |

`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 |

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

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`

),
`fail_time`

(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).

```
library(dplyr)
library(tibble)
# example 1
sim_pw_surv(n = 20)
# example 2
# 3:1 randomization
sim_pw_surv(n = 20,
block = c(rep("Experimental",3), "Control"))
# example 3
# Simulate 2 strata; will use defaults for blocking and enrollRates
sim_pw_surv(n = 20,
# 2 strata,30% and 70% prevalence
strata = tibble(Stratum = c("Low","High"), p = c(.3, .7)),
fail_rate = 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)))
# example 4
# If you want a more rectangular entry for a tibble
fail_rate <- 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))
sim_pw_surv(n = 12,
strata = tibble(Stratum = c("Low","High"), p = c(.3, .7)),
fail_rate = fail_rate,
dropoutRates = dropoutRates)
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.