This function utilizes iterative simulations to determine approximate power for cluster-randomized controlled trials. Users can modify a variety of parameters to suit the simulations to their desired experimental situation.
Runs the power simulation for difference in difference RCTs with binary outcomes.
Users must specify the desired number of simulations, number of subjects per cluster, number of clusters per arm, pre-treatment between-cluster variance, and two of the following three terms: expected probability of outcome in arm 1, expected probability of outcome in arm 2, expected difference in probabilities between groups ; post-treatment between-cluster variance, significance level, analytic method, progress updates, and simulated data set output may also be specified.
The following equations are used to estimate intra-cluster correlation coefficients:
P_h: ICC = _b_b + ^2/3 P_c: ICC = P(Y_ij = 1, Y_ih = 1) - _j_h_j(1 - _j)_h(1 - _h) P_lmer: ICC = _b_b + _w
cps.did.binary(
nsim = NULL,
nsubjects = NULL,
nclusters = NULL,
p.diff = NULL,
p1t0 = 0,
p2t0 = NULL,
p1t1 = NULL,
p2t1 = NULL,
or1 = NULL,
or2 = NULL,
or.diff = NULL,
sigma_b_sq0 = NULL,
sigma_b_sq1 = NULL,
alpha = 0.05,
method = "glmm",
quiet = TRUE,
allSimData = FALSE,
poorFitOverride = FALSE,
lowPowerOverride = FALSE,
timelimitOverride = TRUE,
seed = NA,
nofit = FALSE
)
Number of datasets to simulate; accepts integer (required).
Number of subjects per cluster; accepts integer (required).
Number of clusters per arm; accepts integer (required).
Optional if p1t1 and p2t0 are provided. Expected difference in outcome proportion between groups, defined as p.diff = (p1t1 - p1t0) - (p2t1 - p2t0).
At least 2 of the following 3 arguments must be specified when using expected odds ratios:
Required. Expected outcome proportion in arm 1 at baseline. Default is 0.
Optional. Expected outcome proportion in arm 2 at baseline. If no quantity is provided, p2t0 = p1t0 is assumed.
Optional. Expected outcome proportion in arm 1 at follow-up. If no quantity is provided, p1t1 = p1t0 is assumed.
Required. Expected outcome proportion in arm 2 at follow-up.
Expected odds ratio for outcome in arm 1
Expected odds ratio for outcome in arm 2
Expected difference in odds ratio for outcome between groups, defined as or.diff = or1 - or2.
Pre-treatment (time == 0) between-cluster variance; accepts numeric scalar (indicating equal between-cluster variances for both arms) or a vector of length 2 specifying treatment-specific between-cluster variances.
Post-treatment (time == 1) between-cluster variance; accepts numeric scalar (indicating equal between-cluster variances for both arms) or a vector of length 2 specifying treatment-specific between-cluster variances. If not provided by the user, sigma_b_sq1 = sigma_b_sq0.
Significance level. Default = 0.05
Analytical method, either Generalized Linear Mixed Effects Model (GLMM) or Generalized Estimating Equation (GEE). Accepts c('glmm', 'gee') (required); default = 'glmm'.
When set to FALSE, displays simulation start time and completion time. Default is TRUE.
Option to output list of all simulated datasets. Default = FALSE.
Option to override stop()
if more than 25%
of fits fail to converge; default = FALSE.
Option to override stop()
if the power
is less than 0.5 after the first 50 simulations and every ten simulations
thereafter. On function execution stop, the actual power is printed in the
stop message. Default = FALSE. When TRUE, this check is ignored and the
calculated power is returned regardless of value.
Logical. When FALSE, stops execution if the estimated completion time is more than 2 minutes. Defaults to TRUE.
Option to set the seed. Default is NA.
Option to skip model fitting and analysis and only return
the simulated data. Default = FALSE
.
A list with the following components
Character string indicating total number of simulations, simulation type, and number of convergent models
Number of simulations
Data frame with columns "Power" (Estimated statistical power), "lower.95.ci" (Lower 95 "upper.95.ci" (Upper 95
Analytic method used for power estimation
Significance level
Vector containing user-defined cluster sizes
Vector containing user-defined number of clusters
Data frame reporting sigma_b_sq for each group at each time point
Vector containing expected difference in probabilities based on user inputs
Data frame with columns: "Period" (Pre/Post-treatment indicator), "Arm" (Arm indicator), "Value" (Mean response value)
Data frame containing three estimates of ICC
Data frame with columns: "Estimate" (Estimate of treatment effect for a given simulation), "Std.err" (Standard error for treatment effect estimate), "Test.statistic" (z-value (for GLMM) or Wald statistic (for GEE)), "p.value", "converge" (Did simulated model converge?), "sig.val" (Is p-value less than alpha?)
If allSimData = TRUE
, a list of data frames, each containing:
"y" (Simulated response value),
"trt" (Indicator for arm),
"clust" (Indicator for cluster),
"period" (Indicator for time point)
List of warning messages produced by non-convergent models.
Includes model number for cross-referencing against
model.estimates
If nofit = T
, a data frame of the simulated data sets, containing:
"arm" (Indicator for treatment arm)
"cluster" (Indicator for cluster)
"y1" ... "yn" (Simulated response value for each of the nsim
data sets).
Snjiders, T. & Bosker, R. Multilevel Analysis: an Introduction to Basic and Advanced Multilevel Modelling. London, 1999: Sage.
Elridge, S., Ukoumunne, O. & Carlin, J. The Intra-Cluster Correlation Coefficient in Cluster Randomized Trials: A Review of Definitions. International Statistical Review (2009), 77, 3, 378-394. doi: 10.1111/j.1751-5823.2009.00092.x
# NOT RUN {
# Estimate power for a trial with 10 clusters in both arms, those clusters having
# 20 subjects each, with sigma_b_sq0 = 1. We have estimated arm proportions of 0.2
# and 0.3 in the first and second arms, respectively, and we use
# 100 simulated data sets analyzed by the GLMM method. The resulting estimated power
# (if you set seed = 123) should be about 0.78.
# }
# NOT RUN {
did.binary.sim = cps.did.binary(nsim = 100, nsubjects = 20, nclusters = 10,
p1t0 = 0.1, p2t0 = 0.1,
p1t1 = 0.2, p2t1 = 0.45, sigma_b_sq0 = 1,
sigma_b_sq1 = 1, alpha = 0.05,
method = 'glmm', allSimData = FALSE, seed = 123)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab