Type: | Package |
Title: | Optimal Design and Statistical Power for Experimental Studies Investigating Main, Mediation, and Moderation Effects |
Version: | 1.6.3 |
Date: | 2025-8-4 |
Description: | Calculate the optimal sample size allocation that uses the minimum resources to achieve targeted statistical power in experiments. Perform power analyses with and without accommodating costs and budget. The designs cover single-level and multilevel experiments detecting main, mediation, and moderation effects (and some combinations). The references for the proposed methods include: (1) Shen, Z., & Kelcey, B. (2020). Optimal sample allocation under unequal costs in cluster-randomized trials. Journal of Educational and Behavioral Statistics, 45(4): 446-474. <doi:10.3102/1076998620912418>. (2) Shen, Z., & Kelcey, B. (2022b). Optimal sample allocation for three-level multisite cluster-randomized trials. Journal of Research on Educational Effectiveness, 15 (1), 130-150. <doi:10.1080/19345747.2021.1953200>. (3) Shen, Z., & Kelcey, B. (2022a). Optimal sample allocation in multisite randomized trials. The Journal of Experimental Education, 90(3), 693-711. <doi:10.1080/00220973.2020.1830361>. (4) Shen, Z., Leite, W., Zhang, H., Quan, J., & Kuang, H. (2025). Using ant colony optimization to identify optimal sample allocations in cluster-randomized trials. The Journal of Experimental Education, 93(1), 167-185. <doi:10.1080/00220973.2024.2306392>. (5) Shen, Z., Li, W., & Leite, W. (in press). Statistical power and optimal design for randomized controlled trials investigating mediation effects. Psychological Methods. <doi:10.1037/met0000698>. (6) Champely, S. (2020). pwr: Basic functions for power analysis (Version 1.3-0) [Software]. Available from https://CRAN.R-project.org/package=pwr. |
Language: | en-US |
Depends: | R (≥ 3.3.0), stats (≥ 3.0.0), graphics (≥ 3.0.0), base(≥ 3.0.0) |
License: | GPL-3 |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Suggests: | rmarkdown, knitr, markdown |
VignetteBuilder: | rmarkdown, knitr, markdown |
NeedsCompilation: | no |
Packaged: | 2025-08-04 21:35:34 UTC; zucha |
Author: | Zuchao Shen |
Maintainer: | Zuchao Shen <zuchao.shen@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-08-20 20:20:10 UTC |
Optimal Design and Statistical Power for Experimental Studies Investigating Main, Mediation, and Moderation Effects
Description
This package is to help researchers design cost-efficient and well-powered experimental studies investigating main, mediation, and moderation effects (and some combinations). Specifically, this package can (a) identify optimal sample allocations, (b) compare design efficiency between different sample allocations, and (c) perform power analyses with and without accommodating costs and budget.
Details
The package covers seven types of experiments aiming to detect main, moderation, and mediation effects. These experiments are individual randomized controlled trials (RCTs), two-, three-, and four-level cluster-randomized trials (CRTs), two-, three-, and four-level multisite randomized trials (MRTs). The two categorical functions are 'od' and 'power'. The 'od' function can calculate the optimal sample allocation with and without constraint for each type of experiments. The 'power' function by default can calculate required budget (and required sample size) for desired power, minimum detectable effect size (MDES) under a fixed budget, statistical power under a fixed budget. The 'power' function can perform conventional power analyses (e.g., required sample size, power, MDES calculation). The uniform function 're' (or 'rpe') is to compare the relative (precision and) efficiency between two designs with different sample allocations (limited to main effects).
Author(s)
Zuchao Shen, Benjamin Kelcey
Maintainer: Zuchao Shen zuchao.shen@gmail.com (University of Georgia)
Generate optimal design parameters using ant colony optimization
Description
This function can generate a set of optimal design parameters based on given distributions of the rank of optimization target (or budget).
Usage
gen.design.pars(
dist.mean,
dist.rank,
n.of.ants,
nl,
q = 1e-04,
n.of.archive = 100,
xi = 0.5
)
Arguments
dist.mean |
List of means - coordinates |
dist.rank |
Rank of the archived values of the objective function(s) |
n.of.ants |
The number of artificial ants in the search. |
nl |
Neighborhood of the search area |
q |
The locality of the search (0, 1) |
n.of.archive |
The number of the solution archive. |
xi |
The convergence pressure (0, Inf) |
Value
Generated optimal design parameter value(s) (i.e., a matrix with n.of.ants rows and n.of.design.pars columns)
References
Socha, K., & Dorigo, M. (2008). Ant colony optimization for continuous domains. European Journal of Operational Research, 185(3), 1155-1173.
We thank Dr. Krzysztof Socha for providing us the original code (https://iridia.ulb.ac.be/supp/IridiaSupp2008-001/) for this function.
Optimal sample allocation calculation for single-level experiments detecting main effects
Description
The optimal design of single-level experiments detecting main effects
is to choose
the optimal sample allocation that minimizes the variance of
a treatment effect under a fixed budget, which is approximately the optimal
sample allocation that maximizes statistical power under a fixed budget.
The optimal design parameter is
the proportion of individuals to be assigned to treatment (p
).
Usage
od.1(
p = NULL,
r12 = NULL,
c1 = NULL,
c1t = NULL,
m = NULL,
plots = TRUE,
plim = NULL,
varlim = NULL,
plab = NULL,
varlab = NULL,
vartitle = NULL,
verbose = TRUE
)
Arguments
p |
The proportion of individuals to be assigned to treatment. |
r12 |
The proportion of outcome variance explained by covariates. |
c1 |
The cost of sampling one unit in control condition. |
c1t |
The cost of sampling one unit in treatment condition. |
m |
Total budget, default value is the total costs of sampling 60 individuals across treatment conditions. |
plots |
Logical, provide variance plots if TRUE, otherwise not; default value is TRUE. |
plim |
The plot range for p, default value is c(0, 1). |
varlim |
The plot range for variance, default value is c(0, 0.05). |
plab |
The plot label for |
varlab |
The plot label for variance, default value is "Variance". |
vartitle |
The title of variance plot, default value is NULL. |
verbose |
Logical; print the value of |
Value
Unconstrained or constrained optimal sample allocation (p
).
The function also returns the variance of the treatment effect,
function name, design type,
and parameters used in the calculation.
Examples
# Unconstrained optimal design #---------
myod1 <- od.1(r12 = 0.5, c1 = 1, c1t = 5, varlim = c(0, 0.2))
myod1$out # output
# Constrained p, no calculation performed #---------
myod2 <- od.1(r12 = 0.5, c1 = 1, c1t = 5, varlim = c(0, 0.2), p = 0.5)
myod2$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod2)
myre$re # RE = 0.87
# When sampling costs are equal, a balanced design with p = 0.5 is the best #---------
myod3 <- od.1(r12 = 0.5, c1 = 1, c1t = 1, varlim = c(0, 0.2))
myod3$out # output
Optimal sample allocation calculation for single-level randomized controlled trials (RCTs) investigating mediation effects (1-1-1)
Description
The optimal design of single-level RCTs
probing mediation effects is to identify the optimal sample
allocation that use the minimum budget to achieve a fixed level of
statistical power. The optimal design parameter is the proportion of
individuals/units to be assigned to the experimental condition.
This function identifies the optimal p
.
Usage
od.1.111(
a = NULL,
b = NULL,
c1 = NULL,
c1t = NULL,
m = NULL,
r.yx = 0,
r.mx = 0,
r.mw = 0,
q.a = 0,
q.b = 0,
test = "joint",
p = NULL,
n = NULL,
tol = 1e-11,
power = 0.8,
d.p = c(0.1, 0.5),
sig.level = 0.05,
two.tailed = TRUE,
plim = c(0.01, 0.99),
varlim = c(0, 0.001),
plab = NULL,
varlab = NULL,
vartitle = NULL,
nlim = c(6, 1e+06),
verbose = TRUE,
max.value = Inf,
max.iter = 300,
e = 1e-10,
n.of.ants = 10,
n.of.archive = 20,
q = 1e-04,
xi = 0.5
)
Arguments
a |
The treatment effect on the mediator. |
b |
The within-treatment correlation between the outcome and the mediator. |
c1 |
The cost of sampling an individual in the control group. |
c1t |
The cost of sampling an individual in the treated group. |
m |
Total budget. |
r.yx |
The within-treatment correlation between the outcome and the covariate(s) in the outcome model. |
r.mx |
The within-treatment correlation between the mediator and the covariate(s) in the outcome model. |
r.mw |
The within-treatment correlation between the mediator and the covariate(s) in the mediator model. |
q.a |
The number of covariates at the mediator model (except the treatment indicator), the default value is zero. |
q.b |
The number of covariates in the outcome model (except the treatment indicator and the mediator), the default value is zero. |
test |
The type of test will be used to detect mediation effects. The default is the joint significance test (i.e., test = "joint", "Joint","JOINT"). Another choice is the Sobel test by specifying the argument as test = "sobel", "Sobel", or "SOBEL". |
p |
The proportion of level-4 clusters/units to be assigned to treatment. |
n |
Total number of individuals in the experimental study, the default value is NULL. |
tol |
convergence tolerance. |
power |
Statistical power specified, default is .80. |
d.p |
The initial sampling domains for p. Default is c(0.10, 0.50). |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Two tailed test, the default value is TRUE. |
plim |
The plot range for p, default value is c(0, 1). |
varlim |
The plot range for variance, default value is c(0, 0.05). |
plab |
The plot label for |
varlab |
The plot label for variance, default value is "Variance". |
vartitle |
The title of variance plot, default value is NULL. |
nlim |
The interval/range used to numerically solve for n, the default values are c(6, 1e7). |
verbose |
Print out evaluation process if TRUE, default is TRUE. |
max.value |
Maximal value of optimization when used as the stopping criterion. Default is infinite. |
max.iter |
Maximal number of function evaluations when used as the stopping criterion. Default is 300. |
e |
Maximum error value used when solution quality used as the stopping criterion, default is 1e-10. |
n.of.ants |
Number of ants used in each iteration after the initialization stage, the default value is 10. |
n.of.archive |
Size of the solution archive, default is 20. |
q |
Locality of the search (0,1), default is 0.0001. |
xi |
Convergence pressure (0, Inf), suggested: (0, 1), default is 0.5. |
Value
Unconstrained or constrained optimal sample allocation p
).
The function also returns statistical power,
function name, design type,
and parameters used in the calculation.
Examples
myod <- od.1.111(a = .3, b = .5, c1 = 10, c1t = 100)
myod
Jointly optimal sample allocation identification for single-level randomized controlled trials (RCTs) investigating main and moderation effects (1-1-1m)
Description
The optimal design of single-level RCTs
probing main and moderation effects is to identify the jointly optimal sample
allocation that use the minimum budget to achieve targeted
statistical power for both effects. The optimal design parameter
is the proportion of
individuals/units assigned to the experimental condition.
This function uses the ant colony optimization algorithm
to identify the optimal p
.
Usage
od.1.111m(
d = NULL,
gamma = NULL,
n = NULL,
Q = 0.5,
p = NULL,
binary = TRUE,
c1 = NULL,
c1t = NULL,
r12 = NULL,
r.yx = 0,
r.mx = 0,
r.ym = 0,
m = NULL,
q.main = 1,
q.mod = 1,
power.mod = 0.8,
power.main = 0.8,
d.p = c(0.1, 0.5),
sig.level = 0.05,
two.tailed = TRUE,
verbose = TRUE,
nlim = c(20, 1e+07),
max.value = Inf,
max.iter = 300,
e = 1e-10,
n.of.ants = 10,
n.of.archive = 50,
q = 1e-04,
xi = 0.5
)
Arguments
d |
The standardized main effect size. |
gamma |
Moderated treatment effect. |
n |
Total number of individuals. |
Q |
The proportion of individuals in one group the binary moderator. Default value is 0.5, which requires the minimum number of individuals to achieve a targeted power. Change it as necessary. |
p |
The proportion of individuals assigned to the experimental group. |
binary |
Logical. The moderator is binary if TRUE and continuous if FALSE. Default is TRUE. |
c1 |
The cost of sampling one unit in control condition. |
c1t |
The cost of sampling one unit in treatment condition. |
r12 |
The proportion of within-treatment outcome variance explained by covariates in the model that estimated the main effect. |
r.yx |
Within-treatment correlation between the outcome (y) and the covariate (x) for continuous moderators. Within-treatment within-moderator correlation between the outcome (y) and the covariate (x) for binary moderators. |
r.mx |
Within-treatment correlation between the moderator (m) and the covariate (x), if specified, for continuous moderators. |
r.ym |
Within-treatment correlation between the outcome (y) and the moderator (m), if specified, for continuous moderators. |
m |
Total budget. |
q.main |
The number of covariates in the model estimating the main effect (besides the treatment, moderator). The default value is 1. |
q.mod |
The number of covariates in the moderation model (besides the treatment, moderator, and their interaction term). The default value is 1. |
power.mod |
Statistical power specified for the moderation effect. The default value is .80. |
power.main |
Statistical power specified for the main effect. The default value is .80. |
d.p |
The initial sampling domains for p. Default is c(0.10, 0.50). |
sig.level |
Significance level, default value is .05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
verbose |
Print out evaluation process if TRUE. The default value is TRUE. |
nlim |
The range for identifying the root of sample size ( |
max.value |
Maximal value of optimization when used as the stopping criterion. Default is infinite. |
max.iter |
Maximal number of function evaluations when used as the stopping criterion. The default value is 300. |
e |
Maximum error value used when solution quality used as the stopping criterion. The default value is 1e-10. |
n.of.ants |
Number of ants used in each iteration after the initialization stage. The default value is 10. |
n.of.archive |
Size of the solution archive, default is 20. |
q |
Locality of the search (0,1). The default value is 0.0001. |
xi |
Convergence pressure (0, Inf), suggested: (0, 1). The default value is 0.5. |
Value
Unconstrained or constrained optimal sample allocation p
).
The function also returns statistical power for
main and moderation effects,
function name, design type,
and parameters used in the calculation.
Examples
myod <- od.1.111m(d =.1, gamma = .2, r12 = .50,
c1 = 10, c1t = 100)
myod
Optimal sample allocation calculation for two-level CRTs detecting main effects
Description
The optimal design of two-level
cluster randomized trials (CRTs) detecting main effects is to calculate
the optimal sample allocation that minimizes the variance of
a treatment effect under a fixed budget, which is approximately the optimal
sample allocation that maximizes statistical power under a fixed budget.
The optimal design parameters include
the level-1 sample size per level-2 unit (n
)
and the proportion of level-2 clusters/groups to be assigned to treatment (p
).
This function solves the optimal n
and/or p
with and without constraints.
Usage
od.2(
n = NULL,
p = NULL,
icc = NULL,
r12 = NULL,
r22 = NULL,
c1 = NULL,
c2 = NULL,
c1t = NULL,
c2t = NULL,
m = NULL,
plots = TRUE,
plot.by = NULL,
nlim = NULL,
plim = NULL,
varlim = NULL,
nlab = NULL,
plab = NULL,
varlab = NULL,
vartitle = NULL,
verbose = TRUE
)
Arguments
n |
The level-1 sample size per level-2 unit. |
p |
The proportion of level-2 clusters/units to be assigned to treatment. |
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
m |
Total budget, default value is the total costs of sampling 60 level-2 units across treatment conditions. |
plots |
Logical, provide variance plots if TRUE, otherwise not; default value is TRUE. |
plot.by |
Plot the variance by |
nlim |
The plot range for n, default value is c(2, 50). |
plim |
The plot range for p, default value is c(0, 1). |
varlim |
The plot range for variance, default value is c(0, 0.05). |
nlab |
The plot label for |
plab |
The plot label for p, default value is "Proportion Level-2 Units in Treatment: p". |
varlab |
The plot label for variance, default value is "Variance". |
vartitle |
The title of variance plot, default value is NULL. |
verbose |
Logical; print the values of |
Value
Unconstrained or constrained optimal sample allocation (n
and p
).
The function also returns the variance of the treatment effect,
function name, design type,
and parameters used in the calculation.
References
Shen, Z., & Kelcey, B. (2020). Optimal sample allocation under unequal costs in cluster-randomized trials. Journal of Educational and Behavioral Statistics, 45(4): 446–474. <https://doi.org/10.3102/1076998620912418>
Examples
# Unconstrained optimal design #---------
myod1 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50,
varlim = c(0.01, 0.02))
myod1$out # output
# Plot by p
myod1 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50,
varlim = c(0.01, 0.02), plot.by = list(p = 'p'))
# Constrained optimal design with n = 20 #---------
myod2 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50,
n = 20, varlim = c(0.005, 0.025))
myod2$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod2)
myre$re # RE = 0.88
# Constrained optimal design with p = 0.5 #---------
myod3 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50,
p = 0.5, varlim = c(0.005, 0.025))
myod3$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod3)
myre$re # RE = 0.90
# Constrained n and p, no calculation performed #---------
myod4 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50,
n = 20, p = 0.5, varlim = c(0.005, 0.025))
myod4$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod4)
myre$re # RE = 0.83
Optimal sample allocation calculation for two-level CRTs probing mediation effects with cluster-level mediators
Description
The optimal design of two-level
cluster randomized trials (CRTs) probing mediation effects with
cluster-level mediators is to to identify
the optimal sample allocation that requires the minimum budget
to achieve certain power level.
The optimal design parameters include
the level-1 sample size per level-2 unit (n
)
and the proportion of level-2 clusters/groups to be assigned to
treatment (p
).
This function solves the optimal n
and/or p
with and without a constraint.
Usage
od.2.221(
a = NULL,
b = NULL,
d = NULL,
n = NULL,
p = NULL,
icc = NULL,
c1 = NULL,
c1t = NULL,
c2 = NULL,
c2t = NULL,
r12 = NULL,
r22 = NULL,
m = NULL,
r2m = 0,
r.yx = 0,
r.mw = 0,
r.yw = 0,
q.main = 0,
q.a = 0,
q.b = 0,
test = "joint",
tol = 1e-11,
power.med = 0.8,
power.main = 0.8,
d.p = c(0.1, 0.5),
d.n = c(2, 100),
sig.level = 0.05,
two.tailed = TRUE,
Jlim = NULL,
verbose = TRUE,
nrange = c(1.5, 10000),
max.value = Inf,
max.iter = 300,
e = 1e-10,
n.of.ants = 10,
n.of.archive = 50,
q = 1e-04,
xi = 0.5
)
Arguments
a |
The treatment effect on the mediator. |
b |
The within treatment correlation between the outcome and the mediator at the cluster level. |
d |
Effect size. |
n |
The level-1 sample size per level-2 unit. |
p |
The proportion of level-2 clusters/units to be assigned to treatment. |
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
m |
Total budget. |
r2m |
The proportion of mediator variance explained by covariates in the mediator model. |
r.yx |
The correlation between the outcome and the covariate at the individual level. |
r.mw |
The correlation between the mediator and the covariate at the cluster level. |
r.yw |
The correlation between the outcome and the covariate at the cluster level. |
q.main |
The number of covariates in the outcome model testing main effects |
q.a |
The number of covariates in the mediator model (except the treatment indicator). |
q.b |
The number of covariates in the outcome model at the cluster level (except the treatment indicator and the mediator). |
test |
The type of test will be used to detect mediation effects. Default is the joint significance test (i.e., test = "joint"). The other choice is the Sobel test by specifying the argument as test = "sobel". |
tol |
convergence tolerance. |
power.med |
Statistical power specified for mediation. The default value is .80. |
power.main |
Statistical power specified for the total/main effect. The default value is .80. |
d.p |
The initial sampling domains for p. Default is c(0.1, 0.5). |
d.n |
The initial sampling domain for n. Default is c(2, 100). |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Two tailed test, the default value is TRUE. |
Jlim |
The range for J to solve for a numerical solution. Default is c(max(q.a, q.b)+4, 1e6). |
verbose |
Print out evaluation process if TRUE, default is TRUE. |
nrange |
The range of the individual-level sample size per cluster that used to exclude unreasonable values. Default value is c(1.5, 10000). |
max.value |
Maximal value of optimization when used as the stopping criterion. Default is -Inf. |
max.iter |
Maximal number of function evaluations when used as the stopping criterion. |
e |
Maximum error value used when solution quality used as the stopping criterion, default is 1e-10. |
n.of.ants |
Number of ants used in each iteration after the initialization of power analysis for calculating required budget, default value is 10. |
n.of.archive |
Size of the solution archive, default is 100. |
q |
Locality of the search (0,1), default is 0.0001. |
xi |
Convergence pressure (0, Inf), suggested: (0, 1), default is 0.5. |
Value
Unconstrained or constrained optimal sample allocation
(n
and p
).
The function also returns the variance of a mediation effect
or statistical power,
function name, design type,
and parameters used in the calculation.
Optimal sample allocation calculation for two-level CRTs probing moderation effects with cluster-level moderators
Description
The optimal design of two-level
cluster randomized trials (CRTs) probing moderation effects with
cluster-level moderators is to to identify
the optimal sample allocation that requires the minimum budget
to achieve a certain power level.
The optimal design parameters include
the level-1 sample size per level-2 unit (n
)
and the proportion of level-2 clusters/groups to be assigned to
treatment (p
).
This function solves the optimal n
and/or p
with and without a constraint.
Usage
od.2.221m(
d = NULL,
gamma = NULL,
n = NULL,
Q = NULL,
p = NULL,
icc = NULL,
c1 = NULL,
c1t = NULL,
c2 = NULL,
c2t = NULL,
r12 = NULL,
r22 = NULL,
r12m = NULL,
r22m = NULL,
m = NULL,
q.main = 1,
q.mod = 1,
power.mod = 0.8,
power.main = 0.8,
d.p = c(0.1, 0.5),
d.n = c(2, 1000),
sig.level = 0.05,
two.tailed = TRUE,
Jlim = NULL,
verbose = TRUE,
nrange = c(1.5, 10000),
max.value = Inf,
max.iter = 300,
e = 1e-10,
n.of.ants = 10,
n.of.archive = 50,
q = 1e-04,
xi = 0.5
)
Arguments
d |
The standardized main or average treatment effect. |
gamma |
The standardized moderated treatment effect (i.e., regression coefficient of the interaction term of moderator and treatment). |
n |
The level-1 sample size per level-2 unit. |
Q |
The proportion of binary moderator that coded as 1. |
p |
The proportion of level-2 clusters/units to be assigned to treatment. |
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
r12m |
The proportion of outcome variance at the individual level explained by covariates in the model with the moderator. |
r22m |
The proportion of outcome variance at the cluster level explained by covariates in the model with the moderator. |
m |
Total budget. |
q.main |
The number of covariates in the outcome model testing main effects (except the treatment indicator). The default value is 1. |
q.mod |
The number of cluster-level covariates in the model (except the treatment indicator, moderator, and the interaction term). The default value is 1. |
power.mod |
Statistical power specified for moderation. The default value is .80. |
power.main |
Statistical power specified for the total/main effect. The default value is .80. |
d.p |
The initial sampling domain for p. Default is c(0.1, 0.5). |
d.n |
The initial sampling domain for n. Default is c(2, 100). |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Two tailed test, the default value is TRUE. |
Jlim |
The range for J to solve for a numerical solution. Default is c(max(q.mod, q.main)+7, 1e6). |
verbose |
Print out evaluation process if TRUE, default is TRUE. |
nrange |
The range of the individual-level sample size per cluster that used to exclude unreasonable values. Default value is c(1.5, 10000). |
max.value |
Maximal value of optimization when used as the stopping criterion. Default is -Inf. |
max.iter |
Maximal number of function evaluations when used as the stopping criterion. |
e |
Maximum error value used when solution quality used as the stopping criterion, default is 1e-10. |
n.of.ants |
Number of ants used in each iteration after the initialization of power analysis for calculating required budget, default value is 10. |
n.of.archive |
Size of the solution archive, default is 100. |
q |
Locality of the search (0,1), default is 0.0001. |
xi |
Convergence pressure (0, Inf), suggested: (0, 1), default is 0.5. |
Value
Unconstrained or constrained optimal sample allocation
(n
and p
).
The function also returns
function name, design type,
and parameters used in the calculation.
Optimal sample allocation calculation for two-level MRTs detecting main effects
Description
The optimal design of two-level
multisite randomized trials (MRTs) detecting main effects is to calculate
the optimal sample allocation that minimize the budget to achieve a
fixed statistical power (e.g., 80
algorithm. Alternatively, the function can calculate the allocation that
minimizes the variance of a treatment effect under a fixed budget,
which is less precise than the ACO algorithm.
The optimal design parameters include
the level-one sample size per site (n
)
and the proportion of level-one unit to be assigned to treatment (p
).
This function solves the optimal n
and/or p
with and without a constraint.
Usage
od.2m(
n = NULL,
p = NULL,
icc = NULL,
r12 = NULL,
r22m = NULL,
c1 = NULL,
c2 = NULL,
c1t = NULL,
omega = NULL,
m = NULL,
plots = TRUE,
plot.by = NULL,
nlim = NULL,
plim = NULL,
varlim = NULL,
nlab = NULL,
plab = NULL,
varlab = NULL,
vartitle = NULL,
verbose = TRUE,
iter = 100,
tol = 1e-10,
q = 1,
d = 0.1,
power = 0.8,
aco = TRUE,
d.p = c(0.1, 0.5),
d.n = c(2, 1000),
sig.level = 0.05,
two.tailed = TRUE,
Jlim = c(2.5, 1e+10),
nrange = c(2, 10000),
max.value = Inf,
max.iter = 300,
e = 1e-10,
n.of.ants = 10,
n.of.archive = 50,
q.aco = 1e-04,
xi = 0.5
)
Arguments
n |
The level-1 sample size per level-2 unit. |
p |
The proportion of level-1 units within each level 2 unit to be assigned to treatment. |
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22m |
The proportion of variance of site-specific treatment effect explained by covariates. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit (site). |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
omega |
The standardized variance of site-specific treatment effect. |
m |
Total budget, default is the total costs of sampling 60 sites. |
plots |
Logical, provide variance plots if TRUE, otherwise not; default value is TRUE. |
plot.by |
Plot the variance by |
nlim |
The plot range for n, default value is c(2, 50). |
plim |
The plot range for p, default value is c(0, 1). |
varlim |
The plot range for variance, default value is c(0, 0.05). |
nlab |
The plot label for |
plab |
The plot label for |
varlab |
The plot label for variance, default value is "Variance". |
vartitle |
The title of variance plot, default value is NULL. |
verbose |
Logical; print the values of |
iter |
Number of iterations; default value is 100. |
tol |
Tolerance for convergence; default value is 1e-10. |
q |
The number of covariates at level 2. Default is 1. |
d |
Standardized effect size, default is 0.1. |
power |
Statistical power. |
aco |
Logic. If TRUE, the function will use the ant colony optimization (ACO) algorithm to identify optimal allocations. If FALSE, the function will use the first-order derivative method to identify optimal allocations. Default is TRUE. |
d.p |
The initial sampling domains for p. Default is c(0.1, 0.5). |
d.n |
The initial sampling domain for n. Default is c(2, 1000). |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
Jlim |
The range for solving the root of level-2 sample size
( |
nrange |
The range of the level-1 sample size per level-2 unit that used to exclude unreasonable values. Default value is c(2, 10000). |
max.value |
Maximal value of optimization when used as the stopping criterion. Default is -Inf. |
max.iter |
Maximal number of function evaluations when used as the stopping criterion. |
e |
Maximum error value used when solution quality used as the stopping criterion, default is 1e-10. |
n.of.ants |
Number of ants used in each iteration after the initialization of power analysis for calculating required budget, default value is 10. |
n.of.archive |
Size of the solution archive, default is 100. |
q.aco |
Locality of the ACO search (0,1), default is 0.0001. |
xi |
Convergence pressure (0, Inf), suggested: (0, 1), default is 0.5. |
Value
Unconstrained or constrained optimal sample allocation
(n
and p
).
The function also returns the variance of the treatment effect,
function name, design type,
and parameters used in the calculation.
References
Shen, Z., & Kelcey, B. (2022). Optimal sample allocation in multisite randomized trials. The Journal of Experimental Education, 90(3), 693-711. <https://doi.org/10.1080/00220973.2020.1830361>
Examples
# Unconstrained optimal design #---------
myod1 <- od.2m(icc = 0.2, omega = 0.02, r12 = 0.5, r22m = 0.5,
c1 = 1, c2 = 10, c1t = 10,
varlim = c(0, 0.005))
myod1$out
# Constrained optimal design with p = 0.5 #---------
myod2 <- od.2m(icc = 0.2, omega = 0.02,
r12 = 0.5, r22m = 0.5,
c1 = 1, c2 = 10, c1t = 10,
varlim = c(0, 0.005), p = 0.5)
myod2$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod2)
myre$re # RE = 0.81
# Constrained optimal design with n = 5 #---------
myod3 <- od.2m(icc = 0.2, omega = 0.02,
r12 = 0.5, r22m = 0.5, c1 = 1, c2 = 10,
c1t = 10, varlim = c(0, 0.005), n = 5)
myod3$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod3)
myre$re # RE = 0.78
# Constrained n and p, no calculation performed #---------
myod4 <- od.2m(icc = 0.2, omega = 0.02, r12 = 0.5, r22m = 0.5,
c1 = 1, c2 = 10, c1t = 10,
varlim = c(0, 0.005), p = 0.5, n = 10)
myod4$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod4)
myre$re # RE = 0.79
Optimal sample allocation calculation for two-level multisite-randomized trials investigating mediation effects with individual-level mediators (1-1-1)
Description
The optimal design of two-level
multisite-randomized trials (MRTs) probing mediation effects with
individual-level mediators, for the
Sobel test, is to calculate
the optimal sample allocation that minimizes the variance of
a mediation effect under a fixed budget. For the joint significance test, it is to identify
the optimal sample allocation that requires the minimum budget
to achieve certain power level.
The optimal design parameters include
the level-1 sample size per level-2 unit (n
)
and the proportion of level-1 individuals/units to be assigned to treatment (p
).
This function solves the optimal n
and/or p
with and without a constraint.
Usage
od.2m.111(
a = NULL,
b = NULL,
icc.m = NULL,
icc = NULL,
c1 = NULL,
c1t = NULL,
c2 = NULL,
m = NULL,
r12m = 0,
r22m = 0,
r12 = 0,
omega = 0.01,
q.a = 0,
q.b = 3,
test = "joint",
n = NULL,
p = NULL,
iter = 100,
tol = 1e-11,
power = 0.8,
d.p = c(0.1, 0.5),
d.n = c(5, 50),
sig.level = 0.05,
two.tailed = TRUE,
plots = TRUE,
nlim = c(4, 100),
plim = c(0.01, 0.99),
varlim = c(0, 0.001),
nlab = NULL,
plab = NULL,
varlab = NULL,
vartitle = NULL,
Jlim = c(3, 1e+05),
verbose = TRUE,
max.value = Inf,
max.iter = 300,
e = 1e-10,
n.of.ants = 10,
n.of.archive = 50,
q = 1e-04,
xi = 0.5,
plot.by = list(n = "n", p = "p")
)
Arguments
a |
The treatment effect on the mediator. |
b |
The within treatment correlation between the outcome and the mediator. |
icc.m |
The intraclass correlation coefficient for the mediator. |
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2 |
The cost of sampling one level-2 unit (site). |
m |
Total budget. |
r12m |
The proportion of within treatment mediator variance at the level one explained by covariates. |
r22m |
The proportion of treatment-by-site variance explained by covariates. |
r12 |
The proportion of within treatment individual-level outcome variance explained by covariates. |
omega |
The treatment-by-site variance of the outcome. |
q.a |
The number of covariates at the individual level of the mediator model (except the treatment indicator). |
q.b |
The number of covariates in the outcome model (except the treatment indicator and the mediator). |
test |
The type of test will be used to detect mediation effects. Default is the joint significance test (i.e., test = "joint"). Another choice is the Sobel test by specifying the argument as test = "sobel". |
n |
The level-1 sample size per level-2 unit. |
p |
The proportion of level-1 units to be assigned to treatment. |
iter |
number of iteration used for solving roots in the Sobel test. |
tol |
convergence tolerance. |
power |
Statistical power specified, default is .80. |
d.p |
The initial sampling domains for p. Default is c(0.10, 0.50). |
d.n |
The initial sampling domain for n. Default is c(4, 500). |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
plots |
Logical, provide variance plots if TRUE, otherwise not; default value is TRUE. |
nlim |
The plot range for n, default value is c(2, 50). |
plim |
The plot range for p, default value is c(0, 1). |
varlim |
The plot range for variance, default value is c(0, 0.05). |
nlab |
The plot label for |
plab |
The plot label for |
varlab |
The plot label for variance, default value is "Variance". |
vartitle |
The title of variance plot, default value is NULL. |
Jlim |
The range for J to search for a numerical solution. Default is c(3, 10e4). |
verbose |
Print out evaluation process if TRUE, default is TRUE. |
max.value |
Maximal value of optimization when used as the stopping criterion. Default is infinite. |
max.iter |
Maximal number of function evaluations when used as the stopping criterion. Default is 200. |
e |
Maximum error value used when solution quality used as the stopping criterion, default is 1e-10. |
n.of.ants |
Number of ants used in each iteration after the initialization of power analysis for calculating required budget, default value is 10. |
n.of.archive |
Size of the solution archive, default is 100. |
q |
Locality of the search (0,1), default is 0.0001. |
xi |
Convergence pressure (0, Inf), suggested: (0, 1), default is 0.5. |
plot.by |
Plot the variance by |
Value
Unconstrained or constrained optimal sample allocation (n
and p
).
The function also returns statistical power,
function name, design type,
and parameters used in the calculation.
Optimal sample allocation identification for two-level multisite randomized trials (MRTs) investigating main and moderation effects
Description
The optimal design of two-level
MRTs probing main and moderation effects
identify the optimal sample allocations.
The optimal design parameters include
the level-1 sample size per level-2 unit (n
)
and the proportion of level-1 individuals/units assigned to
the experimental group (p
).
This function solves the optimal n
and/or p
with and without a constraint.
Usage
od.2m.mod(
n = NULL,
p = NULL,
icc = NULL,
r12 = NULL,
r22m = NULL,
c1 = NULL,
c2 = NULL,
c1t = NULL,
omega = NULL,
m = NULL,
plots = TRUE,
plot.by = list(n = "n", p = "p"),
verbose = TRUE,
iter = 100,
tol = 1e-10,
q = 1,
q.mod = 1,
d = 0.1,
gamma = 0.1,
power = 0.8,
power.mod = 0.8,
mod.level = 1,
d.p = c(0.1, 0.5),
d.n = c(2, 1000),
sig.level = 0.05,
two.tailed = TRUE,
Jlim = c(2.5, 1e+10),
binary = TRUE,
nrange = c(2, 10000),
Q = 0.5,
max.value = Inf,
max.iter = 300,
e = 1e-10,
n.of.ants = 10,
n.of.archive = 50,
q.aco = 1e-04,
xi = 0.5
)
Arguments
n |
The level-1 sample size per level-2 unit. |
p |
The proportion of level-1 units within each level 2 unit to be assigned to treatment. |
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22m |
The proportion of variance of site-specific treatment effect explained by covariates. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit (site). |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
omega |
The treatment-by-site variance of the outcome. |
m |
Total budget, default is the total costs of sampling 60 sites. |
plots |
Logical, provide variance plots if TRUE, otherwise not; default value is TRUE. |
plot.by |
Plot the variance by |
verbose |
Logical; print the values of |
iter |
Number of iterations; default value is 100. |
tol |
Tolerance for convergence; default value is 1e-10. |
q |
The number of covariates in the model detecting the main/average treatment effect. The default is 1. |
q.mod |
The number of predictors at the moderator level in the moderation model. |
d |
Standardized effect size, default is 0.1. |
gamma |
The standardized moderated treatment effect. |
power |
Statistical power specified for the main effect. The default is .80. |
power.mod |
Statistical power for the moderation effect. The default is .80. |
mod.level |
The level of the moderator is at. The moderator is at level 1 if mod.level is 1, and at level 2 if mod.level is 2. The default is mod.level = 1. |
d.p |
The initial sampling domains for p. Default is c(0.1, 0.5). |
d.n |
The initial sampling domain for n. Default is c(2, 1000). |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
Jlim |
The range for solving the root of level-2 sample size
( |
binary |
Logical; The moderator is binary if TRUE, and continuous if FALSE. The default is TRUE. |
nrange |
The range of the level-1 sample size per level-2 unit that used to exclude unreasonable values. Default value is c(2, 10000). |
Q |
The proportion of units in one group for the binary moderator. Default is 0.5. |
max.value |
Maximal value of optimization when used as the stopping criterion. Default is -Inf. |
max.iter |
Maximal number of function evaluations when used as the stopping criterion. |
e |
Maximum error value used when solution quality used as the stopping criterion, default is 1e-10. |
n.of.ants |
Number of ants used in each iteration after the initialization of power analysis for calculating required budget, default value is 10. |
n.of.archive |
Size of the solution archive, default is 100. |
q.aco |
The locality of the search (0, 1) |
xi |
Convergence pressure (0, Inf), suggested: (0, 1), default is 0.5. |
Value
Unconstrained or constrained optimal sample allocation (n
and p
).
The function also returns statistical power formulas,
function name, design type,
and parameters used in the calculation.
Examples
myod <- od.2m.mod(icc = .2, r12 = .5, r22m = .5,
c1 = 10, c1t = 100, c2 = 50, omega = .01,
gamma = 0.1)
myod$out
Using the first-order derivative method to identify the optimal sample allocations for moderation effects in two-level multisite randomized trials (MRTs)
Description
The optimal design of two-level
MRTs probing moderation effects
identify the optimal sample allocations.
The optimal design parameters include
the level-1 sample size per level-2 unit (n
)
and the proportion of level-1 individuals/units assigned to
the experimental group (p
).
This function solves the optimal n
and/or p
with and without a constraint using the first-order derivative
method to minimize the variance of the moderation effect
estimator. It includes binary or continuous moderators at
level 2 or level 1.
Usage
od.2m.only.mod(
icc = NULL,
r12 = NULL,
r22m = NULL,
c1 = NULL,
c1t = NULL,
c2 = NULL,
omega = 0.01,
Q = 0.5,
n = NULL,
p = NULL,
m = NULL,
iter = 300,
binary = TRUE,
mod.level = 2,
nlim = c(2, 300),
plim = c(0.01, 0.99),
varlim = c(0, 0.005),
by = c("n", "p"),
varlab = "Variance",
nlab = "Level-One Sample Size (n)",
plab = "Proportion (p)",
vartitle = ""
)
Arguments
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22m |
The proportion of variance of site-specific treatment effect explained by covariates. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2 |
The cost of sampling one level-2 unit (site). |
omega |
The standardized variance of site-specific treatment effect. |
Q |
The proportion of units in one group for the binary moderator. Default is 0.5. |
n |
The level-1 sample size per level-2 unit. |
p |
The proportion of level-1 units within each level 2 unit to be assigned to treatment. |
m |
The total cost to plot the variance curve. The default value is the total cost of sampling 60 sites at the optimal allocation. |
iter |
Number of iterations; default value is 100. |
binary |
Logical; The moderator is binary if TRUE, and continuous if FALSE. The default is TRUE. |
mod.level |
The level of the moderator is at. The moderator is at level 1 if mod.level is 1, and at level 2 if mod.level is 2. The default is mod.level = 1. |
nlim |
The plot range for n, default value is c(2, 50). |
plim |
The plot range for p, default value is c(0, 1). |
varlim |
The plot range for variance, default value is c(0, 0.05). |
by |
Dimensions to plot power curves by the optimal design parameters. The default value is by all optimal design parameters for a type of design. For example, default values are by = "p" for single-level designs, by = c("n", "p") for two-level designs, and by = c("n", "p", "J") for three-level designs. |
varlab |
The plot label for variance, default value is "Variance". |
nlab |
The plot label for |
plab |
The plot label for |
vartitle |
The title of variance plot, default value is NULL. |
Examples
myod <- od.2m.only.mod(icc = .2, r12 = .5, r22m = .5,
c1 = 10, c1t = 100, c2 = 50, omega = .01)
myod$out
Optimal sample allocation calculation for three-level CRTs detecting main effects
Description
The optimal design of three-level
cluster randomized trials (CRTs) is to calculate
the optimal sample allocation that minimizes the variance of
treatment effect under fixed budget, which is approximately the optimal
sample allocation that maximizes statistical power under a fixed budget.
The optimal design parameters include
the level-1 sample size per level-2 unit (n
),
the level-2 sample size per level-3 unit (J
),
and the proportion of level-3 clusters/groups to be assigned to treatment (p
).
This function solves the optimal n
, J
and/or p
with and without constraints.
Usage
od.3(
n = NULL,
J = NULL,
p = NULL,
icc2 = NULL,
icc3 = NULL,
r12 = NULL,
r22 = NULL,
r32 = NULL,
c1 = NULL,
c2 = NULL,
c3 = NULL,
c1t = NULL,
c2t = NULL,
c3t = NULL,
m = NULL,
plots = TRUE,
plot.by = NULL,
nlim = NULL,
Jlim = NULL,
plim = NULL,
varlim = NULL,
nlab = NULL,
Jlab = NULL,
plab = NULL,
varlab = NULL,
vartitle = NULL,
verbose = TRUE,
iter = 100,
tol = 1e-10
)
Arguments
n |
The level-1 sample size per level-2 unit. |
J |
The level-2 sample size per level-3 unit. |
p |
The proportion of level-3 clusters/units assigned to treatment. |
icc2 |
The unconditional intraclass correlation coefficient (ICC) at level 2. |
icc3 |
The unconditional intraclass correlation coefficient (ICC) at level 3. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
r32 |
The proportion of level-3 variance explained by covariates. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c3 |
The cost of sampling one level-3 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
c3t |
The cost of sampling one level-3 unit in treatment condition. |
m |
Total budget, default is the total costs of sampling 60 level-3 units across treatment conditions. |
plots |
Logical, provide variance plots if TRUE, otherwise not; default value is TRUE. |
plot.by |
Plot the variance by |
nlim |
The plot range for n, default value is c(2, 50). |
Jlim |
The plot range for J, default value is c(2, 50). |
plim |
The plot range for p, default value is c(0, 1). |
varlim |
The plot range for variance, default value is c(0, 0.05). |
nlab |
The plot label for |
Jlab |
The plot label for |
plab |
The plot label for p, default is "Proportion Level-3 Units in Treatment: p". |
varlab |
The plot label for variance, default value is "Variance". |
vartitle |
The title of variance plot, default value is NULL. |
verbose |
Logical; print the values of |
iter |
Number of iterations; default value is 100. |
tol |
Tolerance for convergence; default value is 1e-10. |
Value
Unconstrained or constrained optimal sample allocation
(n
, J
, and p
).
The function also returns the variance of the treatment effect,
function name, design type,
and parameters used in the calculation.
References
Shen, Z., & Kelcey, B. (2020). Optimal sample allocation under unequal costs in cluster-randomized trials. Journal of Educational and Behavioral Statistics, 45(4): 446–474. <https://doi.org/10.3102/1076998620912418>
Examples
# Unconstrained optimal design #---------
myod1 <- od.3(icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c1t = 1, c2t = 50, c3t = 250,
varlim = c(0.005, 0.025))
myod1$out # output
# Plots by p and J
myod1 <- od.3(icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c1t = 1, c2t = 50, c3t = 250,
varlim = c(0.005, 0.025), plot.by = list(p = 'p', J = 'J'))
# Constrained optimal design with J = 20 #---------
myod2 <- od.3(icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5, J = 20,
c1 = 1, c2 = 5, c3 = 25, c1t = 1, c2t = 50, c3t = 250,
varlim = c(0, 0.025))
myod2$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod2)
myre$re # RE = 0.53
# Constrained optimal design with p = 0.5 #---------
myod3 <- od.3(icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5, p = 0.5,
c1 = 1, c2 = 5, c3 = 25, c1t = 1, c2t = 50, c3t = 250,
varlim = c(0.005, 0.025))
myod3$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod3)
myre$re # RE = 0.84
# Constrained n, J and p, no calculation performed #---------
myod4 <- od.3(icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5, n = 10, J = 10, p = 0.5,
c1 = 1, c2 = 5, c3 = 25, c1t = 1, c2t = 50, c3t = 250,
varlim = c(0, 0.025))
myod4$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod4)
myre$re # RE = 0.61
Optimal sample allocation calculation for three-level MRTs detecting main effects
Description
The optimal design of two-level
multisite randomized trials (MRTs) detecting main effects is to calculate
the optimal sample allocation that minimize the budget to achieve a
fixed statistical power (e.g., 80
algorithm. Alternatively, the function can calculate the optimal allocation
that minimizes the variance of a treatment effect under a fixed budget,
which is less precise than the ACO algorithm.
The optimal design parameters include
the level-1 sample size per level-2 unit (n
),
the level-2 sample size per level-3 unit (J
),
and the proportion of level-2 unit to be assigned to treatment (p
).
This function solves the optimal n
, J
and/or p
with and without constraints.
Usage
od.3m(
n = NULL,
J = NULL,
p = NULL,
icc2 = NULL,
icc3 = NULL,
r12 = NULL,
r22 = NULL,
r32m = NULL,
c1 = NULL,
c2 = NULL,
c3 = NULL,
c1t = NULL,
c2t = NULL,
omega = NULL,
m = NULL,
plots = TRUE,
plot.by = NULL,
nlim = NULL,
Jlim = NULL,
plim = NULL,
varlim = NULL,
nlab = NULL,
Jlab = NULL,
plab = NULL,
varlab = NULL,
Klim = c(6, 1e+10),
q = 1,
d = 0.1,
vartitle = NULL,
verbose = TRUE,
iter = 100,
tol = 1e-10,
power = 0.8,
ACO = TRUE,
d.p = c(0.5, 0.9),
d.n = c(2, 1000),
d.J = c(2, 1000),
sig.level = 0.05,
two.tailed = TRUE,
nrange = c(2, 10000),
Jrange = c(2, 10000),
max.value = Inf,
max.iter = 300,
e = 1e-10,
n.of.ants = 10,
n.of.archive = 50,
q.aco = 1e-04,
xi = 0.5
)
Arguments
n |
The level-1 sample size per level-2 unit. |
J |
The level-2 sample size per level-3 unit. |
p |
The proportion of level-2 units within each level-3 site to be assigned to treatment. |
icc2 |
The unconditional intraclass correlation coefficient (ICC) at level 2. |
icc3 |
The unconditional intraclass correlation coefficient (ICC) at level 3. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
r32m |
The proportion of variance of site-specific treatment effect explained by covariates. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit (site). |
c3 |
The cost of sampling one level-3 unit (site). |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
omega |
The standardized variance of site-specific treatment effect. |
m |
Total budget, default is the total costs of sampling 60 level-3 units. |
plots |
Logical, provide variance plots if TRUE, otherwise not; default value is TRUE. |
plot.by |
Plot the variance by |
nlim |
The plot range for n, default value is c(2, 50). |
Jlim |
The range for solving the root of level-2 sample size
( |
plim |
The plot range for p, default value is c(0, 1). |
varlim |
The plot range for variance, default value is c(0, 0.05). |
nlab |
The plot label for |
Jlab |
The plot label for |
plab |
The plot label for |
varlab |
The plot label for variance, default value is "Variance". |
Klim |
The plot range for K, default value is c(2, 50). |
q |
The number of covariates at level 2. Default is 1. |
d |
Standardized effect size, default is 0.1. |
vartitle |
The title of variance plot, default value is NULL. |
verbose |
Logical; print the values of |
iter |
Number of iterations; default value is 100. |
tol |
Tolerance for convergence; default value is 1e-10. |
power |
Statistical power. |
ACO |
Logic. If TRUE, the function will use the ant colony optimization (ACO) algorithm to identify optimal allocations. If FALSE, the function will use the first-order derivative method to identify optimal allocations. Default is TRUE. |
d.p |
The initial sampling domains for p. Default is c(0.1, 0.5). |
d.n |
The initial sampling domain for n. Default is c(2, 1000). |
d.J |
The initial sampling domain for J. Default is c(2, 1000). |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
nrange |
The range of the level-1 sample size per level-2 unit that used to exclude unreasonable values. Default value is c(2, 10000). |
Jrange |
The range of the level-2 sample size per level-3 unit that used to exclude unreasonable values. Default value is c(2, 10000). |
max.value |
Maximal value of optimization when used as the stopping criterion. Default is -Inf. |
max.iter |
Maximal number of function evaluations when used as the stopping criterion. |
e |
Maximum error value used when solution quality used as the stopping criterion, default is 1e-10. |
n.of.ants |
Number of ants used in each iteration after the initialization of power analysis for calculating required budget, default value is 10. |
n.of.archive |
Size of the solution archive, default is 100. |
q.aco |
Locality of the ACO search (0,1), default is 0.0001. |
xi |
Convergence pressure (0, Inf), suggested: (0, 1), default is 0.5. |
Value
Unconstrained or constrained optimal sample allocation
(n
, J
, and p
).
The function also returns the variance of the treatment effect,
function name, design type,
and parameters used in the calculation.
References
Shen, Z., & Kelcey, B. (2022). Optimal sampling ratios in three-level multisite experiments. Journal of Research on Educational Effectiveness, 15(1), 130-150. <https://doi.org/10.1080/19345747.2021.1953200>
Examples
# Unconstrained optimal design #---------
myod1 <- od.3m(icc2 = 0.2, icc3 = 0.1, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32m = 0.5,
c1 = 1, c2 = 5,
c1t = 1, c2t = 200, c3 = 200,
varlim = c(0, 0.005))
myod1$out # output
# Plots by p and J
myod1 <- od.3m(icc2 = 0.2, icc3 = 0.1, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32m = 0.5,
c1 = 1, c2 = 5,
c1t = 1, c2t = 200, c3 = 200,
varlim = c(0, 0.005), plot.by = list(p = 'p', J = 'J'))
# Constrained optimal design with p = 0.5 #---------
myod2 <- od.3m(icc2 = 0.2, icc3 = 0.1, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32m = 0.5,
c1 = 1, c2 = 5,
c1t = 1, c2t = 200, c3 = 200,
varlim = c(0, 0.005), p = 0.5)
myod2$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod2)
myre$re # RE = 0.81
# Constrained optimal design with n = 5 #---------
myod3 <- od.3m(icc2 = 0.2, icc3 = 0.1, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32m = 0.5,
c1 = 1, c2 = 5,
c1t = 1, c2t = 200, c3 = 200,
varlim = c(0, 0.005), n = 5)
myod3$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod3)
myre$re # RE = 0.89
# Constrained n, J and p, no calculation performed #---------
myod4 <- od.3m(icc2 = 0.2, icc3 = 0.1, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32m = 0.5,
c1 = 1, c2 = 5,
c1t = 1, c2t = 200, c3 = 200,
varlim = c(0, 0.005), p = 0.5, n = 15, J = 20)
myod4$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod4)
myre$re # RE = 0.75
Optimal sample allocation calculation for four-level CRTs detecting main effects
Description
The optimal design of four-level
cluster randomized trials (CRTs) is to calculate
the optimal sample allocation that minimizes the variance of
treatment effect under fixed budget, which is approximately the optimal
sample allocation that maximizes statistical power under a fixed budget.
The optimal design parameters include
the level-1 sample size per level-2 unit (n
),
the level-2 sample size per level-3 unit (J
),
the level-3 sample size per level-4 unit (K
),
and the proportion of level-4 clusters/groups to be assigned to treatment (p
).
This function solves the optimal n
, J
, K
and/or p
with and without constraints.
Usage
od.4(
n = NULL,
J = NULL,
K = NULL,
p = NULL,
icc2 = NULL,
icc3 = NULL,
icc4 = NULL,
r12 = NULL,
r22 = NULL,
r32 = NULL,
r42 = NULL,
c1 = NULL,
c2 = NULL,
c3 = NULL,
c4 = NULL,
c1t = NULL,
c2t = NULL,
c3t = NULL,
c4t = NULL,
m = NULL,
plots = TRUE,
plot.by = NULL,
nlim = NULL,
Jlim = NULL,
Klim = NULL,
plim = NULL,
varlim = NULL,
nlab = NULL,
Jlab = NULL,
Klab = NULL,
plab = NULL,
varlab = NULL,
vartitle = NULL,
verbose = TRUE,
iter = 100,
tol = 1e-10
)
Arguments
n |
The level-1 sample size per level-2 unit. |
J |
The level-2 sample size per level-3 unit. |
K |
The level-3 sample size per level-4 unit. |
p |
The proportion of level-4 clusters/units to be assigned to treatment. |
icc2 |
The unconditional intraclass correlation coefficient (ICC) at level 2. |
icc3 |
The unconditional intraclass correlation coefficient (ICC) at level 3. |
icc4 |
The unconditional intraclass correlation coefficient (ICC) at level 4. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
r32 |
The proportion of level-3 variance explained by covariates. |
r42 |
The proportion of level-4 variance explained by covariates. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c3 |
The cost of sampling one level-3 unit in control condition. |
c4 |
The cost of sampling one level-4 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
c3t |
The cost of sampling one level-3 unit in treatment condition. |
c4t |
The cost of sampling one level-4 unit in treatment condition. |
m |
Total budget, default value is the total costs of sampling 60 level-4 units across treatment conditions. |
plots |
Logical, provide variance plots if TRUE, otherwise not; default value is TRUE. |
plot.by |
Plot the variance by |
nlim |
The plot range for n, default value is c(2, 50). |
Jlim |
The plot range for J, default value is c(2, 50). |
Klim |
The plot range for K, default value is c(2, 50). |
plim |
The plot range for p, default value is c(0, 1). |
varlim |
The plot range for variance, default value is c(0, 0.05). |
nlab |
The plot label for |
Jlab |
The plot label for |
Klab |
The plot label for |
plab |
The plot label for |
varlab |
The plot label for variance, default value is "Variance". |
vartitle |
The title of variance plot, default value is NULL. |
verbose |
Logical; print the values of |
iter |
Number of iterations; default value is 100. |
tol |
Tolerance for convergence; default value is 1e-10. |
Value
Unconstrained or constrained optimal sample allocation
(n
, J
, K
, and p
).
The function also returns the variance of the treatment effect,
function name, design type,
and parameters used in the calculation.
Examples
# Unconstrained optimal design #---------
myod1 <- od.4(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c4 = 125,
c1t = 1, c2t = 50, c3t = 250, c4t = 2500,
varlim = c(0, 0.01))
myod1$out # output
# Plots by p and K
myod1 <- od.4(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c4 = 125,
c1t = 1, c2t = 50, c3t = 250, c4t = 2500,
varlim = c(0, 0.01), plot.by = list(p = 'p', K = 'K'))
# Constrained optimal design with p = 0.5 #---------
myod2 <- od.4(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, p = 0.5,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c4 = 125,
c1t = 1, c2t = 50, c3t = 250, c4t = 2500,
varlim = c(0, 0.01))
myod2$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod2)
myre$re # RE = 0.78
# Constrained optimal design with K = 20 #---------
myod3 <- od.4(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, K = 20,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c4 = 125,
c1t = 1, c2t = 50, c3t = 250, c4t = 2500,
varlim = c(0, 0.01))
myod3$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod3)
myre$re # RE = 0.67
# Constrained n, J, K and p, no calculation performed #---------
myod4 <- od.4(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05,
r12 = 0.5, n = 10, J = 10, K = 20, p = 0.5,
r22 = 0.5, r32 = 0.5, r42 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c4 = 125,
c1t = 1, c2t = 50, c3t = 250, c4t = 2500,
varlim = c(0, 0.01))
myod4$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod4)
myre$re # RE = 0.27
Optimal sample allocation calculation for four-level MRTs detecting main effects
Description
The optimal design of four-level
multisite randomized trials (MRTs) is to calculate
the optimal sample allocation that minimizes the variance of
treatment effect under fixed budget, which is approximately the optimal
sample allocation that maximizes statistical power under a fixed budget.
The optimal design parameters include
the level-1 sample size per level-2 unit (n
),
the level-2 sample size per level-3 unit (J
),
the level-3 sample size per level-4 unit (K
),
and the proportion of level-3 units to be assigned to treatment (p
).
This function solves the optimal n
, J
, K
and/or p
with and without constraints.
Usage
od.4m(
n = NULL,
J = NULL,
K = NULL,
p = NULL,
icc2 = NULL,
icc3 = NULL,
icc4 = NULL,
r12 = NULL,
r22 = NULL,
r32 = NULL,
r42m = NULL,
c1 = NULL,
c2 = NULL,
c3 = NULL,
c4 = NULL,
c1t = NULL,
c2t = NULL,
c3t = NULL,
omega = NULL,
m = NULL,
plots = TRUE,
plot.by = NULL,
nlim = NULL,
Jlim = NULL,
Klim = NULL,
plim = NULL,
varlim = NULL,
nlab = NULL,
Jlab = NULL,
Klab = NULL,
plab = NULL,
varlab = NULL,
vartitle = NULL,
verbose = TRUE,
iter = 100,
tol = 1e-10
)
Arguments
n |
The level-1 sample size per level-2 unit. |
J |
The level-2 sample size per level-3 unit. |
K |
The level-3 sample size per level-4 unit. |
p |
The proportion of level-3 units to be assigned to treatment. |
icc2 |
The unconditional intraclass correlation coefficient (ICC) at level 2. |
icc3 |
The unconditional intraclass correlation coefficient (ICC) at level 3. |
icc4 |
The unconditional intraclass correlation coefficient (ICC) at level 4. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
r32 |
The proportion of level-3 variance explained by covariates. |
r42m |
The proportion of variance of site-specific treatment effect explained by covariates. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c3 |
The cost of sampling one level-3 unit in control condition. |
c4 |
The cost of sampling one level-4 unit (site). |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
c3t |
The cost of sampling one level-3 unit in treatment condition. |
omega |
The standardized variance of site-specific treatment effect. |
m |
Total budget, default is the total costs of sampling 60 level-4 units. |
plots |
Logical, provide variance plots if TRUE, otherwise not; default value is TRUE. |
plot.by |
Plot the variance by |
nlim |
The plot range for n, default value is c(2, 50). |
Jlim |
The plot range for J, default value is c(2, 50). |
Klim |
The plot range for K, default value is c(2, 50). |
plim |
The plot range for p, default value is c(0, 1). |
varlim |
The plot range for variance, default value is c(0, 0.05). |
nlab |
The plot label for |
Jlab |
The plot label for |
Klab |
The plot label for |
plab |
The plot label for |
varlab |
The plot label for variance, default value is "Variance". |
vartitle |
The title of variance plot, default value is NULL. |
verbose |
Logical; print the values of |
iter |
Number of iterations; default value is 100. |
tol |
Tolerance for convergence; default value is 1e-10. |
Value
Unconstrained or constrained optimal sample allocation
(n
, J
, K
, and p
).
The function also returns the variance of the treatment effect,
function name, design type,
and parameters used in the calculation.
Examples
# Unconstrained optimal design #---------
myod1 <- od.4m(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42m = 0.5,
c1 = 1, c2 = 5, c3 = 25,
c1t = 1, c2t = 50, c3t = 250, c4 = 500,
varlim = c(0, 0.005))
myod1$out # output
# Plots by p and K
myod1 <- od.4m(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42m = 0.5,
c1 = 1, c2 = 5, c3 = 25,
c1t = 1, c2t = 50, c3t = 250, c4 = 500,
varlim = c(0, 0.005), plot.by = list(p = 'p', K = 'K'))
# Constrained optimal design with p = 0.5 #---------
myod2 <- od.4m(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42m = 0.5,
c1 = 1, c2 = 5, c3 = 25,
c1t = 1, c2t = 50, c3t = 250, c4 = 500,
varlim = c(0, 0.005), p = 0.5)
myod2$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod2)
myre$re # RE = 0.88
# Constrained optimal design with J = 20 #---------
myod3 <- od.4m(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42m = 0.5,
c1 = 1, c2 = 5, c3 = 25,
c1t = 1, c2t = 50, c3t = 250, c4 = 500,
varlim = c(0, 0.005), J = 20)
myod3$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod3)
myre$re # RE = 0.58
# Constrained n, J, K and p, no calculation performed #---------
myod4 <- od.4m(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42m = 0.5,
c1 = 1, c2 = 5, c3 = 25,
c1t = 1, c2t = 50, c3t = 250, c4 = 500,
varlim = c(0, 0.005), p = 0.5, n = 15, J = 20, K = 5)
myod4$out
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod4)
myre$re # RE = 0.46
Plot statistical power curves under a fixed budget across optimal design parameters
Description
This function plots statistical power curves (for main, moderation, and/or mediation effects) under a fixed budget across optimal design parameters.
Usage
## S3 method for class 'power'
plot(
expr,
nlim = c(2, 300),
plim = c(0.01, 0.99),
powerlim = c(0, 1),
plot.title = NULL,
m = NULL,
by = c("n", "p"),
legend = TRUE,
nlab = "Level-One Sample Size (n)",
plab = "Proportion (p)",
Jlab = "Level-Two Sample Size (J)",
powerlab = "Statistical Power"
)
Arguments
expr |
Returned objects from an od function (e.g., od.2m, od.2m.mod). |
nlim |
The plot range for n, default value is c(2, 50). |
plim |
The plot range for p, default value is c(0, 1). |
powerlim |
The limit for plotting power curves. |
plot.title |
The title of the plot (e.g., plot.title = "Power Curves"). The default is NULL. |
m |
Total budget, default is the total costs of sampling 60 sites. |
by |
Dimensions to plot power curves by the optimal design parameters. The default value is by all optimal design parameters for a type of design. For example, default values are by = "p" for single-level designs, by = c("n", "p") for two-level designs, and by = c("n", "p", "J") for three-level designs. |
legend |
Logical; present plot legend if TRUE. The default is TRUE. |
nlab |
Label for the x-axis when the plot is by the optimal design parameter "n". |
plab |
Label for the x-axis when the plot is by the optimal design parameter "p". |
Jlab |
Label for the x-axis when the plot is by the optimal design parameter "J". |
powerlab |
The label for the statistical power. |
Budget and/or sample size, power, MDES calculation for single-level experiments detecting main effects
Description
This function can calculate required budget for desired power, power or minimum detectable effect size (MDES) under fixed budget for single-level experiments. It also can perform conventional power analyses (e.g., required sample size, power, and MDES calculation).
Usage
power.1(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
d = NULL,
power = NULL,
m = NULL,
n = NULL,
p = NULL,
r12 = NULL,
q = 1,
c1 = NULL,
c1t = NULL,
dlim = NULL,
powerlim = NULL,
nlim = NULL,
mlim = NULL,
rounded = TRUE
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for desired power, power/MDES under fixed budget) if TRUE, otherwise conventional power analyses (e.g., required sample size, power, or MDES calculation); default value is TRUE. |
expr |
Returned object from function |
constraint |
Specify the constrained value of
|
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
d |
Effect size. |
power |
Statistical power. |
m |
Total budget. |
n |
The total sample size. |
p |
The proportion of individuals to be assigned to treatment. |
r12 |
The proportion of outcome variance explained by covariates. |
q |
The number of covariates. Default is 1. |
c1 |
The cost of sampling one unit in control condition. |
c1t |
The cost of sampling one unit in treatment condition. |
dlim |
The range for solving the root of effect size ( |
powerlim |
The range for solving the root of power ( |
nlim |
The range for searching the root of sample size ( |
mlim |
The range for searching the root of budget ( |
rounded |
Logical; round |
Value
Required budget (or required sample size), statistical power, or MDES depending on the specification of parameters. The function also returns the function name, design type, and parameters used in the calculation.
Examples
# Unconstrained optimal design
myod1 <- od.1(r12 = 0.5, c1 = 1, c1t = 5, varlim = c(0, 0.2))
myod1$out # p = 0.31
# ------- Power analyses by default considering costs and budget -------
# Required budget and sample size
mym.1 <- power.1(expr = myod1, d = 0.2, q = 1, power = 0.8)
mym.1$out # m = 1032 n = 461
# mym.1$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
mym.1 <- power.1(d = 0.2, power = 0.8, c1 = 1, c1t = 5,
r12 = 0.5, p = 0.31, q = 1)
# Required budget and sample size with constrained p
mym.2 <- power.1(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5))
mym.2$out # m = 1183, n = 394
# Power calculation
mypower <- power.1(expr = myod1, q = 1, d = 0.2, m = 1032)
mypower$out # power = 0.80
# Power calculation under constrained p (p = 0.5)
mypower.1 <- power.1(expr = myod1, q = 1, d = 0.2, m = 1032,
constraint = list(p = 0.5))
mypower.1$out # power = 0.74
# MDES calculation
mymdes <- power.1(expr = myod1, q = 1, power = 0.80, m = 1032)
mymdes$out # d = 0.20
# ------- Conventional power analyses with cost.model = FALSE-------
# Required sample size n
myn <- power.1(cost.model = FALSE, expr = myod1, d = 0.2, q = 1, power = 0.8)
myn$out # n = 461
# myn$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
myn <- power.1(cost.model = FALSE, d = 0.2, power = 0.8,
r12 = 0.5, p = 0.31, q = 1)
# Power calculation
mypower1 <- power.1(cost.model = FALSE, expr = myod1, n = 461, d = 0.2, q = 1)
mypower1$out # power = 0.80
# MDES calculation
mymdes1 <- power.1(cost.model = FALSE, expr = myod1, n = 461, power = 0.8, q = 1)
mymdes1$out # d = 0.20
Budget and/or sample size, power, MDES calculation for single-level randomized controlled trials (RCTs) investigating mediation effects
Description
This function can calculate required budget for desired power and power under a fixed budget for RCTs probing mediation effects. It also can perform conventional power analyses (e.g., required sample size and power calculation).
Usage
power.1.111(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
a = NULL,
b = NULL,
power = NULL,
m = NULL,
test = NULL,
n = NULL,
p = NULL,
c1 = NULL,
c1t = NULL,
r.yx = 0,
r.mx = 0,
r.mw = 0,
q.a = 0,
q.b = 0,
max.iter = 300,
alim = c(0, 4),
blim = c(0.01, 0.99),
powerlim = NULL,
nlim = c(6, 1e+07),
mlim = NULL
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for a desired power, power under fixed budget) if TRUE. Otherwise, conventional power analyses are performed (e.g., required sample size and power calculation); default value is TRUE. |
expr |
Returned object from function |
constraint |
If specified, the constrained value of
|
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Two tailed test, the default value is TRUE. |
a |
The treatment effect on the mediator. |
b |
The within-treatment correlation between the outcome and the mediator. |
power |
Statistical power specified, default is .80. |
m |
Total budget. |
test |
The type of test will be used to detect mediation effects. The default is the NULL or the one used in the expr Choices are the joint significance test (i.e., test = "joint", "Joint","JOINT") or the Sobel test (test = "sobel", "Sobel", or "SOBEL"). |
n |
Total number of individuals in the experimental study, the default value is NULL. |
p |
The proportion of level-4 clusters/units to be assigned to treatment. |
c1 |
The cost of sampling an individual in the control group. |
c1t |
The cost of sampling an individual in the treated group. |
r.yx |
The within-treatment correlation between the outcome and the covariate(s) in the outcome model. |
r.mx |
The within-treatment correlation between the mediator and the covariate(s) in the outcome model. |
r.mw |
The within-treatment correlation between the mediator and the covariate(s) in the mediator model. |
q.a |
The number of covariates at the mediator model (except the treatment indicator), the default value is zero. |
q.b |
The number of covariates in the outcome model (except the treatment indicator and the mediator), the default value is zero. |
max.iter |
Maximal number of function evaluations when used as the stopping criterion. Default is 300. |
alim |
The range for identifying the root of a path
effect ( |
blim |
The range for identifying the root of b path within-treatment
correlation between the mediator and outcome ( |
powerlim |
The range for solving the root of power ( |
nlim |
The interval/range used to numerically solve for n, the default values are c(6, 1e7). |
mlim |
The range for identifying the root of budget ( |
Value
Required budget (or required sample size), statistical power,
(a
) , or (b
) depending on the specification of parameters.
The function also returns the function name, design type,
and parameters used in the calculation.
Examples
# Optimal design and power analyses accommodating costs and budget
myod <- od.1.111(a = .3, b = .5, c1 = 10, c1t = 100)
# myod
mypower <- power.1.111(expr = myod, power = .8)
#mypower
# Conventional power analyses
mypower <- power.1.111(cost.model = FALSE, a = .3, b = .5, test = "joint",
power = .8, p =.5)
#mypower
mypower <- power.1.111(cost.model = FALSE, n = 350, b = .5, test = "joint",
power = .8, p =.5)
#mypower
Budget and/or sample size, power, MDES calculation for single-level randomized controlled trials (RCTs) investigating moderation effects (1-1-1m)
Description
This function can calculate required budget for desired power, the minimum detectable effect size, and statistical power under a fixed budget in randomized controlled trials (RCTs) probing moderation effects. It also can perform conventional power analyses (e.g., required sample size calculation, minimum detectable effect size calculation, and power calculation).
Usage
power.1.111m(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
gamma = NULL,
binary = TRUE,
power = NULL,
m = NULL,
n = NULL,
p = NULL,
Q = 0.5,
c1 = NULL,
c1t = NULL,
r.yx = 0,
r.mx = 0,
r.ym = 0,
q.mod = 1,
gammalim = c(0.005, 5),
powerlim = c(1e-04, 0.9999),
nlim = c(20, 1e+07),
mlim = NULL
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for a desired power, power under fixed budget) if TRUE. Otherwise, conventional power analyses are performed (e.g., required sample size and power calculation); default value is TRUE. |
expr |
Returned object from function |
constraint |
If specified, the constrained value of
|
sig.level |
Significance level, default value is .05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
gamma |
Moderated treatment effect. |
binary |
Logical. The moderator is binary if TRUE and continuous if FALSE. Default is TRUE. |
power |
Statistical power. |
m |
Total budget. |
n |
Total number of individuals. |
p |
The proportion of individuals assigned to the experimental group. |
Q |
The proportion of individuals in one group the binary moderator. Default value is 0.5, which requires the minimum number of individuals to achieve a targeted power. Change it as necessary. |
c1 |
The cost of sampling one unit in control condition. |
c1t |
The cost of sampling one unit in treatment condition. |
r.yx |
Within-treatment correlation between the outcome (y) and the covariate (x) for continuous moderators. Within-treatment within-moderator correlation between the outcome (y) and the covariate (x) for binary moderators. |
r.mx |
Within-treatment correlation between the moderator (m) and the covariate (x), if specified, for continuous moderators. |
r.ym |
Within-treatment correlation between the outcome (y) and the moderator (m), if specified, for continuous moderators. |
q.mod |
The number of covariates in the moderation model (besides the treatment, moderator, and their interaction term). The default value is 1. |
gammalim |
The range for identifying the root of moderation
effect size ( |
powerlim |
The range for identifying the root of power
( |
nlim |
The range for identifying the root of sample size ( |
mlim |
The range for identifying the root of budget ( |
Value
Required budget (m
) or required sample size (n
),
statistical power(power
),
minimum detectable moderation effect size (gamma
),
depending on the specification of parameters.
The function also returns the function name, design type,
and parameters used in the calculation.
Examples
# Optimal design and power analyses accommodating costs and budget
myod <- od.1.111m(d =.1, gamma = .2, r12 = .50,
c1 = 10, c1t = 100)
myod
N <- power.1.111m(expr = myod, power = .8)
N$out
# Conventional power analyses
# Required sample size for a binary moderator
N <- power.1.111m(cost.model = FALSE, gamma = .2, power = .8, p =.5)
N
# Required sample size for a continuous moderator
N <- power.1.111m(cost.model = FALSE,
gamma = .2, power = .8, p =.5, binary = FALSE)
N
Budget and/or sample size, power, MDES calculation for two-level CRTs detecting main effects
Description
This function can calculate required budget for desired power, power or minimum detectable effect size (MDES) under fixed budget for two-level cluster randomized trials (CRTs). It also can perform conventional power analyses (e.g., required sample size, power, and MDES calculation).
Usage
power.2(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
d = NULL,
power = NULL,
m = NULL,
n = NULL,
J = NULL,
p = NULL,
icc = NULL,
r12 = NULL,
r22 = NULL,
q = NULL,
c1 = NULL,
c2 = NULL,
c1t = NULL,
c2t = NULL,
dlim = NULL,
powerlim = NULL,
Jlim = NULL,
mlim = NULL,
rounded = TRUE
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for desired power, power/MDES under fixed budget) if TRUE, otherwise conventional power analyses (e.g., required sample size, power, or MDES calculation); default value is TRUE. |
expr |
Returned object from function |
constraint |
Specify the constrained values of |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
d |
Effect size. |
power |
Statistical power. |
m |
Total budget. |
n |
The level-1 sample size per level-2 unit. |
J |
The total level-2 sample size. |
p |
The proportion of level-2 clusters/units to be assigned to treatment. |
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
q |
The number of level-2 covariates. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
dlim |
The range for solving the root of effect size ( |
powerlim |
The range for solving the root of power ( |
Jlim |
The range for searching the root of level-2 sample size ( |
mlim |
The range for searching the root of budget ( |
rounded |
Logical; round |
Value
Required budget (and/or required level-2 sample size), statistical power, or MDES depending on the specification of parameters. The function also returns the function name, design type, and parameters used in the calculation.
References
Shen, Z., & Kelcey, B. (2020). Optimal sample allocation under unequal costs in cluster-randomized trials. Journal of Educational and Behavioral Statistics, 45(4): 446–474. <https://doi.org/10.3102/1076998620912418>
Examples
# Unconstrained optimal design
myod1 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50)
myod1$out # n = 8.9, p = 0.33
# ------- Power analyses by default considering costs and budget -------
# Required budget and sample size
mym.1 <- power.2(expr = myod1, d = 0.2, q = 1, power = 0.8)
mym.1$out # m = 3755, J = 130.2
#mym.1$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
mym.1 <- power.2(d = 0.2, power = 0.8, icc = 0.2,
c1 = 1, c2 = 5, c1t = 1, c2t = 50,
r12 = 0.5, r22 = 0.5, n = 9, p = 0.33, q = 1)
# Required budget and sample size with constrained p
mym.2 <- power.2(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5))
mym.2$out # m = 4210, J = 115.3
# Required budget and sample size with constrained p and n
mym.3 <- power.2(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5, n = 20))
mym.3$out # m = 4568, J = 96.2
# Power calculation
mypower <- power.2(expr = myod1, q = 1, d = 0.2, m = 3755)
mypower$out # power = 0.80
# Power calculation under constrained p (p = 0.5)
mypower.1 <- power.2(expr = myod1, q = 1, d = 0.2, m = 3755,
constraint = list(p = 0.5))
mypower.1$out # power = 0.75
# MDES calculation
mymdes <- power.2(expr = myod1, q = 1, power = 0.80, m = 3755)
mymdes$out # d = 0.20
# ------- Conventional power analyses with cost.model = FALSE-------
# Required J
myJ <- power.2(cost.model = FALSE, expr = myod1, d = 0.2, q = 1, power = 0.8)
myJ$out # J = 130.2
#myJ$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
myJ <- power.2(cost.model = FALSE, d = 0.2, power = 0.8, icc = 0.2,
r12 = 0.5, r22 = 0.5, n = 9, p = 0.33, q = 1)
# Power calculation
mypower1 <- power.2(cost.model = FALSE, expr = myod1, J = 130, d = 0.2, q = 1)
mypower1$out # power = 0.80
# MDES calculation
mymdes1 <- power.2(cost.model = FALSE, expr = myod1, J = 130, power = 0.8, q = 1)
mymdes1$out # d = 0.20
Budget and/or sample size, power calculation for CRTs probing mediation effects with cluster-level mediators
Description
This function can calculate required budget for desired power and power under a fixed budget for experimental studies with group mediators probing mediation effects. It also can perform conventional power analyses (e.g., required sample size and power calculation).
Usage
power.2.221(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
a = NULL,
b = NULL,
test = "joint",
n = NULL,
p = NULL,
power = NULL,
J = NULL,
m = NULL,
c1 = NULL,
c1t = NULL,
c2 = NULL,
c2t = NULL,
r2m = r2m,
r.yx = 0,
r.mw = 0,
r.yw = 0,
icc = NULL,
q = 0,
q.a = 0,
q.b = 0,
powerlim = NULL,
Jlim = NULL,
mlim = NULL
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for desired power, power/MDES under fixed budget) if TRUE, otherwise conventional power analyses (e.g., required sample size, power, or MDES calculation); default value is TRUE. |
expr |
returned object from function |
constraint |
specify the constrained value of
|
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
a |
The treatment effect on the mediator. |
b |
The within treatment correlation between the outcome and the mediator at the cluster level. |
test |
The type of test will be used to detect mediation effects. Default is the joint significance test (i.e., test = "joint"). The other choice is the Sobel test by specifying the argument as test = "sobel". |
n |
The level-1 sample size per level-2 unit. |
p |
The proportion of level-2 clusters/units to be assigned to treatment. |
power |
Statistical power. |
J |
The total level-2 sample size. |
m |
Total budget. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
r2m |
The proportion of mediator variance explained by covariates in the mediator model. |
r.yx |
The correlation between the outcome and the covariate at the individual level. |
r.mw |
The correlation between the mediator and the covariate at the cluster level. |
r.yw |
The correlation between the outcome and the covariate at the cluster level. |
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
q |
The number of level-2 covariates. |
q.a |
The number of covariates in the mediator model (except the treatment indicator). |
q.b |
The number of covariates in the outcome model at the cluster level (except the treatment indicator and the mediator). |
powerlim |
The range for solving the root of power ( |
Jlim |
The range for searching the root of level-2 sample size ( |
mlim |
the range for searching the root of budget ( |
Value
Required budget (or required sample size), statistical power, or MDES depending on the specification of parameters. The function also returns the function name, design type, and parameters used in the calculation.
Budget and/or sample size, power, MDES calculation for two-level MRTs detecting main effects
Description
This function can calculate required budget for desired power, power or minimum detectable effect size (MDES) under fixed budget for two-level multisite randomized trials (MRTs). It also can perform conventional power analyses (e.g., required sample size, power, and MDES calculation).
Usage
power.2m(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
d = NULL,
power = NULL,
m = NULL,
n = NULL,
J = NULL,
p = NULL,
icc = NULL,
r12 = NULL,
r22m = NULL,
q = 1,
c1 = NULL,
c2 = NULL,
c1t = NULL,
omega = NULL,
dlim = NULL,
powerlim = NULL,
Jlim = NULL,
mlim = NULL,
rounded = TRUE
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for desired power, power/MDES under fixed budget) if TRUE, otherwise conventional power analyses (e.g., required sample size, power, or MDES calculation); default value is TRUE. |
expr |
Returned objects from function |
constraint |
Specify the constrained values of |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
d |
Effect size. |
power |
Statistical power. |
m |
Total budget. |
n |
The level-1 sample size per level-2 unit. |
J |
The number of sites. |
p |
The proportion of level-1 units to be assigned to treatment. |
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22m |
The proportion of variance of site-specific treatment effect explained by covariates. |
q |
The number of covariates at level 2. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit (site). |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
omega |
The standardized variance of site-specific treatment effect. |
dlim |
The range for solving the root of effect size ( |
powerlim |
The range for solving the root of power ( |
Jlim |
The range for searching the root of level-2 sample size ( |
mlim |
The range for searching the root of budget ( |
rounded |
Logical; round the values of |
Value
Required budget (and/or required level-2 sample size), statistical power, or MDES depending on the specification of parameters. The function also returns the function name, design type, and parameters used in the calculation.
References
Shen, Z., & Kelcey, B. (2022). Optimal sample allocation in multisite randomized trials. The Journal of Experimental Education, 90(3), 693-711. <https://doi.org/10.1080/00220973.2020.1830361
Examples
# Unconstrained optimal design #---------
myod1 <- od.2m(icc = 0.2, omega = 0.02, r12 = 0.5, r22m = 0.5,
c1 = 1, c2 = 10, c1t = 10,
varlim = c(0, 0.005))
myod1$out # n = 23.5, p = 0.24
# ------- Power analyses by default considering costs and budget -------
# Required budget and sample size
mym.1 <- power.2m(expr = myod1, d = 0.2, q = 1, power = 0.8)
mym.1$out # m = 1882, J = 22.8
# mym.1$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
mym.1 <- power.2m(d = 0.2, power = 0.8, q = 1,
icc = 0.2, omega = 0.02, r12 = 0.5, r22m = 0.5,
c1 = 1, c2 = 10, c1t = 10,
n = 23.5, p = 0.24)
# Required budget and sample size with constrained p
mym.2 <- power.2m(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5))
mym.2$out # m = 2424, J = 18
# Required budget and sample size with constrained p and n
mym.3 <- power.2m(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5, n = 5))
mym.3$out # m = 2502, J = 66.7
# Power calculation
mypower <- power.2m(expr = myod1, q = 1, d = 0.2, m = 1882)
mypower$out # power = 0.80
# Power calculation under constrained p (p = 0.5)
mypower.1 <- power.2m(expr = myod1, q = 1, d = 0.2, m = 1882,
constraint = list(p = 0.5))
mypower.1$out # power = 0.68
# MDES calculation
mymdes <- power.2m(expr = myod1, q = 1, power = 0.80, m = 1882)
mymdes$out # d = 0.20
# ------- Conventional power analyses with cost.model = FALSE-------
# Required sample size
myJ <- power.2m(cost.model = FALSE, expr = myod1, d = 0.2,
q = 1, power = 0.8)
myJ$out # J = 22.8
# myL$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
myJ <- power.2m(cost.model = FALSE, d = 0.2, power = 0.8, q = 1,
icc = 0.2, omega = 0.02, r12 = 0.5, r22m = 0.5,
c1 = 1, c2 = 10, c1t = 10,
n = 23.5, p = 0.24)
# Power calculation
mypower1 <- power.2m(cost.model = FALSE, expr = myod1, J = 22.8,
d = 0.2, q = 1)
mypower1$out # power = 0.80
# MDES calculation
mymdes1 <- power.2m(cost.model = FALSE, expr = myod1, J = 22.8,
power = 0.8, q = 1)
mymdes1$out # d = 0.20
Budget and/or sample size, power, MDES calculation for MRTs investigating mediation effects with individual-level mediators
Description
This function can calculate required budget for desired power and power under a fixed budget for multisite-randomized trials (MRTs) with individual mediators probing mediation effects. It also can perform conventional power analyses (e.g., required sample size and power calculation).
Usage
power.2m.111(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
a = NULL,
b = NULL,
power = NULL,
m = NULL,
test = NULL,
n = NULL,
p = NULL,
c1 = NULL,
c1t = NULL,
c2 = NULL,
r12 = 0,
r22m = 0,
r12m = 0,
icc.m = NULL,
omega = NULL,
icc = NULL,
J = NULL,
q = 0,
q.a = 0,
q.b = 0,
max.iter = 300,
powerlim = NULL,
Jlim = NULL,
mlim = NULL,
rounded = TRUE
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for desired power, power/MDES under fixed budget) if TRUE, otherwise conventional power analyses (e.g., required sample size, power, or MDES calculation); default value is TRUE. |
expr |
returned object from function |
constraint |
specify the constrained value of
|
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
a |
The treatment effect on the mediator. |
b |
The within treatment correlation between the outcome and the mediator. |
power |
Statistical power. |
m |
Total budget. |
test |
The type of test will be used to detect mediation effects. Default is the joint significance test (i.e., test = "joint"). Another choice is the Sobel test by specifying the argument as test = "sobel". |
n |
The level-1 sample size per level-2 unit. |
p |
The proportion of level-1 units to be assigned to treatment. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2 |
The cost of sampling one level-2 unit (site). |
r12 |
The proportion of level-1 variance explained by covariates. |
r22m |
The proportion of variance of site-specific treatment effect explained by covariates. |
r12m |
The proportion of within treatment mediator variance at the level one explained by covariates. |
icc.m |
The intraclass correlation coefficient for the mediator. |
omega |
The standardized variance of site-specific treatment effect. |
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
J |
The number of sites. |
q |
The number of covariates at level 2. |
q.a |
The number of covariates at the individual level of the mediator model (except the treatment indicator). |
q.b |
The number of covariates in the outcome model (except the treatment indicator and the mediator). |
max.iter |
Maximal number of function evaluations when used as the stopping criterion. Default is 200. |
powerlim |
The range for solving the root of power ( |
Jlim |
The range for searching the root of level-2 sample size ( |
mlim |
the range for searching the root of budget ( |
rounded |
Logical; round the values of |
Value
Required budget (or required sample size), statistical power, or MDES depending on the specification of parameters. The function also returns the function name, design type, and parameters used in the calculation.
Statistical power, sample size (and/or budget), minimum detectable moderator effect size calculation for two-level multisite randomized trials (MRTs) detecting moderation effects
Description
This function can calculate power, required sample size/budget for desired power, or minimum detectable moderation effect size (MDMES) under a fixed budget in two-level MRTs. It also can perform conventional power analyses (e.g., required sample size, power, and MDMES calculation).
Usage
power.2m.mod(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
omega = NULL,
gamma = NULL,
power.mod = NULL,
m = NULL,
n = NULL,
J = NULL,
p = NULL,
icc = NULL,
r12 = NULL,
r22m = NULL,
q.mod = 1,
c1 = NULL,
c2 = NULL,
c1t = NULL,
gammalim = c(0, 5),
powerlim = c(1e-10, 1 - 1e-10),
Jlim = c(2.5, 1e+10),
mod.level = 1,
binary = TRUE,
mlim = NULL,
rounded = TRUE,
Q = 0.5
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for desired power, power/MDES under fixed budget) if TRUE, otherwise conventional power analyses (e.g., required sample size, power, or MDES calculation); default value is TRUE. |
expr |
Returned objects from function |
constraint |
Specify the constrained values of |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
omega |
The treatment-by-site variance of the outcome. |
gamma |
The standardized moderated treatment effect. |
power.mod |
Statistical power for the moderation effect. The default is .80. |
m |
Total budget, default is the total costs of sampling 60 sites. |
n |
The level-1 sample size per level-2 unit. |
J |
The number of sites. |
p |
The proportion of level-1 units within each level 2 unit to be assigned to treatment. |
icc |
The unconditional intraclass correlation coefficient (ICC) in population or in each treatment condition. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22m |
The proportion of variance of site-specific treatment effect explained by covariates. |
q.mod |
The number of predictors at the moderator level in the moderation model. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit (site). |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
gammalim |
The range for numerically solving the root of standardized moderation effect (gamma). Default is c(0, 5). |
powerlim |
The range for solving the root of power ( |
Jlim |
The range for solving the root of level-2 sample size
( |
mod.level |
The level of the moderator is at. The moderator is at level 1 if mod.level is 1, and at level 2 if mod.level is 2. The default is mod.level = 1. |
binary |
Logical; The moderator is binary if TRUE, and continuous if FALSE. The default is TRUE. |
mlim |
The range for numerically solving the root of budget ( |
rounded |
Logical; round the values of |
Q |
The proportion of units in one group for the binary moderator. Default is 0.5. |
power |
Statistical power.mod for a moderation effect. |
Value
Required budget (and/or required level-2 sample size), statistical power, or MDES depending on the specification of parameters. The function also returns the function name, design type, and parameters used in the calculation.
Examples
myod <- od.2m.mod(icc = .2, r12 = .5, r22m = .5,
c1 = 10, c1t = 100, c2 = 50,
omega = .01, gamma = 0.1)
mypower <- power.2m.mod(expr = myod, m=myod$out$m, gamma = 0.1); mypower$out
mym <- power.2m.mod(expr = myod, power.mod = .80, gamma = 0.1); mym$out
myod <- od.2m.only.mod(icc = .2, r12 = .5, r22m = .5,
c1 = 10, c1t = 100, c2 = 50, omega = .01)
mypower <- power.2m.mod(expr = myod, power.mod = .8, gamma = 0.1)
mypower$out
Budget and/or sample size, power, MDES calculation for three-level CRTs detecting main effects
Description
This function can calculate required budget for desired power, power or minimum detectable effect size (MDES) under fixed budget for three-level cluster randomized trials (CRTs). It also can perform conventional power analyses (e.g., required sample size, power, and MDES calculation).
Usage
power.3(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
d = NULL,
power = NULL,
m = NULL,
n = NULL,
J = NULL,
K = NULL,
p = NULL,
icc2 = NULL,
icc3 = NULL,
r12 = NULL,
r22 = NULL,
r32 = NULL,
q = NULL,
c1 = NULL,
c2 = NULL,
c3 = NULL,
c1t = NULL,
c2t = NULL,
c3t = NULL,
dlim = NULL,
powerlim = NULL,
Klim = NULL,
mlim = NULL,
rounded = TRUE
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for desired power, power/MDES under fixed budget) if TRUE, otherwise conventional power analyses (e.g., required sample size, power, or MDES calculation); default value is TRUE. |
expr |
Returned objects from function |
constraint |
Specify the constrained values of |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
d |
Effect size. |
power |
Statistical power. |
m |
Total budget. |
n |
The level-1 sample size per level-2 unit. |
J |
The level-2 sample size per level-3 unit. |
K |
The total level-3 sample size. |
p |
The proportion of level-3 clusters/units assigned to treatment. |
icc2 |
The unconditional intraclass correlation coefficient (ICC) at level 2. |
icc3 |
The unconditional intraclass correlation coefficient (ICC) at level 3. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
r32 |
The proportion of level-3 variance explained by covariates. |
q |
The number of covariates at level 3. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c3 |
The cost of sampling one level-3 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
c3t |
The cost of sampling one level-3 unit in treatment condition. |
dlim |
The range for solving the root of effect size ( |
powerlim |
The range for solving the root of power ( |
Klim |
The range for searching the root of level-3 sample size ( |
mlim |
The range for searching the root of budget ( |
rounded |
Logical; round the values of |
Value
Required budget (and/or required level-3 sample size), statistical power, or MDES depending on the specification of parameters. The function also returns the function name, design type, and parameters used in the calculation.
References
Shen, Z., & Kelcey, B. (2020). Optimal sample allocation under unequal costs in cluster-randomized trials. Journal of Educational and Behavioral Statistics, 45(4): 446–474. <https://doi.org/10.3102/1076998620912418>
Examples
# Unconstrained optimal design
myod1 <- od.3(icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c1t = 1, c2t = 50, c3t = 250)
myod1$out # output # n = 7.9, J = 3.2, p = 0.28
# ------- Power analyses by default considering costs and budget -------
# Required budget and sample size
mym.1 <- power.3(expr = myod1, d = 0.2, q = 1, power = 0.8)
mym.1$out # m = 16032, K = 97.3
#mym.1$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
mym.1 <- power.3(d = 0.2, power = 0.8, q = 1,
icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c1t = 1, c2t = 50, c3t = 250,
n = 8, J = 3, p = 0.28)
# Required budget and sample size with constrained p
mym.2 <- power.3(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5))
mym.2$out # m = 19239, K = 78.8
# Required budget and sample size with constrained p and J
mym.3 <- power.3(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5, J = 20))
mym.3$out # m = 39774, K = 46.9
# Power calculation
mypower <- power.3(expr = myod1, q = 1, d = 0.2, m = 16032)
mypower$out # power = 0.80
# Power calculation under constrained p (p = 0.5)
mypower.1 <- power.3(expr = myod1, q = 1, d = 0.2, m = 16032,
constraint = list(p = 0.5))
mypower.1$out # power = 0.72
# MDES calculation
mymdes <- power.3(expr = myod1, q = 1, power = 0.80, m = 16032)
mymdes$out # d = 0.20
# ------- Conventional power analyses with cost.model = FALSE-------
# Required sample size
myK <- power.3(cost.model = FALSE, expr = myod1, d = 0.2, q = 1, power = 0.8)
myK$out # K = 97.3
#myK$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
myK <- power.3(cost.model = FALSE, d = 0.2, power = 0.8, q = 1,
icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5,
n = 8, J = 3, p = 0.28)
# Power calculation
mypower1 <- power.3(cost.model = FALSE, expr = myod1, K = 97, d = 0.2, q = 1)
mypower1$out # power = 0.80
# MDES calculation
mymdes1 <- power.3(cost.model = FALSE, expr = myod1, K = 97, power = 0.8, q = 1)
mymdes1$out # d = 0.20
Budget and/or sample size, power, MDES calculation for three-level MRTs detecting main effects
Description
This function can calculate required budget for desired power, power or minimum detectable effect size (MDES) under fixed budget for three-level multisite randomized trials (MRTs). It also can perform conventional power analyses (e.g., required sample size, power, and MDES calculation).
Usage
power.3m(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
d = NULL,
power = NULL,
m = NULL,
n = NULL,
J = NULL,
K = NULL,
p = NULL,
icc2 = NULL,
icc3 = NULL,
r12 = NULL,
r22 = NULL,
r32m = NULL,
q = NULL,
c1 = NULL,
c2 = NULL,
c3 = NULL,
c1t = NULL,
c2t = NULL,
omega = NULL,
dlim = NULL,
powerlim = NULL,
Klim = NULL,
mlim = NULL,
rounded = TRUE
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for desired power, power/MDES under fixed budget) if TRUE, otherwise conventional power analyses (e.g., required sample size, power, or MDES calculation); default value is TRUE. |
expr |
Returned objects from function |
constraint |
Specify the constrained values of |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
d |
Effect size. |
power |
Statistical power. |
m |
Total budget. |
n |
The level-1 sample size per level-2 unit. |
J |
The level-2 sample size per level-3 unit. |
K |
The level-3 sample size per level-4 unit. |
p |
The proportion of level-2 units to be assigned to treatment. |
icc2 |
The unconditional intraclass correlation coefficient (ICC) at level 2. |
icc3 |
The unconditional intraclass correlation coefficient (ICC) at level 3. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
r32m |
The proportion of variance of site-specific treatment effect explained by covariates. |
q |
The number of covariates at level 3. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c3 |
The cost of sampling one level-3 unit (site). |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
omega |
The standardized variance of site-specific treatment effect. |
dlim |
The range for solving the root of effect size ( |
powerlim |
The range for solving the root of power ( |
Klim |
The range for searching the root of level-3 sample size ( |
mlim |
The range for searching the root of budget ( |
rounded |
Logical; round the values of |
Value
Required budget (and/or required level-3 sample size), statistical power, or MDES depending on the specification of parameters. The function also returns the function name, design type, and parameters used in the calculation.
References
Shen, Z., & Kelcey, B. (2022). Optimal sampling ratios in three-level multisite experiments. Journal of Research on Educational Effectiveness, 15(1), 130-150. <https://doi.org/10.1080/19345747.2021.1953200>
Examples
# Unconstrained optimal design #---------
myod1 <- od.3m(icc2 = 0.2, icc3 = 0.1, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32m = 0.5,
c1 = 1, c2 = 5,
c1t = 1, c2t = 200, c3 = 200,
varlim = c(0, 0.005))
myod1$out # n = 13.1, J = 15.3, p = 0.23
# ------- Power analyses by default considering costs and budget -------
# Required budget and sample size
mym.1 <- power.3m(expr = myod1, d = 0.2, q = 1, power = 0.8)
mym.1$out # m = 15491, K = 13.6
# mym.1$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
mym.1 <- power.3m(d = 0.2, power = 0.8, q = 1,
icc2 = 0.2, icc3 = 0.1, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32m = 0.5,
c1 = 1, c2 = 5,
c1t = 1, c2t = 200, c3 = 200,
n = 13, J = 15, p = 0.23)
# Required budget and sample size with constrained p
mym.2 <- power.3m(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5))
mym.2$out # m = 21072, K = 10.9
# Required budget and sample size with constrained p and n
mym.3 <- power.3m(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5, n = 20))
mym.3$out # m = 21252, K = 10.4
# Power calculation
mypower <- power.3m(expr = myod1, q = 1, d = 0.2, m = 15491)
mypower$out # power = 0.80
# Power calculation under constrained p (p = 0.5)
mypower.1 <- power.3m(expr = myod1, q = 1, d = 0.2, m = 15491,
constraint = list(p = 0.5))
mypower.1$out # power = 0.62
# MDES calculation
mymdes <- power.3m(expr = myod1, q = 1, power = 0.80, m = 15491)
mymdes$out # d = 0.20
# ------- Conventional power analyses with cost.model = FALSE-------
# Required sample size
myK <- power.3m(cost.model = FALSE, expr = myod1, d = 0.2, q = 1, power = 0.8)
myK$out # K = 13.6
# myK$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
myK <- power.3m(cost.model = FALSE, d = 0.2, power = 0.8, q = 1,
icc2 = 0.2, icc3 = 0.1, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32m = 0.5,
c1 = 1, c2 = 5,
c1t = 1, c2t = 200, c3 = 200,
n = 13, J = 15, p = 0.23)
# Power calculation
mypower1 <- power.3m(cost.model = FALSE, expr = myod1, K = 13.6, d = 0.2, q = 1)
mypower1$out # power = 0.80
# MDES calculation
mymdes1 <- power.3m(cost.model = FALSE, expr = myod1, K = 13.6, power = 0.8, q = 1)
mymdes1$out # d = 0.20
Budget and/or sample size, power, MDES calculation for four-level CRTs detecting main effects
Description
This function can calculate required budget for desired power, power or minimum detectable effect size (MDES) under fixed budget for four-level cluster randomized trials (CRTs). It also can perform conventional power analyses (e.g., required sample size, power, and MDES calculation).
Usage
power.4(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
d = NULL,
power = NULL,
m = NULL,
n = NULL,
J = NULL,
K = NULL,
L = NULL,
p = NULL,
icc2 = NULL,
icc3 = NULL,
icc4 = NULL,
r12 = NULL,
r22 = NULL,
r32 = NULL,
r42 = NULL,
q = NULL,
c1 = NULL,
c2 = NULL,
c3 = NULL,
c4 = NULL,
c1t = NULL,
c2t = NULL,
c3t = NULL,
c4t = NULL,
dlim = NULL,
powerlim = NULL,
Llim = NULL,
mlim = NULL,
rounded = TRUE
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for desired power, power/MDES under fixed budget) if TRUE, otherwise conventional power analyses (e.g., required sample size, power, or MDES calculation); default value is TRUE. |
expr |
Returned objects from function |
constraint |
Specify the constrained values of |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
d |
Effect size. |
power |
Statistical power. |
m |
Total budget. |
n |
The level-1 sample size per level-2 unit. |
J |
The level-2 sample size per level-3 unit. |
K |
The level-3 sample size per level-4 unit. |
L |
The total level-4 sample size. |
p |
The proportion of level-4 clusters/units to be assigned to treatment. |
icc2 |
The unconditional intraclass correlation coefficient (ICC) at level 2. |
icc3 |
The unconditional intraclass correlation coefficient (ICC) at level 3. |
icc4 |
The unconditional intraclass correlation coefficient (ICC) at level 4. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
r32 |
The proportion of level-3 variance explained by covariates. |
r42 |
The proportion of level-4 variance explained by covariates. |
q |
The number of covariates at level 4. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c3 |
The cost of sampling one level-3 unit in control condition. |
c4 |
The cost of sampling one level-4 unit in control condition. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
c3t |
The cost of sampling one level-3 unit in treatment condition. |
c4t |
The cost of sampling one level-4 unit in treatment condition. |
dlim |
The range for solving the root of effect size ( |
powerlim |
The range for solving the root of power ( |
Llim |
The range for solving the root of level-4 sample size ( |
mlim |
The range for searching the root of budget ( |
rounded |
Logical; round the values of |
Value
Required budget (and/or required level-4 sample size), statistical power, or MDES depending on the specification of parameters. The function also returns the function name, design type, and parameters used in the calculation.
Examples
# Unconstrained optimal design
myod1 <- od.4(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c4 = 125,
c1t = 1, c2t = 50, c3t = 250, c4t = 2500)
myod1$out # output # n = 7.1, J = 3.2, K = 4.2, p = 0.23
# ------- Power analyses by default considering costs and budget -------
# Required budget and sample size
mym.1 <- power.4(expr = myod1, d = 0.2, q = 1, power = 0.8)
mym.1$out # m = 71161, L = 57.1
#mym.1$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
mym.1 <- power.4(d = 0.2, power = 0.8, q = 1,
icc2 = 0.2, icc3 = 0.1, icc4 = 0.05,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c4 = 125,
c1t = 1, c2t = 50, c3t = 250, c4t = 2500,
n = 7, J = 3, K = 4, p = 0.23)
# Required budget and sample size with constrained p (p = 0.5)
mym.2 <- power.4(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5))
mym.2$out # m = 93508, L = 41.1
# Required budget and sample size with constrained p and K
mym.3 <- power.4(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5, K = 20))
mym.3$out # m = 157365, L = 25.7
# Power calculation
mypower <- power.4(expr = myod1, q = 1, d = 0.2, m = 71161)
mypower$out # power = 0.80
# Power calculation under constrained p (p = 0.5)
mypower.1 <- power.4(expr = myod1, q = 1, d = 0.2, m = 71161,
constraint = list(p = 0.5))
mypower.1$out # power = 0.68
# MDES calculation
mymdes <- power.4(expr = myod1, q = 1, power = 0.80, m = 71161)
mymdes$out # d = 0.20
# ------- Conventional power analyses with cost.model = FALSE-------
# Required sample size
myL <- power.4(cost.model = FALSE, expr = myod1, d = 0.2, q = 1, power = 0.8)
myL$out # L = 57.1
#myL$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
myL <- power.4(cost.model = FALSE, d = 0.2, power = 0.8, q = 1,
icc2 = 0.2, icc3 = 0.1, icc4 = 0.05,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42 = 0.5,
n = 7, J = 3, K = 4, p = 0.23)
# Power calculation
mypower1 <- power.4(cost.model = FALSE, expr = myod1, L = 57, d = 0.2, q = 1)
mypower1$out # power = 0.80
# MDES calculation
mymdes1 <- power.4(cost.model = FALSE, expr = myod1, L = 57, power = 0.8, q = 1)
mymdes1$out # d = 0.20
Budget and/or sample size, power, MDES calculation for four-level MRTs detecting main effects
Description
This function can calculate required budget for desired power, power or minimum detectable effect size (MDES) under fixed budget for four-level multisite randomized trials (MRTs). It also can perform conventional power analyses (e.g., required sample size, power, and MDES calculation).
Usage
power.4m(
cost.model = TRUE,
expr = NULL,
constraint = NULL,
sig.level = 0.05,
two.tailed = TRUE,
d = NULL,
power = NULL,
m = NULL,
n = NULL,
J = NULL,
K = NULL,
L = NULL,
p = NULL,
icc2 = NULL,
icc3 = NULL,
icc4 = NULL,
r12 = NULL,
r22 = NULL,
r32 = NULL,
r42m = NULL,
q = NULL,
c1 = NULL,
c2 = NULL,
c3 = NULL,
c4 = NULL,
c1t = NULL,
c2t = NULL,
c3t = NULL,
omega = NULL,
dlim = NULL,
powerlim = NULL,
Llim = NULL,
mlim = NULL,
rounded = TRUE
)
Arguments
cost.model |
Logical; power analyses accommodating costs and budget (e.g., required budget for desired power, power/MDES under fixed budget) if TRUE, otherwise conventional power analyses (e.g., required sample size, power, or MDES calculation); default value is TRUE. |
expr |
Returned objects from function |
constraint |
The constrained values of |
sig.level |
Significance level or type I error rate, default value is 0.05. |
two.tailed |
Logical; two-tailed tests if TRUE, otherwise one-tailed tests; default value is TRUE. |
d |
Effect size. |
power |
Statistical power. |
m |
Total budget. |
n |
The level-1 sample size per level-2 unit. |
J |
The level-2 sample size per level-3 unit. |
K |
The level-3 sample size per level-4 unit. |
L |
The total level-4 sample size. |
p |
The proportion of level-3 units to be assigned to treatment. |
icc2 |
The unconditional intraclass correlation coefficient (ICC) at level 2. |
icc3 |
The unconditional intraclass correlation coefficient (ICC) at level 3. |
icc4 |
The unconditional intraclass correlation coefficient (ICC) at level 4. |
r12 |
The proportion of level-1 variance explained by covariates. |
r22 |
The proportion of level-2 variance explained by covariates. |
r32 |
The proportion of level-3 variance explained by covariates. |
r42m |
The proportion of variance of site-specific treatment effect explained by covariates. |
q |
The number of covariates at level 4. |
c1 |
The cost of sampling one level-1 unit in control condition. |
c2 |
The cost of sampling one level-2 unit in control condition. |
c3 |
The cost of sampling one level-3 unit in control condition. |
c4 |
The cost of sampling one level-4 unit (cite. |
c1t |
The cost of sampling one level-1 unit in treatment condition. |
c2t |
The cost of sampling one level-2 unit in treatment condition. |
c3t |
The cost of sampling one level-3 unit in treatment condition. |
omega |
The standardized variance of site-specific treatment effect. |
dlim |
The range for solving the root of effect size ( |
powerlim |
The range for solving the root of power ( |
Llim |
The range for solving the root of level-4 sample size ( |
mlim |
The range for searching the root of budget ( |
rounded |
Logical; round the values of |
Value
Required budget (and/or required level-4 sample size), statistical power, or MDES depending on the specification of parameters. The function also returns the function name, design type, and parameters used in the calculation.
Examples
# Unconstrained optimal design #---------
myod1 <- od.4m(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42m = 0.5,
c1 = 1, c2 = 5, c3 = 25,
c1t = 1, c2t = 50, c3t = 250, c4 = 500,
varlim = c(0, 0.005))
myod1$out # n = 8.3, J = 3.2, K = 4.9, p = 0.36
# ------- Power analyses by default considering costs and budget -------
# Required budget and sample size
mym.1 <- power.4m(expr = myod1, d = 0.2, q = 1, power = 0.8)
mym.1$out # m = 30201, L = 20.6
# mym.1$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
mym.1 <- power.4m(d = 0.2, power = 0.8, q = 1,
icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42m = 0.5,
c1 = 1, c2 = 5, c3 = 25,
c1t = 1, c2t = 50, c3t = 250, c4 = 500,
n = 8, J = 3, K = 5, p = 0.36)
# Required budget and sample size with constrained p
mym.2 <- power.4m(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5))
mym.2$out # m = 33183, L = 19.3
# Required budget and sample size with constrained p and n
mym.3 <- power.4m(expr = myod1, d = 0.2, q = 1, power = 0.8,
constraint = list(p = 0.5, n = 20))
mym.3$out # m = 34262, L = 18.0
# Power calculation
mypower <- power.4m(expr = myod1, q = 1, d = 0.2, m = 30201)
mypower$out # power = 0.80
# Power calculation under constrained p (p = 0.5)
mypower.1 <- power.4m(expr = myod1, q = 1, d = 0.2, m = 30201,
constraint = list(p = 0.5))
mypower.1$out # power = 0.76
# MDES calculation
mymdes <- power.4m(expr = myod1, q = 1, power = 0.80, m = 30201)
mymdes$out # d = 0.20
# ------- Conventional power analyses with cost.model = FALSE-------
# Required sample size
myL <- power.4m(cost.model = FALSE, expr = myod1, d = 0.2, q = 1, power = 0.8)
myL$out # L = 20.6
# myL$par # parameters and their values used for the function
# Or, equivalently, specify every argument in the function
myL <- power.4m(cost.model = FALSE, d = 0.2, power = 0.8, q = 1,
icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, omega = 0.02,
r12 = 0.5, r22 = 0.5, r32 = 0.5, r42m = 0.5,
c1 = 1, c2 = 5, c3 = 25,
c1t = 1, c2t = 50, c3t = 250, c4 = 500,
n = 8, J = 3, K = 5, p = 0.36)
# Power calculation
mypower1 <- power.4m(cost.model = FALSE, expr = myod1, L = 20.6, d = 0.2, q = 1)
mypower1$out # power = 0.80
# MDES calculation
mymdes1 <- power.4m(cost.model = FALSE, expr = myod1, L = 20.6, power = 0.8, q = 1)
mymdes1$out # d = 0.20
Relative efficiency (RE) calculation
Description
Calculate the relative efficiency (RE) between two designs, it returns
same results as those from function rpe
.
Usage
re(od, subod, rounded = TRUE, verbose = TRUE)
Arguments
od |
Returned object of first design (e.g., unconstrained optimal design)
from function |
subod |
Returned object of second design (e.g., constrained optimal design)
from function |
rounded |
Logical; round the values of |
verbose |
Logical; print the value of relative efficiency if TRUE, otherwise not; default is TRUE. |
Value
Relative efficiency value.
References
(1) Shen, Z., & Kelcey, B. (2020). Optimal sample allocation under unequal costs in cluster-randomized trials. Journal of Educational and Behavioral Statistics, 45(4): 446–474. <https://doi.org/10.3102/1076998620912418> (2) Shen, Z., & Kelcey, B. (in press). Optimal sample allocation in multisite randomized trials. The Journal of Experimental Education. <https://doi.org/10.1080/00220973.2020.1830361> (3) Shen, Z., & Kelcey, B. (in press). Optimal sampling ratios in three-level multisite experiments. Journal of Research on Educational Effectiveness.
Examples
# Unconstrained optimal design of 2-level CRT #----------
myod1 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50,
varlim = c(0.01, 0.02))
# Constrained optimal design with n = 20
myod2 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50,
n = 20, varlim = c(0.005, 0.025))
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod2)
myre$re # RE = 0.88
# Constrained optimal design with p = 0.5
myod2 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50,
p = 0.5, varlim = c(0.005, 0.025))
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod2)
myre$re # RE = 0.90
# Unconstrained optimal design of 3-level CRT #----------
myod1 <- od.3(icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c1t = 1, c2t = 50, c3t = 250,
varlim = c(0.005, 0.025))
# Constrained optimal design with J = 20
myod2 <- od.3(icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5, J = 20,
c1 = 1, c2 = 5, c3 = 25, c1t = 1, c2t = 50, c3t = 250,
varlim = c(0, 0.025))
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod2)
myre$re # RE = 0.53
# Unconstrained optimal design of 4-level CRT #---------
myod1 <- od.4(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, r12 = 0.5,
r22 = 0.5, r32 = 0.5, r42 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c4 = 125,
c1t = 1, c2t = 50, c3t = 250, c4t = 2500,
varlim = c(0, 0.01))
# Constrained optimal design with p = 0.5
myod2 <- od.4(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, r12 = 0.5, p = 0.5,
r22 = 0.5, r32 = 0.5, r42 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c4 = 125,
c1t = 1, c2t = 50, c3t = 250, c4t = 2500,
varlim = c(0, 0.01))
# Relative efficiency (RE)
myre <- re(od = myod1, subod= myod2)
myre$re # RE = 0.78
Relative precision and efficiency (RPE) calculation
Description
Calculate the relative precision and efficiency (RPE) between two designs,
it returns same results as those from function re
.
Usage
rpe(od, subod, rounded = TRUE, verbose = TRUE)
Arguments
od |
Returned object of first design (e.g., unconstrained optimal design)
from function |
subod |
Returned object of second design (e.g., constrained optimal design)
from function |
rounded |
Logical; round the values of |
verbose |
Logical; print the value of relative precision and efficiency if TRUE, otherwise not; default is TRUE. |
Value
Relative precision and efficiency value.
References
(1) Shen, Z., & Kelcey, B. (2020). Optimal sample allocation under unequal costs in cluster-randomized trials. Journal of Educational and Behavioral Statistics, 45(4): 446–474. <https://doi.org/10.3102/1076998620912418> (2) Shen, Z., & Kelcey, B. (in press). Optimal sample allocation in multisite randomized trials. The Journal of Experimental Education. <https://doi.org/10.1080/00220973.2020.1830361> (3) Shen, Z., & Kelcey, B. (in press). Optimal sampling ratios in three-level multisite experiments. Journal of Research on Educational Effectiveness.
Examples
# Unconstrained optimal design of 2-level CRT #----------
myod1 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50,
varlim = c(0.01, 0.02))
# Constrained optimal design with n = 20
myod2 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50,
n = 20, varlim = c(0.005, 0.025))
# Relative precision and efficiency (RPE)
myrpe <- rpe(od = myod1, subod= myod2)
myrpe$rpe # RPE = 0.88
# Constrained optimal design with p = 0.5
myod2 <- od.2(icc = 0.2, r12 = 0.5, r22 = 0.5, c1 = 1, c2 = 5, c1t = 1, c2t = 50,
p = 0.5, varlim = c(0.005, 0.025))
# Relative precision and efficiency (RPE)
myrpe <- rpe(od = myod1, subod= myod2)
myrpe$rpe # RPE = 0.90
# Unconstrained optimal design of 3-level CRT #----------
myod1 <- od.3(icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c1t = 1, c2t = 50, c3t = 250,
varlim = c(0.005, 0.025))
# Constrained optimal design with J = 20
myod2 <- od.3(icc2 = 0.2, icc3 = 0.1, r12 = 0.5, r22 = 0.5, r32 = 0.5, J = 20,
c1 = 1, c2 = 5, c3 = 25, c1t = 1, c2t = 50, c3t = 250,
varlim = c(0, 0.025))
# Relative precision and efficiency (RPE)
myrpe <- rpe(od = myod1, subod= myod2)
myrpe$rpe # RPE = 0.53
# Unconstrained optimal design of 4-level CRT #---------
myod1 <- od.4(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, r12 = 0.5,
r22 = 0.5, r32 = 0.5, r42 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c4 = 125,
c1t = 1, c2t = 50, c3t = 250, c4t = 2500,
varlim = c(0, 0.01))
# Constrained optimal design with p = 0.5
myod2 <- od.4(icc2 = 0.2, icc3 = 0.1, icc4 = 0.05, r12 = 0.5, p = 0.5,
r22 = 0.5, r32 = 0.5, r42 = 0.5,
c1 = 1, c2 = 5, c3 = 25, c4 = 125,
c1t = 1, c2t = 50, c3t = 250, c4t = 2500,
varlim = c(0, 0.01))
# Relative precision and efficiency (RPE)
myrpe <- rpe(od = myod1, subod= myod2)
myrpe$rpe # RPE = 0.78