Skip to content

Instantly share code, notes, and snippets.

# script for initial trial simulation
# plots relationship between trial endpoints and power for entry into network model
# function to compute Z from endpoints and sample sizes
get_Z = function(numerator,denominator){ # each input is a vector length 2
phat = (numerator)/denominator
sigma = phat*(1-phat) / denominator
## computes test statistic for a single trial
compute_test_statistic <- function(sample_size,cases,eta=0.7){
# assume fixed and equal allocation
n0 <- round(sample_size/2)
n1 <- sample_size - n0
# get relative risk from vaccine efficacy eta
relative_risk <- 1 - eta
# sample number of fails for control
f0 <- rbinom(max(length(cases),length(sample_size)),cases,1 / (1+relative_risk))
# get number of fails for experimental