This repository includes an R file that has the functions to implement all the sample size and power methods developed in the paper [Li F, Chen X, Tian Z, Esserman DA, Heagerty PJ, Wang R. Planning Three-Level Cluster Randomized Trials to Assess Treatment Effect Heterogeneity. Under Review.]. Besides, R code for reproducing Figure 2 and 3, Table 1 to 3, Web Table 1 to 6, and Web Figure 1 in the manuscript is also provided in folders.
For questions or comments about the code, please contact Zizhong Tian at [email protected].
For the separate R file "sample size_power_calculations.R", it contains 2x3x3 functions that conveniently implement the sample size and power formulas for testing HTE, ATE, and unadjusted ATE under three levels of randomization scenarios. For the code that help to reproduce the simulations or plots in the paper, the descriptions are as follows:
I. Supporting Files: These supporting files are sourced in the corresponding main files that reproduce the simulation tables and illustrative plots in the main manuscript as well as the supplementary web appendix.
Folder: functions
- L1_sim_functions.R = functions about sample size/power formula and data generation under the scenario of level-1 (individual-level) randomization;
- L2_sim_functions.R = functions about sample size/power formula and data generation under the scenario of level-2 (subcluster-level) randomization;
- L3_sim_functions.R = functions about sample size/power formula and data generation under the scenario of level-3 (cluster-level) randomization;
- L1_plot_functions.R = functions used for data application under the scenario of level-1 (individual-level) randomization;
- L2_plot_functions.R = functions used for data application under the scenario of level-2 (subcluster-level) randomization;
- L3_plot_functions.R = functions used for data application under the scenario of level-3 (cluster-level) randomization;
II. Main Files: These main files are used to reproduce the simulation results and illustrative plots in the main manuscript as well as the web appendix.
Folder: simulations
- L1_HTE.R = reproduce the simulation table for testing HTE under level-1 randomization;
- L1_OTE.R = reproduce the simulation table for testing ATE under level-1 randomization;
- L1_OTE_unadj.R = reproduce the simulation table for testing unadjusted ATE under level-1 randomization;
- L2_HTE.R = reproduce the simulation table for testing HTE under level-2 randomization;
- L2_OTE.R = reproduce the simulation table for testing ATE under level-2 randomization;
- L2_OTE_unadj.R = reproduce the simulation table for testing unadjusted ATE under level-2 randomization;
- L3_HTE.R = reproduce the simulation table for testing HTE under level-3 randomization;
- L3_OTE.R = reproduce the simulation table for testing ATE under level-3 randomization;
- L3_OTE_unadj.R = reproduce the simulation table for testing unadjusted ATE under level-3 randomization;
- xtable.R = generate the LaTeX editing version of all table contents;
Folder: plots
- Remark_1_Level2.R = reproduce the illustrative variance plot regarding Remark 1 (level-2 randomization);
- Remark_1_Level3.R = reproduce the illustrative variance plot regarding Remark 1 (level-3 randomization);
- HALI_example_BaselineScore.R = reproduce the power analysis plot in the data application section;
III. Software
Analyses were conducted with R, version 4.0.3 (https://www.r-project.org/) The calculations used R packages nlme (version 3.1-143).
IV. R commands for the installation of R packages
install.packages(c("nlme"))