Type: | Package |
Title: | Power and Sample Size Tools |
Version: | 0.1.3 |
Maintainer: | Catherine M. Crespi <ccrespi@ucla.edu> |
Description: | Power and sample size calculations for a variety of study designs and outcomes. Methods include t tests, ANOVA (including tests for interactions, simple effects and contrasts), proportions, categorical data (chi-square tests and proportional odds), linear, logistic and Poisson regression, alternative and coprimary endpoints, power for confidence intervals, correlation coefficient tests, cluster randomized trials, individually randomized group treatment trials, multisite trials, treatment-by-covariate interaction effects and nonparametric tests of location. Utilities are provided for computing various effect sizes. Companion package to the book "Power and Sample Size in R", Crespi (2025, ISBN:9781138591622). Further resources available at https://powerandsamplesize.org/. |
URL: | https://github.com/powerandsamplesize/powertools |
BugReports: | https://github.com/powerandsamplesize/powertools/issues |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
Suggests: | testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
Imports: | mvtnorm, PowerTOST, Hmisc, stats, knitr |
Depends: | R (≥ 2.10) |
NeedsCompilation: | no |
Packaged: | 2025-06-10 13:10:46 UTC; ccrespi |
Author: | Catherine M. Crespi [aut, cre], Zichen Liu [aut], Kristen M. McGreevy [ctb] |
Repository: | CRAN |
Date/Publication: | 2025-06-10 13:40:02 UTC |
Power calculation for multiple alternative (at least one) primary continuous endpoints assuming known covariance matrix
Description
Calculates power and sample size for the case of comparing two groups on the means of K continuous endpoints and concluding that the trial is a 'success' if the null hypothesis is rejected for at least one of the K endpoints. All mean differences must be specified as positive; the scale for some outcomes may need to be reversed to meet this condition. All tests are assumed to be upper-tailed, one-sided tests. Can solve for power, n1, n.ratio or alpha.
To use a Bonferroni correction for multiple comparisons, specify alpha as the desired familywise error rate (FWER) divided by K. For example, for one-sided FWER of 0.025 and K = 2 endpoints, specify alpha as 0.0125.
Either sd and rho or Sigma must be specified.
A known covariance matrix is assumed, which can result in a slight overestimate of power and underestimate of required sample size.
Usage
altprimary(
K,
n1 = NULL,
n.ratio = 1,
delta = NULL,
Sigma,
sd,
rho,
alpha = 0.025,
power = NULL,
v = FALSE
)
Arguments
K |
The number of endpoints. |
n1 |
The sample size for group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
delta |
A vector of length K of the true mean differences mu1k - mu2k; must all be positive. |
Sigma |
The covariance matrix of the K outcomes, of dimension K x K. |
sd |
A vector of length K of the standard deviations of the K outcomes. |
rho |
A vector of length 0.5K(K-1) of the correlations among the K outcomes. |
alpha |
The significance level (type 1 error rate) for each test; defaults to 0.025. A one-sided test is assumed. |
power |
The specified level of power. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
Sozu T, Sugimoto T, Hamasaki T, Evans SR (2015) Sample Size Determination in Clinical Trials with Multiple Endpoints. Springer International Publishing, Switzerland.
Value
A list of the arguments (including the computed one).
Examples
altprimary(K = 2, n1 = 100, delta = c(0.4, 0.5), sd = c(1, 1), rho = 0.3,
alpha = 0.025 / 2, power = NULL)
Sigma <- matrix(c(1, 0.3, 0.3, 0.3, 1, 0.3, 0.3, 0.3, 1), nrow = 3, ncol = 3)
altprimary(K = 3, n1 = 100, delta = c(0.2, 0.2, 0.4), Sigma = Sigma,
alpha = 0.025 / 3, power = NULL)
Power calculation for balanced one-way ANOVA omnibus F test
Description
This function performs power and sample size calculations for the overall (omnibus) F test in a balanced (equal-sized groups) one-way analysis of variance (ANOVA). Can be used to solve for power, n (sample size per group), or alpha. For an unbalanced one-way ANOVA F test (that is, unequal group sample sizes), use 'anova1way.F.unbal'. For contrast tests in a one-way ANOVA, see 'anova1way.c.bal' and 'anova1way.c.unbal'.
Usage
anova1way.F.bal(
n = NULL,
mvec = NULL,
sd = 1,
Rsq = 0,
ncov = 0,
alpha = 0.05,
power = NULL,
v = FALSE
)
Arguments
n |
The sample size per group. |
mvec |
A vector of group means c(mu1, mu2, ...). |
sd |
The estimated standard deviation within each group; defaults to 1. |
Rsq |
The estimated R^2 for regressing the outcome on the covariates; defaults to 0. |
ncov |
The number of covariates adjusted for in the model; defaults to 0. |
alpha |
The significance level or type 1 error rate; defaults to 0.05. |
power |
The specified level of power. |
v |
Either TRUE for verbose output or FALSE to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
anova1way.F.bal(n = 20, mvec = c(5, 10, 12), sd = 10)
anova1way.F.bal(n = NULL, mvec = c(-0.25, 0.25), sd = 1, Rsq = 0.5^2, ncov = 1, power = 0.8)
Power calculation for unbalanced one-way analysis of variance omnibus F test
Description
Performs power calculation for an unbalanced (unequal group sizes) one-way ANOVA omnibus F test, which tests for any differences among group means. This function solves for power given other parameters. For balanced data (equal-sized groups), anova1way.F.bal can be used and solves for more parameters.
Usage
anova1way.F.unbal(
nvec = NULL,
mvec = NULL,
sd = NULL,
Rsq = 0,
ncov = 0,
alpha = 0.05,
v = FALSE
)
Arguments
nvec |
A vector of group sample sizes c(n1, n2, ...). |
mvec |
A vector of group mvec c(mu1, mu2, ...). |
sd |
The estimated standard deviation within each group. |
Rsq |
The estimated R^2 for regressing the outcome on the covariates; defaults to 0. |
ncov |
The number of covariates adjusted for in the model; defaults to 0. |
alpha |
The significance level or type 1 error rate; defaults to 0.05. |
v |
Either TRUE for verbose output or FALSE to output computed argument only. |
Value
A list of the arguments (including the computed power).
Examples
anova1way.F.unbal(nvec = c(10, 20, 30), mvec = c(5, 10, 12), sd = 10)
Power calculation for one-way balanced analysis of variance contrast test
Description
Performs sample size and power calculations for a test of a contrast in a one-way ANOVA with balanced data (that is, equal sized groups). Can be used to solve for power, n (sample size per group), or alpha. For unbalanced data, see anova1way.c.unbal.
Usage
anova1way.c.bal(
n = NULL,
mvec = NULL,
cvec = NULL,
sd = 1,
Rsq = 0,
ncov = 0,
alpha = 0.05,
power = NULL,
v = FALSE
)
Arguments
n |
The sample size per group. |
mvec |
A vector of group means c(mu1, mu2, ...). |
cvec |
A vector of contrast coefficients c(c1, c2, ...). |
sd |
The estimated standard deviation within each group; defaults to 1. |
Rsq |
The estimated R^2 for regressing the outcome on the covariates; defaults to 0. |
ncov |
The number of covariates adjusted for in the model; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
anova1way.c.bal(n = 20, mvec = c(5, 10, 12), cvec = c(1, -1, 0), sd = 10, alpha = 0.025)
anova1way.c.bal(n = 20, mvec = c(5, 10, 12), cvec = c(1, 0, -1), sd = 10, alpha = 0.025)
Power calculation for one-way unbalanced analysis of variance contrast test
Description
Calculates power for a test of a contrast in a one-way ANOVA with unbalanced data (that is, unequal sized groups). This function only solves for power. For a one-way balanced ANOVA, (equal group sizes), anova1way.c.bal can also be used, and will solve for quantities other than power.
Usage
anova1way.c.unbal(
nvec = NULL,
mvec = NULL,
cvec = NULL,
sd = NULL,
Rsq = 0,
ncov = 0,
alpha = 0.05,
v = FALSE
)
Arguments
nvec |
A vector of group sample sizes c(n1, n2, ...). |
mvec |
A vector of group mvec c(mu1, mu2, ...). |
cvec |
A vector of contrast coefficients c(c1, c2, ...). |
sd |
The estimated standard deviation within each group. |
Rsq |
The estimated R^2 for regressing the outcome on the covariates; defaults to 0. |
ncov |
The number of covariates adjusted for in the model; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed power).
Examples
anova1way.c.unbal(nvec = c(20, 20, 20), mvec = c(5, 10, 12), cvec = c(1, -1, 0),
sd = 10, alpha = 0.025)
anova1way.c.unbal(nvec = c(20, 20, 20), mvec = c(5, 10, 12), cvec = c(1, 0, -1),
sd = 10, alpha = 0.025)
Power calculation for two-way balanced analysis of variance F tests
Description
Performs sample size and power calculations for F tests in a two-way ANOVA with balanced data (that is, equal cell sizes). For a given matrix of cell means, computes power or required cell size for each factor and for their interaction, if an interaction is present. For unbalanced data (unequal cell sizes), see anova2way.F.unbal.
Usage
anova2way.F.bal(
n = NULL,
mmatrix = NULL,
sd = 1,
Rsq = 0,
ncov = 0,
alpha = 0.05,
power = NULL,
v = FALSE
)
Arguments
n |
The sample size per cell |
mmatrix |
A matrix of cell means (see example). |
sd |
The estimated standard deviation within each cell; defaults to 1. |
Rsq |
The estimated R^2 for regressing the outcome on the covariates; defaults to 0. |
ncov |
The number of covariates adjusted for in the model; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
mmatrix <- matrix(c(9.3, 8.9, 8.5, 8.7, 8.3, 7.9), nrow = 2, byrow = TRUE)
anova2way.F.bal(n = 30, mmatrix = mmatrix, sd = 2, alpha = 0.05)
mmatrix <- matrix(c(9.3, 8.9, 8.5, 8.7, 8.3, 7.3), nrow = 2, byrow = TRUE)
anova2way.F.bal(n = 30, mmatrix = mmatrix, sd = 2, alpha = 0.05)
mmatrix <- matrix(c(9.3, 8.9, 8.5, 8.7, 8.3, 7.9), nrow = 2, byrow = TRUE)
anova2way.F.bal(n = 30, mmatrix = mmatrix, sd = 2, Rsq = 0.4, ncov = 1, alpha = 0.05)
Power calculation for two-way unbalanced analysis of variance F tests
Description
Performs sample size and power calculations for F tests in a two-way ANOVA with unbalanced data (that is, unequal sized cells). For given matrix of cell means and matrix of cell sample sizes, computes power for each factor and for their interaction, if an interaction is present. This function does not solve for cell sizes. For balanced data (equal cell sizes), see anova2way.F.unbal, which can solve for cell size.
Usage
anova2way.F.unbal(
nmatrix = NULL,
mmatrix = NULL,
sd = NULL,
Rsq = 0,
ncov = 0,
alpha = 0.05,
v = FALSE
)
Arguments
nmatrix |
A matrix of cell sample sizes (see example). |
mmatrix |
A matrix of cell means (see example). |
sd |
The estimated standard deviation within each cell |
Rsq |
The estimated R^2 for regressing the outcome on the covariates; defaults to 0. |
ncov |
The number of covariates adjusted for in the model; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed power).
Examples
nmatrix <- matrix(c(30, 30, 30, 30, 30, 30), nrow = 2, byrow = TRUE)
mmatrix <- matrix(c(9.3, 8.9, 8.5, 8.7, 8.3, 7.9), nrow = 2, byrow = TRUE)
anova2way.F.unbal(nmatrix = nmatrix, mmatrix = mmatrix, sd = 2, alpha = 0.05)
nmatrix <- matrix(c(30, 30, 30, 30, 30, 30), nrow = 2, byrow = TRUE)
mmatrix <- matrix(c(9.3, 8.9, 8.5, 8.7, 8.3, 7.3), nrow = 2, byrow = TRUE)
anova2way.F.unbal(nmatrix = nmatrix, mmatrix = mmatrix, sd = 2, alpha = 0.05)
nmatrix <- matrix(c(30, 30, 30, 30, 30, 30), nrow = 2, byrow = TRUE)
mmatrix <- matrix(c(9.3, 8.9, 8.5, 8.7, 8.3, 7.9), nrow = 2, byrow = TRUE)
anova2way.F.unbal(nmatrix = nmatrix, mmatrix = mmatrix, sd = 2, Rsq = 0.4^2,
ncov = 1, alpha = 0.05)
Power calculation for two-way balanced analysis of variance contrast test
Description
Performs sample size and power calculations for a test of a contrast between levels of a factor in a two-way ANOVA with balanced data (that is, equal sized cells). Can be used to solve for power, n (sample size per cell), or alpha. For unbalanced data, see anova2way.c.unbal. For a test of a contrast among cell means, see anova2way.se.bal.
Usage
anova2way.c.bal(
n = NULL,
mmatrix = NULL,
cvec = NULL,
factor = c("a", "b"),
sd = 1,
Rsq = 0,
ncov = 0,
alpha = 0.05,
power = NULL,
v = FALSE
)
Arguments
n |
The sample size per cell |
mmatrix |
A matrix of cell means (see example). |
cvec |
A vector of contrast coefficients c(c1, c2, ...). |
factor |
Either "a" for rows or "b" for columns depending on which factor the contrast test is being made on. |
sd |
The estimated standard deviation within each cell; defaults to 1. |
Rsq |
The estimated R^2 for regressing the outcome on the covariates; defaults to 0. |
ncov |
The number of covariates adjusted for in the model; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
mmatrix <- matrix(c(9.3, 8.9, 8.5, 8.7, 8.3, 7.3), nrow = 2, byrow = TRUE)
anova2way.c.bal(n = 30, mmatrix = mmatrix, cvec = c(1, 0, -1), factor = "b",
sd = 2, alpha = 0.05)
Power calculation for two-way unbalanced analysis of variance contrast test
Description
Calculates power for a test of a contrast between levels of a factor in a two-way ANOVA with unbalanced data (that is, unequal cell sizes). This function only solves for power. For a two-way balanced ANOVA, (equal cell sizes), anova2way.c.bal can also be used, and will solve for quantities other than power. For a test of a contrast among cell means, see anova2way.se.unbal.
Usage
anova2way.c.unbal(
nmatrix = nmatrix,
mmatrix = NULL,
cvec = NULL,
factor = c("a", "b"),
sd = NULL,
Rsq = 0,
ncov = 0,
alpha = 0.05,
v = FALSE
)
Arguments
nmatrix |
A matrix of cell sample sizes (see example). |
mmatrix |
A matrix of cell means (see example). |
cvec |
A vector of contrast coefficients c(c1, c2, ...). |
factor |
Either "a" (rows) or "b" (columns) depending on which factor the contrast test is being made on. |
sd |
The estimated standard deviation within each cell. |
Rsq |
The estimated R^2 for regressing the outcome on the covariates; defaults to 0. |
ncov |
The number of covariates adjusted for in the model; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
nmatrix <- matrix(c(30, 30, 30, 30, 30, 30), nrow = 2, byrow = TRUE)
mmatrix <- matrix(c(9.3, 8.9, 8.5, 8.7, 8.3, 7.3), nrow = 2, byrow = TRUE)
anova2way.c.unbal(nmatrix = nmatrix, mmatrix = mmatrix, cvec = c(1, 0, -1),
factor = "b", sd = 2, alpha = 0.05)
Power calculation for test of simple effect for two-way balanced analysis of variance
Description
Conducts power and sample size calculations for a test of a simple effect in a two-way balanced (equal cell sizes) ANOVA. A "simple effect" is a contrast among the cell means. For a test of a contrast in an unbalanced (unequal cell sizes) two-way ANOVA, see anova2way.se.unbal. For a test of contrast among factor levels, see anova2way.c.bal.
Usage
anova2way.se.bal(
n = NULL,
mmatrix = NULL,
cmatrix = NULL,
sd = 1,
Rsq = 0,
ncov = 0,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
n |
The sample size per cell. |
mmatrix |
A matrix of cell means (see example). |
cmatrix |
A matrix of contrast coefficients (see example). |
sd |
The estimated standard deviation within each cell; defaults to 1. |
Rsq |
The estimated R^2 for regressing the outcome on the covariates; defaults to 0. |
ncov |
The number of covariates adjusted for in the model; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
mmatrix <- matrix(c(9.3, 8.9, 8.5, 8.7, 8.3, 7.3), nrow = 2, byrow = TRUE)
cmatrix <- matrix(c(-1, 0, 0, 1, 0, 0), nrow = 2, byrow = TRUE)
anova2way.se.bal(n = 30, mmatrix = mmatrix, cmatrix = cmatrix, sd = 2, alpha = 0.025, sides = 1)
Power calculation for test of simple effect for two-way unbalanced analysis of variance
Description
Conducts power calculations for a test of a simple effect in a two-way unbalanced (unequal cell sizes) ANOVA. A "simple effect" is a contrast among the cell means. This function does not solve for sample size. For a test of a contrast in a balanced (equal cell sizes) two-way ANOVA, anova2way.se.bal can also be used and can solve for sample size. For a test of contrast among factor levels, see anova2way.c.unbal.
Usage
anova2way.se.unbal(
nmatrix = NULL,
mmatrix = NULL,
cmatrix = NULL,
sd = 1,
Rsq = 0,
ncov = 0,
alpha = 0.05,
sides = 2,
v = FALSE
)
Arguments
nmatrix |
A matrix of sample sizes (see example). |
mmatrix |
A matrix of group means (see example). |
cmatrix |
A matrix of contrast coefficients (see example). |
sd |
The estimated standard deviation within each group. |
Rsq |
The estimated R^2 for regressing the outcome on the covariates; defaults to 0. |
ncov |
The number of covariates adjusted for in the model; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed power).
Examples
nmatrix <- matrix(c(30, 30, 30, 30, 30, 30), nrow = 2, byrow = TRUE)
mmatrix <- matrix(c(9.3, 8.9, 8.5, 8.7, 8.3, 7.3), nrow = 2, byrow = TRUE)
cmatrix <- matrix(c(-1, 0, 0, 1, 0, 0), nrow = 2, byrow = TRUE)
anova2way.se.unbal(nmatrix = nmatrix, mmatrix = mmatrix, cmatrix = cmatrix,
sd = 2, alpha = 0.025, sides = 1)
Internal-use function for quality checking sets of parameters
Description
Internal-use function for quality checking sets of parameters
Usage
check.many(paramlist = NULL, type = c("oneof"))
Arguments
paramlist |
The list of parameters being checked. |
type |
The expected type of parameter: currently only supports "oneof". |
Value
If the check passes, returns nothing. If the check does not pass, throw an error.
Examples
N <- 10
power <- NULL
check.many(list(N, power), "oneof")
Internal-use function for quality checking individual parameters
Description
Internal-use function for quality checking individual parameters
Usage
check.param(
param = NULL,
type = c("req", "num", "unit", "uniti", "unitii", "pos", "int", "bool", "vals", "min",
"mini", "vec", "mat", "sum1", "sum0"),
valslist = NULL,
min = NULL
)
Arguments
param |
The parameter being checked. |
type |
The expected type of parameter: one of "req", "num", "unit(i)(i)", "pos", "int", "bool", "vals", "min(i)", "vec", "mat", "sum". |
valslist |
If the type is "vals", a list of allowed values. |
min |
If the type is "min" or "mini", a lower bound. |
Value
If the check passes, returns nothing. If the check does not pass, throw an error.
Examples
power <- 0.8
check.param(power, "unit")
Power calculation for chi-square goodness-of-fit test
Description
Performs sample size and power calculations for chi-square goodness-of-fit test, which is used to test whether a sample of data arises from a population with a specific discrete distribution. This function can solve for power, total sample size or alpha.
Usage
chisq.gof(
p0vec = NULL,
p1vec = NULL,
N = NULL,
alpha = 0.05,
power = NULL,
v = FALSE
)
Arguments
p0vec |
Vector of probabilities for the specified population distribution. Must sum to 1. |
p1vec |
Vector of expected probabilities for the sample. Must sum to 1. |
N |
The total number of observations. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
chisq.gof(p0vec = c(0.5, 0.3, 0.2), p1vec = c(0.7, 0.15, 0.15), N = 50)
Power calculation for chi-square test of independence
Description
Performs power and sample size calculations for a chi-square test of independence. The user inputs a matrix of cell probabilities for a two-way table. The function computes the power (or required total sample size) for a test of no association between the two factors.
Usage
chisq.indep(pmatrix = NULL, N = NULL, alpha = 0.05, power = NULL, v = FALSE)
Arguments
pmatrix |
The two-way probability table under the alternative hypothesis. The probabilities must sum to 1. |
N |
The total number of observations. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
chisq.indep(pmatrix = matrix(c(0.050, 0.350, 0.100, 0.075, 0.250, 0.175),
nrow = 2, byrow = TRUE), N = 230)
chisq.indep(pmatrix = matrix(c(0.3, 0.2, 0.4, 0.1), nrow = 2, byrow = TRUE), N = 200)
Power calculation for precision analysis (confidence interval) for one mean
Description
Calculates the "power" of a confidence interval for one mean, that is, the probability of achieving a 100(1 - alpha) percent confidence interval with halfwidth not greater than a specified value. Can solve for power, N or alpha.
Usage
ci.mean(
N = NULL,
halfwidth = NULL,
sd = 1,
alpha = 0.05,
power = NULL,
cond = FALSE,
v = FALSE
)
Arguments
N |
The sample size. |
halfwidth |
The desired halfwidth. |
sd |
The estimated standard deviation; defaults to 1. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
cond |
Specify whether to use unconditional or conditional probability. Defaults to FALSE (unconditional). |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
The unconditional probability is the probability of obtaining the desired precision (i.e., that the observed halfwidth does not exceed the desired halfwidth) regardless of whether or not the confidence interval includes the true parameter value. The conditional probability is the probability of both obtaining the desired precision and having the interval include the true parameter value.
Value
A list of the arguments (including the computed one).
Examples
ci.mean(N = NULL, halfwidth = 0.25, power = 0.8)
ci.mean(N = 62, halfwidth = 0.25, power = NULL)
ci.mean(N = 73, halfwidth = 0.25, cond = TRUE)
Power calculation for precision analysis (confidence interval) for a difference between two means
Description
Calculates the "power" of a confidence interval for a difference between two means, that is, the probability of achieving a 100(1 - alpha) percent confidence interval with halfwidth not greater than a specified value. This function can solve for power, n1, n.ratio or alpha.
Usage
ci.meandiff(
n1 = NULL,
n.ratio = 1,
halfwidth = NULL,
sd = 1,
alpha = 0.05,
power = NULL,
cond = FALSE,
v = FALSE
)
Arguments
n1 |
The sample size for group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
halfwidth |
The desired halfwidth for the difference in means. |
sd |
The estimated standard deviation; defaults to 1. Equal SDs in each group are assumed. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
cond |
Specify using unconditional or conditional probability. Defaults to FALSE. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
The unconditional probability is the probability of obtaining the desired precision (i.e., that the observed halfwidth does not exceed the desired halfwidth) regardless of whether or not the confidence interval includes the true parameter value. The conditional probability is the probability of both obtaining the desired precision and having the interval include the true parameter value.
Value
A list of the arguments (including the computed one).
Examples
ci.meandiff(n1 = NULL, halfwidth = 0.25, power = 0.8)
ci.meandiff(n1 = 134, halfwidth = 0.25, cond = TRUE)
Power calculations for multiple co-primary continuous endpoints assuming unknown covariance matrix
Description
Computes power for test involving multiple co-primary continuous endpoints, assuming that the covariance matrix (variances and covariances between endpoints) is unknown and therefore t-based test statistics will be used. Studies with co-primary endpoints use “all-or-none” testing procedures and only declare the trial to be a “success” if all endpoints are affirmed. All true mean differences must be positive (the scale for some outcomes may need to be reversed to meet this condition) and upper-tailed one-sided tests are assumed. For known covariance matrix, see coprimary.z.
Either sd and rho or Sigma must be specified.
Usage
coprimary.t(
K,
n1 = NULL,
n.ratio = 1,
delta = NULL,
Sigma,
sd,
rho,
alpha = 0.025,
power = NULL,
M = 10000,
v = FALSE
)
Arguments
K |
The number of endpoints. |
n1 |
The sample size for group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
delta |
A vector of length K of the true mean differences mu1k - mu2k; must all be positive. |
Sigma |
The covariance matrix of the K outcomes, of dimension K x K. |
sd |
A vector of length K of the standard deviations of the K outcomes. |
rho |
A vector of length 0.5K(K-1) of the correlations among the K outcomes. |
alpha |
The significance level or type 1 error rate; defaults to 0.025. A one-sided test is assumed. |
power |
The specified level of power. |
M |
Number of simulated values for the covariance matrix, simulated from Wishart distribution. Defaults to 10000. |
v |
Either TRUE for verbose output or FALSE to output computed argument only. |
Details
See Crespi et al. (2025) for more details. This function is based on the power.unknown.var function from the mpe R package and material from Sozu T, Sugimoto T, Hamasaki T, Evans SR. (2015) Sample Size Determination in Clinical Trials with Multiple Endpoints. Springer International Publishing, Switzerland.
This function can be computationally intensive and slow when solving for sample size. Smaller M can descrease computation time. The function coprimary.z provides a close approximation and is much faster.
Value
A list of the arguments (including the computed one).
Examples
# M is set to 10 in these examples to reduce runtime;
# please increase M or do not specify M (defaults to M = 10000) for optimal results
coprimary.t(K = 2, n1 = 100, delta = c(0.4, 0.5), sd = c(1, 1), rho = 0.3, alpha = 0.025,
power = NULL, M = 10)
Sigma <- matrix(c(1, 0.3, 0.3, 0.3, 1, 0.3, 0.3, 0.3, 1), nrow = 3, ncol = 3)
coprimary.t(K = 3, n1 = 200, delta = c(0.2, 0.3, 0.4), Sigma = Sigma, alpha = 0.025,
power = NULL, M = 10)
Power calculations for multiple co-primary continuous endpoints assuming known covariance matrix
Description
Computes power for test involving multiple co-primary continuous endpoints, assuming that the covariance matrix (variances and covariances between endpoints) is known and therefore z-based test statistics will be used. Studies with co-primary endpoints use “all-or-none” testing procedures and only declare the trial to be a “success” if all endpoints are affirmed. All true mean differences must be positive (the scale for some outcomes may need to be reversed to meet this condition) and upper-tailed one-sided tests are assumed. For the more realistic case that the covariance matrix is not known, see coprimary.t.
Either sd and rho or Sigma must be specified.
Usage
coprimary.z(
K,
n1 = NULL,
n.ratio = 1,
delta = NULL,
Sigma,
sd,
rho,
alpha = 0.025,
power = NULL,
v = FALSE
)
Arguments
K |
The number of endpoints. |
n1 |
The sample size for group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
delta |
A vector of length K of the true mean differences mu1k - mu2k; must all be positive. |
Sigma |
The covariance matrix of the K outcomes, of dimension K x K. |
sd |
A vector of length K of the standard deviations of the K outcomes. |
rho |
A vector of length 0.5K(K-1) of the correlations among the K outcomes. |
alpha |
The significance level or type 1 error rate; defaults to 0.025. A one-sided test is assumed. |
power |
The specified level of power. |
v |
Either TRUE for verbose output or FALSE to output computed argument only. |
Details
See Crespi et al. (2025) for more details. This function is based on the power.known.var function from the mpe R package and material from Sozu T, Sugimoto T, Hamasaki T, Evans SR. (2015) Sample Size Determination in Clinical Trials with Multiple Endpoints. Springer International Publishing, Switzerland.
Value
A list of the arguments (including the computed one).
Examples
coprimary.z(K = 2, n1 = 100, delta = c(0.4, 0.5), sd = c(1, 1), rho = 0.3,
alpha = 0.025, power = NULL)
Sigma <- matrix(c(1, 0.3, 0.3, 0.3, 1, 0.3, 0.3, 0.3, 1), nrow = 3, ncol = 3)
coprimary.z(K = 3, n1 = NULL, delta = c(0.2, 0.3, 0.4), Sigma = Sigma, alpha = 0.025, power = 0.8)
Power calculation for test of one correlation coefficient
Description
Calculates power and sample size for a test that the correlation coefficient in a single population is equal to (or less than or greater than) a specified value. Can solve for power, N or alpha.
Usage
corr.1samp(
N = NULL,
rho0 = 0,
rhoA = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
N |
The sample size. |
rho0 |
The correlation coefficient under the null hypothesis; defaults to 0. |
rhoA |
The correlation coefficient under the alternative hypothesis. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
corr.1samp(N = 100, rhoA = 0.2, sides = 1)
corr.1samp(N = 100, rho0 = 0.2, rhoA = 0.4, sides = 1)
Power calculation for comparing two correlation coefficients
Description
Calculates power and sample size for a test that the correlation coefficients in two groups/populations are equal. Can solve for power, n1, n.ratio or alpha.
Usage
corr.2samp(
n1 = NULL,
n.ratio = 1,
rho1 = NULL,
rho2 = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
n1 |
The sample size for group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
rho1 |
The correlation coefficient in group 1. |
rho2 |
The correlation coefficient in group 2. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
corr.2samp(n1 = 300, rho1 = 0.3, rho2 = 0.1, sides = 1)
Power for test of treatment effect in longitudinal cluster randomized trial with baseline measurement
Description
This function computes power and sample size for a cluster randomized trial in which a continuous outcome variable is measured during both baseline and follow-up periods among the cluster members, and it is planned that the outcome data will be analyzed using a linear mixed model in which the dependent variable vector includes both baseline and follow up measurements and there is a random intercept for cluster. This function can solve for power, J1, J.ratio, m or delta.
Usage
crt.long.cont(
m = NULL,
J1 = NULL,
J.ratio = 1,
delta = NULL,
sd = 1,
icc = 0,
cac = 0,
sac = 0,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
m |
The number of subjects measured during each cluster-period. |
J1 |
The number of clusters in arm 1. |
J.ratio |
The ratio J2/J1 between the number of clusters in the two arms; defaults to 1 (equal clusters per arm). |
delta |
The difference between the intervention and control means under the alternative minus the difference under the null hypothesis. |
sd |
The total standard deviation of the outcome variable; defaults to 1. |
icc |
The within-cluster, within-period intraclass correlation coefficient; defaults to 0. |
cac |
The cluster autocorrelation; defaults to 0. |
sac |
The subject autocorrelation; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
The intraclass correlation coefficient (icc) is the correlation between two observations from different subjects in the same cluster and same time period. Denote the correlation between observations from two different subjects in the same cluster but different time periods as iccb. The cluster autocorrelation (cac) is iccb/icc and is interpreted as the proportion of the cluster-level variance that is time-invariant. Denote the correlation between two observations from the same subject in different time periods as rhoa. The subject autocorrelation (sac) is (rhoa - icc)/(iccb - icc) and is interpreted as the proportion of the subject-level variance that is time-invariant. The sac is only relevant for design in which the same subjects are measured at both baseline and follow up. If different subjects are measured during different time periods, sac should be set to zero.
Value
A list of the arguments (including the computed one).
Examples
crt.long.cont(m = 30, J1 = 8, delta = 0.3, icc = 0.05, cac = 0.4, sac = 0.5)
Correlation between a cluster mean at baseline and follow up
Description
For a cluster randomized trial with a continuous outcome, this function calculates the correlation between a cluster's mean at baseline and at follow up based on various inputs. For cross-sectional sampling of subjects, that is, different subjects are measured at baseline and follow up, specify sac = 0.
Usage
crt.means.r(m, icc, cac, sac)
Arguments
m |
The number of measurements in each cluster at baseline and follow up. |
icc |
The intraclass correlation coefficient. |
cac |
The cluster autocorrelation. |
sac |
The subject autocorrelation. |
Value
The computed correlation.
Examples
crt.means.r(m = 30, icc = 0.05, cac = 0.4, sac = 0.5)
Power calculation for cluster randomized trial with binary outcome
Description
This function performs power and sample size calculations for a two-arm cluster randomized trial with a binary outcome. It assumes the outcome analysis will be conducted using a mixed effect logistic regression model that has a random intercept for cluster. Equal allocation of clusters to arms is assumed. Can solve for power, J, m or alpha.
Usage
crt.parallel.bin(
m = NULL,
m.sd = 0,
J = NULL,
pc = NULL,
pt = NULL,
sigma.u = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
m |
The number of subjects per cluster. |
m.sd |
The standard deviation of cluster sizes (provide if unequal number of participants per cluster); defaults to 0. |
J |
The total number of clusters (over both arms). |
pc |
The probability of the outcome in control clusters. |
pt |
The probability of the outcome in treatment clusters. |
sigma.u |
Standard deviation of the cluster random effect (random intercept). |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
For help selecting a reasonable value for sigma.u, consider using the crt.varexplore function.
Value
A list of the arguments (including the computed one).
Examples
crt.parallel.bin(m = 60, J = NULL, pc = 0.25, pt = 0.15, sigma.u = 0.3, power = 0.8)
crt.parallel.bin(m = 60, m.sd = 1, J = NULL, pc = 0.25, pt = 0.15, sigma.u = 0.3, power = 0.8)
Power for cluster randomized trial with continuous outcome
Description
This function performs power and sample size calculations for a two-arm cluster randomized trial with a continuous, normal outcome. Can solve for power, J1, J.ratio, m or alpha.
Usage
crt.parallel.cont(
m = NULL,
m.sd = 0,
J1 = NULL,
J.ratio = 1,
delta = NULL,
sd = 1,
icc1 = 0,
icc2 = 0,
ncov = 0,
RsqB = 0,
RsqW = 0,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
m |
The number of subjects per cluster or the mean cluster size (if unequal number of participants per cluster). |
m.sd |
The standard deviation of cluster sizes (provide if unequal number of participants per cluster); defaults to 0. |
J1 |
The number of clusters in arm 1. |
J.ratio |
The ratio J2/J1 between the number of clusters in the two arms; defaults to 1 (equal clusters per arm). |
delta |
The difference between the intervention and control means under the alternative minus the difference under the null hypothesis. |
sd |
The total standard deviation of the outcome variable; defaults to 1. |
icc1 |
The intraclass correlation coefficient in arm 1; defaults to 0. |
icc2 |
The intraclass correlation coefficient in arm 2; defaults to 0. |
ncov |
The number of cluster-level and individual-level covariates; defaults to 0. |
RsqB |
The estimated proportion of total variance explained by cluster-level covariates; defaults to 0. |
RsqW |
The estimated proportion of total variance explained by individual-level covariates; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
crt.parallel.cont(m = 30, J1 = 8, delta = 0.4, icc1 = 0.05, icc2 = 0.05)
crt.parallel.cont(m = NULL, J1 = 6, delta = 0.5, icc1 = 0.05, icc2 = 0.05, power = 0.8)
crt.parallel.cont(m = 25, m.sd = 15, J1 = NULL, delta = 0.3, icc1 = 0.05,
icc2 = 0.05, power = 0.8)
crt.parallel.cont(m = 20, J1 = 15, delta = 0.3, icc1 = 0.05, icc2 = 0.05,
RsqB = 0.1, ncov = 1, sides = 1)
Power for detecting treatment effect heterogeneity in a cluster randomized trial with a continuous outcome
Description
This function performs power and sample size calculations for detecting a treatment-by-covariate interaction effect in a two-arm cluster randomized trial with a continuous outcome when the data will be analyzed using a linear mixed effects model (random intercept for cluster and fixed effect for the treatment-by-covariate interaction). Can solve for power, beta, J1, J.ratio or m.
Usage
crt.parallel.hte(
m = NULL,
J1 = NULL,
J.ratio = 1,
beta = NULL,
sd.x = NULL,
sd.yx = NULL,
icc.x = 0,
icc.yx = 0,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
m |
The number of subjects per cluster. |
J1 |
The number of clusters in arm 1. |
J.ratio |
The ratio J2/J1 between the number of clusters in the two arms; defaults to 1 (equal clusters per arm). |
beta |
The regression coefficient for the treatment-by-covariate interaction term. |
sd.x |
The standard deviation of the covariate. |
sd.yx |
The standard deviation of the outcome variable adjusting for the covariate. |
icc.x |
The intraclass correlation coefficient for the covariate; defaults to 0. |
icc.yx |
The intraclass correlation coefficient for the outcome adjusting for the covariate; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
This function is based on Yang et al (2020). If the covariate is a cluster-level covariate, then icc.x should be set to 1 (the covariate does not vary within cluster).
Yang S, Li F, Starks MA, Hernandez AF, Mentz RJ, Choudhury KR (2020) Sample size requirements for detecting treatment effect heterogeneity in cluster randomized trials. Statistics in Medicine 39:4218-4237.
Value
A list of the arguments (including the computed one).
Examples
crt.parallel.hte(beta = 1, m = 27, J1 = 20, sd.x = 12.7, sd.yx = 71, icc.x = 0.08, icc.yx = 0.04)
Variance exploration for cluster randomized trials with binary outcomes
Description
This function can be used to help select a plausible value for the variance/SD of the random intercept for cluster in a cluster randomized trial with a binary outcome. Based on user-supplied values of the outcome proportions in the two arms, the function outputs, for a range of possible values of the SD of the random intercept, the intervals within which we expect about 95% of the cluster-level proportions to lie in each arm.
Usage
crt.varexplore(pc, pt, print = TRUE)
Arguments
pc |
The probability of the outcome in control clusters. |
pt |
The probability of the outcome in treatment clusters. |
print |
Whether or not to print the results in a table; defaults to TRUE. To retrieve the results even when print = FALSE, assign the function output to an object. |
Details
The use of this function is illustrated in Crespi CM (2025) Power and Sample Size in R.
Value
A list of the arguments and a dataframe of outputs.
Examples
crt.varexplore(pc = 0.25, pt = 0.15)
output <- crt.varexplore(pc = 0.25, pt = 0.15, print = FALSE)
output$pc
Power for test of treatment effect in 2x2 crossover cluster randomized trial
Description
Power and sample size calculation for a 2x2 crossover cluster randomized trial. Can solve for power, number of clusters per arm (assumes equal number of cluster per arm), m, delta or alpha.
Usage
crt.xo.cont(
m = NULL,
J.arm = NULL,
delta = NULL,
sd = 1,
icc = 0,
icca = 0,
iccb = NULL,
cac = NULL,
sac = 0,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
m |
The number of subjects measured during each cluster-period. |
J.arm |
The number of clusters in each arm. |
delta |
The difference between the intervention and control means under the alternative minus the difference under the null hypothesis. |
sd |
The total standard deviation of the outcome variable; defaults to 1. |
icc |
The within-cluster, within-period intraclass correlation coefficient; defaults to 0. |
icca |
The within-cluster, within-subject correlation (correlation between two measurements within the same subject); defaults to 0. |
iccb |
The within-cluster, between-period intraclass correlation coefficient. Either iccb OR cac must be specified. |
cac |
The cluster autocorrelation. Either iccb OR cac must be specified. |
sac |
The subject autocorrelation; defaults to 0. |
alpha |
The significance level or type 1 error rate; defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
crt.xo.cont(m = 30, J.arm = 4, delta = 0.3, icc = 0.05, cac = 0.8, sac = 0.4)
crt.xo.cont(m = 30, J.arm = 4, delta = 0.3, icc = 0.05, icca = 0.42, iccb = 0.04)
crt.xo.cont(m = 30, J.arm = 4, delta = 0.3, icc = 0.05, cac = 0.5)
Cohen f effect size calculation for one- or two- way analysis of variance
Description
Calculates teh Cohen f effect size for a one- or two-way ANOVA. Takes as input the cell or group means for a one- or two-way ANOVA and the common standard deviation and outputs the f effect size, as defined by Cohen (1988). Note that this effect size calculation is only valid when cell/group sizes are equal.
Usage
es.anova.f(means = NULL, sd = NULL, v = TRUE)
Arguments
means |
A vector or matrix of group means. |
sd |
The estimated standard deviation within each group. |
v |
Either TRUE for verbose output or FALSE to output computed argument only. |
Details
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
Value
Various calculated f effect sizes.
Examples
es.anova.f(means = c(5, 10, 12), sd = 10)
mmatrix <- matrix(c(9.3, 8.9, 8.5, 8.7, 8.3, 7.9), nrow = 2, byrow = TRUE)
es.anova.f(means = mmatrix, sd = 2)
Cohen d effect size calculation for one or two means
Description
This function takes as inputs a difference between two means and a standard deviation and outputs the d effect size as defined by Cohen (1988), also called the standardized mean difference.
Usage
es.d(delta = NULL, sd = 1)
Arguments
delta |
If one mean: muA (the true mean) - mu0 (the mean under the null). If two means: DeltaA (the true difference mu1 - mu2) - Delta0 (the difference under the null). |
sd |
The estimated standard deviation; defaults to 1. |
Details
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
Value
A list of the arguments and the d effect size.
Examples
es.d(delta = 6.5 - 5.7, sd = 0.4)
Cohen f-squared effect size for overall F test in multiple linear regression
Description
Computes the f-squared (f^2) effect size for an overall F test in a multiple linear regression model based on the model R^2 (Rsq). Based on Cohen (1988).
Usage
es.fsq.overall(Rsq = 0.02)
Arguments
Rsq |
The squared sample multiple correlation coefficient. |
Details
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
Value
A list of the arguments and the f^2 effect size.
Examples
es.fsq.overall(Rsq = 0.02)
Cohen f-squared effect size for partial F test in multiple linear regression
Description
Computes the f-squared (f^2) effect size for a partial F test in a multiple linear regression model using either model R^2 (Rsq) values or a partial correlation. Based on Cohen (1988). (EDIT THIS)
Usage
es.fsq.partial(Rsq.red = NULL, Rsq.full = NULL, Rsq.diff = NULL, pc = NULL)
Arguments
Rsq.red |
The squared population multiple correlation coefficient for the reduced model. Either 2 out of 3 Rsq terms OR pc must be specified. |
Rsq.full |
The squared population multiple correlation coefficient for the full model. Either 2 out of 3 Rsq terms OR pc must be specified. |
Rsq.diff |
The difference between the squared population multiple correlation coefficient for the full model and the reduced model. Either 2 out of 3 Rsq terms OR pc must be specified. |
pc |
The partial correlation coefficient. Either 2 out of 3 Rsq terms OR pc must be specified. |
Details
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
Value
A list of the arguments and the f^2 effect size.
Examples
es.fsq.partial(pc = 0.2)
es.fsq.partial(Rsq.red = 0.25, Rsq.full = 0.35)
es.fsq.partial(Rsq.red = 0.25, Rsq.diff = 0.1)
es.fsq.partial(Rsq.full = 0.35, Rsq.diff = 0.1)
Cohen h effect size calculation for two proportions
Description
Takes as input the outcome proportions in two groups and returns the h effect size as defined by Cohen (1988).
Usage
es.h(p1 = NULL, p2 = NULL)
Arguments
p1 |
The outcome proportion in group 1. |
p2 |
The outcome proportion in group 2. |
Details
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
Value
A list of the arguments and the h effect size.
Examples
es.h(p1 = 0.8, p2 = 0.6)
Cohen q effect size calculation for two correlation coefficients
Description
Calculates the q effect size for comparing two correlation coefficients. Based on Cohen (1988).
Usage
es.q(rho1 = NULL, rho2 = NULL)
Arguments
rho1 |
The correlation coefficient in group 1. |
rho2 |
The correlation coefficient in group 2. |
Details
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
Value
A list of the arguments and the q effect size.
Examples
es.q(rho1 = 0.3, rho2 = 0.1)
Cohen w effect size calculation for chi-square tests
Description
Calculates the w effect size for chi-square tests. For chi-square goodness of fit tests, specify p0vec and p1vec. For chi-square tests of independence, provide a matrix of cell probabilities. Based on Cohen (1988).
Usage
es.w(p0vec = NULL, p1vec = NULL, pmatrix = NULL)
Arguments
p0vec |
The first vector of probabilities. Both p0vec and p1vec, or pmatrix must be specified. |
p1vec |
The second vector of probabilities. Both p0vec and p1vec, or pmatrix must be specified. |
pmatrix |
The two-way probability table. Both p0vec and p1vec, or pmatrix must be specified. |
Details
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
Value
A list of the arguments and the w effect size.
Examples
es.w(p0vec = c(0.5, 0.3, 0.2), p1vec = c(0.7, 0.2, 0.1))
es.w(pmatrix = matrix(c(0.050, 0.350, 0.100, 0.075, 0.250, 0.175), nrow = 2, byrow = TRUE))
Power for individual randomized group treatment trial with binary outcome
Description
Computes power and sample size for an individually randomized group treatment trial with a binary outcome, in which after individual randomization, individuals in the intervention/treatment arm are clustered. Can solve for power, J, m, n, or alpha.
Usage
irgtt.bin(
m = NULL,
J = NULL,
n = NULL,
p1 = NULL,
p2 = NULL,
icc = 0,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
m |
The number of subjects per cluster in the intervention arm. |
J |
The total number of clusters in the intervention arm. |
n |
The total number of participants in the control arm. |
p1 |
The probability of the outcome in the control arm. |
p2 |
The probability of the outcome in the intervention arm. |
icc |
The intraclass correlation coefficient in the intervention arm; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two-sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
irgtt.bin(m = 20, J = 5, n = 100, p1 = 0.8, p2 = 0.6, icc = 0.04, sides = 2)
irgtt.bin(m = 20, J = 6, n = 120, p1 = 0.8, p2 = 0.6, icc = 0.04, sides = 2)
Power for individually randomized group treatment trial with continuous outcome
Description
Computes power and sample size for an individually randomized group treatment trial with a continuous outcome, in which after individual randomization, individuals in the intervention/treatment arm are clustered. Can solve for power, J, m, n, delta or alpha.
Usage
irgtt.cont(
m = NULL,
J = NULL,
n = NULL,
delta = NULL,
sd = 1,
icc = 0,
Theta = 1,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
m |
The number of subjects per cluster in the intervention arm. |
J |
The total number of clusters in the intervention arm. |
n |
The total number of participants in the control arm. |
delta |
The difference between the intervention and control means under the alternative minus the difference under the null hypothesis. |
sd |
The total standard deviation of the outcome variable in the control arm; defaults to 1. |
icc |
The intraclass correlation coefficient in the treatment arm; defaults to 0. |
Theta |
The ratio of the total variance in the intervention and control arms; defaults to 1. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two-sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
Power is solved for using noncentral t or F distribution; other quantities (for example, sample sizes) are solved for using normal approximation.
Value
A list of the arguments (including the computed one).
Examples
irgtt.cont(m = 10, J = 12, n = 120, delta = 0.4, icc = 0.05, Theta = 1, power = NULL)
irgtt.cont(m = 10, J = 12, n = NULL, delta = 0.4, icc = 0.05, Theta = 1, power = 0.8)
Power for detecting treatment effect heterogeneity in an individually randomized trial with a continuous outcome
Description
This function performs power and sample size calculations for detecting a treatment-by-covariate interaction effect in a two-arm randomized trial with a continuous outcome. Can solve for power, beta, n1 or n.ratio.
Usage
irt.hte(
n1 = NULL,
n.ratio = 1,
beta = NULL,
sd.x = NULL,
sd.yx = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
n1 |
The sample size for group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
beta |
The regression coefficient for the treatment-by-covariate interaction term. |
sd.x |
The standard deviation of the covariate. |
sd.yx |
The standard deviation of the outcome variable adjusting for the covariate. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
Shieh G (2009) Detecting interaction effects in moderated multiple regression with continuous variables: power and sample size considerations. Organizational Research Methods 12(3):510-528.
Yang S, Li F, Starks MA, Hernandez AF, Mentz RJ, Choudhury KR (2020) Sample size requirements for detecting treatment effect heterogeneity in cluster randomized trials. Statistics in Medicine 39:4218-4237.
Value
A list of the arguments (including the computed one).
Examples
irt.hte(n1 = 540, n.ratio = 1, beta = 1, sd.x = 12.7, sd.yx = 71)
Internal-use function for displaying matrices in function outputs
Description
Internal-use function for displaying matrices in function outputs
Usage
matrix.format(matrix = NULL, nspaces = 18)
Arguments
matrix |
The matrix to be displayed. |
nspaces |
The number of white spaces before the matrix; defaults to 18. |
Value
The matrix printed as a string with rows separated by newline.
Examples
matrix <- matrix(c(1, 2, 3, 4), nrow = 2)
matrix.format(matrix = matrix)
Power calculation for a multiple linear regression overall F test
Description
Conducts power and sample size calculations for an overall (or omnibus) F test in a multiple linear regression model. This is a test that all coefficients other than the intercept are equal to zero. Can solve for power, N or alpha.
Usage
mlrF.overall(
N = NULL,
p = NULL,
Rsq = NULL,
fsq = NULL,
alpha = 0.05,
power = NULL,
random = FALSE,
v = FALSE
)
Arguments
N |
The sample size. |
p |
The number of predictors. |
Rsq |
The squared population multiple correlation coefficient. |
fsq |
The f-squared effect size. Either Rsq OR fsq must be specified. |
alpha |
The significance level or type 1 error rate; defaults to 0.05. |
power |
The specified level of power. |
random |
Whether the values of the predictors are random; defaults to FALSE. |
v |
Either TRUE for verbose output or FALSE to output computed argument only. |
Details
Either Rsq OR fsq must be specified. These are related as fsq = Rsq/(1-Rsq). Rsq is the proportion of the total variation in Y that is explained by linear relationship with the predictors. Specifying random = TRUE yields a calculation in which Y and the predictors are assumed to have a multivariate normal distribution; see Crespi (2025).
Value
A list of the arguments (including the computed one).
Examples
mlrF.overall(N = 400, p = 2, Rsq = 0.02)
mlrF.overall(N = 400, p = 2, fsq = 0.02 / (1 - 0.02))
mlrF.overall(N = 109, p = 1, Rsq = 0.3^2)
mlrF.overall(N = 50, p = 1, Rsq = 0.2)
mlrF.overall(N = 50, p = 3, Rsq = 0.2)
mlrF.overall(N = 50, p = 5, Rsq = 0.2)
mlrF.overall(N = 400, p = 2, Rsq = 0.02, random = TRUE)
Power calculation for a multiple linear regression partial F test
Description
Conducts power and sample size calculations for a partial F test in a multiple linear regression model. This is a test that one or more coefficients are equal to zero after controlling for a set of control predictors. Can solve for power, N or alpha.
Usage
mlrF.partial(
N = NULL,
p = NULL,
q = NULL,
pc = NULL,
Rsq.red = NULL,
Rsq.full = NULL,
alpha = 0.05,
power = NULL,
v = FALSE
)
Arguments
N |
The sample size. |
p |
The number of control predictors. |
q |
The number of test predictors. Must be 1 when only pc is specified. |
pc |
The partial correlation coefficient. Either both Rsq terms OR pc must be specified. |
Rsq.red |
The squared population multiple correlation coefficient for the reduced model. Either both Rsq terms OR pc must be specified. |
Rsq.full |
The squared population multiple correlation coefficient for the full model. Either both Rsq terms OR pc must be specified. |
alpha |
The significance level or type 1 error rate; defaults to 0.05. |
power |
The specified level of power. |
v |
Either TRUE for verbose output or FALSE to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
mlrF.partial(N = 80, p = 3, q = 2, Rsq.red = 0.25, Rsq.full = 0.35)
mlrF.partial(N = 150, p = 4, q = 1, pc = 0.2)
Variance exploration for a multisite trial with a binary outcome
Description
This function can be used to help select a plausible value for the variance/SD of the random intercept for site in a multisite trial with a binary outcome. Based on user-supplied values of the outcome proportions in the two conditions, this function outputs, for a range of possible values of the SD, the intervals within which we expect about 95% of the site-specific odds ratios to lie.
Usage
ms.varexplore(pc, pt, print = TRUE)
Arguments
pc |
The probability of the outcome in control clusters. |
pt |
The probability of the outcome in treatment clusters. |
print |
Whether or not to print the results in a table; defaults to TRUE. To retrieve the results even when print = FALSE, assign the function output to an object. |
Details
In a multisite trial design, participants are randomized to conditions within site. The use of this function is illustrated in Crespi CM (2025) Power and Sample Size in R.
Value
A list containing the calculated OR and a dataframe of outputs.
Examples
ms.varexplore(pc = 0.1, pt = 0.2)
output <- ms.varexplore(pc = 0.1, pt = 0.2, print = FALSE)
output$OR
Power for a multisite trial with a binary outcome
Description
Performs power and sample size calculations for a multisite trial with a binary outcome. Can solve for power, J, m or alpha.
Usage
multisite.bin(
m = NULL,
alloc.ratio = 1,
J = NULL,
pc = NULL,
pt = NULL,
sigma.u = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
m |
The total number of subjects in condition 1 + condition 2. |
alloc.ratio |
The allocation ratio of condition 1/condition 2 within site; defaults to 1. |
J |
The total number of sites. |
pc |
The probability of the outcome in the control condition. |
pt |
The probability of the outcome in the treatment condition. |
sigma.u |
Standard deviation of the treatment effect across sites. |
alpha |
The significance level or type 1 error rate; defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
In a multisite trial design, participants are randomized to conditions within site. Consider using ms.varexplore to select plausible values for sigma.u.
Value
A list of the arguments (including the computed one).
Examples
multisite.bin(m = 30, J = 25, pc = 0.1, pt = 0.2, sigma.u = 0.4, power = NULL)
multisite.bin(m = 30, J = NULL, pc = 0.1, pt = 0.2, sigma.u = 0.4, power = 0.9)
Power for test of average treatment effect in a multisite trial
Description
Performs power and sample size calculations for a multisite trial with a continuous (normal) outcome variable. Can solve for power, J, m or alpha.
Usage
multisite.cont(
m = NULL,
m.sd = 0,
alloc.ratio = 1,
J = NULL,
delta = NULL,
sd = 1,
icc0 = NULL,
icc1 = NULL,
Rsq = 0,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
m |
The mean cluster/site size (number of participants per site). |
m.sd |
The standard deviation of cluster/site sizes (provide if unequal number of participants per site); defaults to 0. |
alloc.ratio |
The allocation ratio of condition 2/condition 1 within site; defaults to 1. |
J |
The total number of sites. |
delta |
The difference between the condition 1 and condition 2 means under the alternative minus the difference under the null hypothesis. |
sd |
The total standard deviation of the outcome variable; defaults to 1. |
icc0 |
The proportion of total variance of the outcome attributable to variation in site-level means. |
icc1 |
The proportion of total variance of the outcome attributable to variation in the treatment effect across sites. |
Rsq |
The estimated R^2 for regressing the outcome on the covariates; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
In a multisite trial design, participants are randomized to conditions within site.
Value
A list of the arguments (including the computed one).
Examples
multisite.cont(m = 20, J = 10, delta = 3, sd = sqrt(40), icc0 = 0.1, icc1 = 0)
multisite.cont(m = 20, J = 10, delta = 3, sd = sqrt(48), icc0 = 0.095, icc1 = 0.048)
multisite.cont(m = 20, alloc.ratio = 1.5, J = 10, delta = 0.43, icc0 = 0.095, icc1 = 0.048)
multisite.cont(m = 10, J = NULL, delta = 0.5, sd = 1, icc0 = 0, icc1 = 0.05, power = 0.8)
multisite.cont(m = 20, m.sd = 5, J = 10, delta = 3, sd = sqrt(48), icc0 = 0.095, icc1 = 0.048)
multisite.cont(m = 20, J = 10, delta = 3, sd = sqrt(48), icc0 = 0.095,
icc1 = 0.048, Rsq = 0.5^2)
Power for test of heterogeneity of treatment effect in a multisite trial
Description
Calculates power for a test of heterogeneity of the treatment effect in a multisite trial with a continuous outcome variable. In particular, let sigma.u1^2 be the variance of the site-level treatment effects. The test of heterogeneity tests the null hypothesis that sigma.u1^2 = 0 versus the alternative that sigma.u1^2 > 0. Can solve for power, J, or m.
Usage
multisite.hte(
m = NULL,
alloc.ratio = 1,
J = NULL,
VR = NULL,
alpha = 0.05,
power = NULL,
v = FALSE
)
Arguments
m |
The mean number of subjects per site. |
alloc.ratio |
The allocation ratio of intervention/control subjects per site; defaults to 1. |
J |
The total number of sites. |
VR |
The variance ratio (variance of the site-level treatment effects divided by variance of observations within sites) under the alternative. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
See Crespi CM (2025) for details.
Value
A list of the arguments (including the computed power).
Examples
multisite.hte(m = 10, J = 30, VR = 8 / 36)
Power calculation for one-sample proportion test
Description
Performs power and sample size calculations for a one-sample test of a proportion. Calculations use the large-sample normal approximation to the binomial. Can solve for power, N or alpha.
Usage
prop.1samp(
N = NULL,
p0 = NULL,
pA = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
N |
The sample size. |
p0 |
The proportion under the null. |
pA |
The true proportion. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
prop.1samp(N = NULL, p0 = 0.2, pA = 0.3, power = 0.8, sides = 1)
prop.1samp(N = NULL, p0 = 0.4, pA = 0.5, power = 0.8, sides = 1)
Power calculation for two-sample proportion test
Description
Performs power and sample size calculations for two-sample tests of proportions using normal approximation to the binomial. Can solve for power, n1, n.ratio or alpha.
Usage
prop.2samp(
n1 = NULL,
n.ratio = 1,
p1 = NULL,
p2 = NULL,
margin = 0,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
n1 |
The sample size for group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
p1 |
The proportion in group 1. |
p2 |
The proportion in group 2. |
margin |
The margin of noninferiority or superiority; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
For a noninferiority or superiority by a margin test, a one-sided test should be used. See Crespi (2025) for more guidance. For an equivalence test for two proportions, see the prop.test.equiv.
Value
A list of the arguments (including the computed one).
Examples
prop.2samp(n1 = NULL, p1 = 0.6, p2 = 0.8, alpha = 0.025, power = 0.9, sides = 1)
prop.2samp(n1 = NULL, p1 = 0.25, p2 = 0.25, margin = 0.1, alpha = 0.025, power = 0.8, sides = 1)
Power calculation for McNemar test of two correlated proportions
Description
Performs power and sample size calculation for McNemar test of two correlated proportions using normal approximation. Can solve for power, N or alpha.
Usage
prop.paired(
N = NULL,
p1 = NULL,
p2 = NULL,
phi = NULL,
paid = NULL,
dpr = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
N |
The sample size; the number of pairs. |
p1 |
The outcome proportion under condition 1. |
p2 |
The outcome proportion under condition 2. |
phi |
The correlation between the two responses from an individual. |
paid |
The smaller of the two discordant probabilities. Either p1, p2 and phi, OR paid and dpr must be specified. |
dpr |
The discordant proportion ratio. Must be greater than or equal to 1. Either p1, p2, and phi, OR paid and dpr must be specified. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
Either p1, p2 and phi, OR paid and dpr must be specified.
Value
A list of the arguments (including the computed one).
Examples
prop.paired(N = NULL, p1 = 0.8, p2 = 0.9, phi = 0, power = 0.9, sides = 2)
prop.paired(N = NULL, paid = 0.08, dpr = 0.18 / 0.08, power = 0.9, sides = 2)
Power calculation for test of equivalence of two proportions
Description
Performs power and sample size calculations for a test of equivalence for two proportions. Can solve for power, n1, n.ratio or alpha.
Usage
prop.test.equiv(
n1 = NULL,
n.ratio = 1,
p1 = NULL,
p2 = NULL,
margin = NULL,
alpha = 0.05,
power = NULL,
v = FALSE
)
Arguments
n1 |
The sample size for group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
p1 |
The outcome proportion in group 1. |
p2 |
The outcome proportion in group 2. |
margin |
The equivalence margin. |
alpha |
The significance level or type 1 error rate; defaults to 0.05. |
power |
The specified level of power. |
v |
Either TRUE for verbose output or FALSE to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
prop.test.equiv(n1 = NULL, p1 = 0.5, p2 = 0.5, margin = 0.1, alpha = 0.05, power = 0.8)
Power calculations for ordinal categorical variable under proportional odds assumption
Description
Performs power and sample size calculation for a comparison of two groups on an ordinal categorical response variable. Assumes that response probabilities follow the proportional odds assumption. Can solve for power, n1, n.ratio and alpha.
Usage
propodds(pC, OR, n1, n.ratio = 1, alpha = 0.05, power = NULL, v = FALSE)
Arguments
pC |
Vector of response probabilities in control group (group 1). Must sum to 1. Categories are ordered from best to worst. |
OR |
Odds ratio when the alternative is true. Must be greater than 1. |
n1 |
Sample size for group 1 (control group). |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power; defaults to 0.8. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
Whitehead J. (1993) Sample size calculations for ordered categorical data. Statistics in Medicine, 12(24):2257–2271
Value
A list of the arguments (including the computed one).
Examples
library(Hmisc)
pC <- c(0.2, 0.5, 0.2, 0.1)
propodds(pC = pC, OR = 2.5, n1 = 65, n.ratio = 1, alpha = 0.05)
Power calculation for rank-sum test
Description
This function performs power and sample size calculations for the Wilcoxon-Mann-Whitney rank-sum test, also called the Mann-Whitney U test, which is the nonparametric analog of the two independent sample t test. Calculations are based on the approximation given by Noether (1987) Sample size determination for some common nonparametric tests. JASA 82(398):645-647.
Usage
ranksum(
n1 = NULL,
n.ratio = 1,
p = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
n1 |
The sample size in group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
p |
The probability that an observation in group 2 is greater than an observation in group 1 (P(Y>X). |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two-sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
Due to symmetry, the power for p is equal to the power for 1 - p. Therefore, when solving for p, two values, p and 1 - p, are returned.
Value
A list of the arguments (including the computed one).
Examples
ranksum(n1 = 10, n.ratio = 1, p = 0.8, alpha = 0.05, power = NULL, sides = 2)
Relative efficiency of a cluster randomized or multisite trial with binary outcome with varying cluster sizes
Description
For a binary outcome, computes the relative efficiency (ratio of the variances) of a cluster randomized or multisite trial with varying cluster (site) sizes to that of a trial with constant cluster sizes, assuming equal total number of subjects. This approximation may not be valid for all combinations of parameters, for example when m.sd is large.
Usage
re.clustsize.bin(m, m.sd, pc, pt, sigma.u)
Arguments
m |
The number of subjects per cluster or the mean cluster size (if unequal number of participants per cluster). |
m.sd |
The standard deviation of cluster sizes (in case of unequal number of participants per cluster). |
pc |
The probability of the outcome in control clusters. |
pt |
The probability of the outcome in treatment clusters. |
sigma.u |
Standard deviation of the cluster random effect. |
Details
Candel MJJM and van Breukelen GJP (2010) Sample size adjustments for varying cluster sizes in cluster randomized trials with binary outcomes analyzed with second-order PQL mixed logistic regression. Statistics in Medicine 29(14):1488-1501.
Value
The computed RE.
Examples
re.clustsize.bin(m = 60, m.sd = 45, pc = 0.25, pt = 0.15, sigma.u = 0.3)
Relative efficiency of a cluster randomized or multisite trial with continuous outcome with varying cluster sizes
Description
For a continuous outcome, computes the relative efficiency (ratio of the variances) of a cluster randomized or multisite trial with varying cluster (site) sizes to that of a trial with constant cluster sizes, assuming equal total number of subjects. This approximation may not be valid for all combinations of parameters, for example when m.sd is large.
Usage
re.clustsize.cont(m, m.sd, icc)
Arguments
m |
The number of subjects per cluster or the mean cluster size (if unequal number of participants per cluster). |
m.sd |
The standard deviation of cluster sizes (in case of unequal number of participants per cluster). |
icc |
The intraclass correlation coefficient. For a multisite trial this is icc1. For a CRT this is the average of the 2 icc's. |
Value
The computed RE.
Examples
re.clustsize.cont(m = 25, m.sd = 15, icc = 0.05)
Power calculation for relative risk
Description
Performs power and sample size calculations for a test of relative risk, p2/p1. Can solve for power, N1, n.ratio or alpha.
Usage
relrisk(
n1 = NULL,
n.ratio = 1,
p1 = NULL,
p2 = NULL,
RR0 = 1,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
n1 |
The sample size for group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
p1 |
The proportion in group 1. |
p2 |
The proportion in group 2. |
RR0 |
The relative risk under the null (p2/p1); defaults to 1. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
relrisk(n1 = NULL, n.ratio = 1/6, p1 = 0.1, p2 = 0.1 * 2, power = 0.8)
Internal-use wrapper for catching errors induced by stats::uniroot
Description
Internal-use wrapper for catching errors induced by stats::uniroot
Usage
safe.uniroot(f = NULL, interval = NULL)
Arguments
f |
The function for which the root is sought |
interval |
A vector containing the end-points of the interval to be searched for the root |
Value
If no error occurs, returns the solved root. If an error occurs, output a custom message.
Examples
f <- function(x) x - 3
safe.uniroot(f, c(-10, 10))$root
Power calculation for signed-rank test
Description
The signed-rank test is a nonparametric alternative to a one-sample or paired t test. This function performs power and sample size calculations for the signed-rank test using Noether's approximation; see Noether (1987) Sample size determination for some common nonparametric tests. JASA 82(398):645-647.
Usage
signedrank(
N = NULL,
ps = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
N |
The sample size; number of observations or paired differences. |
ps |
The probability that the sum of two values exceeds zero when the alternative hypothesis is true. |
alpha |
The significance level or type 1 error rate; defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two-sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE to output computed argument only. |
Details
Due to symmetry, the power for p is equal to the power for 1 - p. Therefore, when solving for p, two values, p and 1 - p, are returned.
Value
A list of the arguments (including the computed one).
Examples
signedrank(N = 20, ps = 0.87, power = NULL, sides = 2)
Power calculation for sign test
Description
The sign test is a nonparametric one-sample test of location, specifically, a test of whether the median equals (or is less than or greater than) zero. Its typical use is in place of a one-sample or paired t test when the normality assumption is violated. This function performs power and sample size calculations for a sign test using the normal approximation to the binomial distribution, based on Noether (1987) Sample size determination for some common nonparametric tests. JASA 82(398):645-647.
Power calculation for an exact sign test using the exact binomial test can be performed using the power_binom_test function from the MESS package; see Crespi CM (2025) Power and Sample Size in R. Routledge, New York, NY.
Usage
signtest(N = NULL, p = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE)
Arguments
N |
The sample size. |
p |
The probability of a positive difference when the alternative hypothesis is true. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two-sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
When solving for p, two values, p and 1 - p, are returned. For a two-sided test, due to symmetry, the power for p is equal to the power for 1 - p. For a one-sided upper-tailed test (rejecting null hypothesis when median > 0), select the higher value. For a one-sided lower-tailed test (rejecting null hypothesis when median < 0), select the lower value.
Value
A list of the arguments (including the computed one).
Examples
signtest(N = 40, p = 0.7, power = NULL, alpha = 0.05, sides = 1)
Power calculation for a simple linear regression
Description
Performs sample size and power calculations for a simple linear regression. Can solve for power, N or alpha. Required inputs include the values of the slope regression coefficient under the null hypothesis and the alternative, the variance of the covariate X, and the SD of the error. Power calculations for a simple linear regression can also be conducted using the mlrF.overall function, which requires fewer inputs.
Usage
slr(
N = NULL,
beta10 = 0,
beta1A = NULL,
var.x = NULL,
sigma.e = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
N |
The sample size. |
beta10 |
The slope regression coefficient under the null hypothesis; defaults to 0. |
beta1A |
The slope regression coefficient under the alternative hypothesis. |
var.x |
The variance of the covariate X. |
sigma.e |
The standard deviation of the error terms. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
# Yi = beta0 + beta1 * Xi + ei, i = 1,...,N
slr(N = 100, beta10 = 1, beta1A = 1.5, var.x = 25, sigma.e = 10, sides = 1)
Power calculation for one-sample t test
Description
This function computes power and sample size for a one-sample t test. Can solve for power, N, delta, sd or alpha.
Usage
ttest.1samp(
N = NULL,
delta = NULL,
sd = 1,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
N |
The sample size. |
delta |
muA (the true mean) - mu0 (the mean under the null). |
sd |
The standard deviation; defaults to 1. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two-sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
ttest.1samp(N = 36, delta = 4.9 - 5.7, sd = 2, sides = 1)
ttest.1samp(N = 36, delta = 6.3 - 5.7, sd = 2, sides = 1)
ttest.1samp(N = 36, delta = 4.9 - 5.7, sd = 2, sides = 2)
ttest.1samp(delta = 0.6, sd = 1, power = 0.8, sides = 1)
Power calculation for two-sample t test
Description
This function computes power and sample size for a two-sample t test. Unequal sample sizes and/or unequal variances in the two groups are allowed. Can solve for power, n1, n.ratio, sd1, sd.ratio, delta or alpha.
Usage
ttest.2samp(
n1 = NULL,
n.ratio = 1,
delta = NULL,
sd1 = 1,
sd.ratio = 1,
df.method = c("welch", "classical"),
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
n1 |
The sample size for group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
delta |
DeltaA (true difference mu1 - mu2) - Delta0 (difference under the null). For a noninferiority or superiority by a margin test, the margin should be subtracted, that is, delta = DeltaA - Delta0 - margin. |
sd1 |
The standard deviation for group 1; defaults to 1 (equal standard deviations in the two groups). |
sd.ratio |
The ratio sd2/sd1 between the standard deviations of the two groups. |
df.method |
Method for calculating the degrees of freedom: "welch" (default) or "classical", which is n1+n2-2. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
For a noninferiority or superiority by a margin test, the margin should be subtracted as part of the specification of delta and a one-sided test should be used. See Crespi (2025) for specific guidance. For an equivalence test for two means, see the sampleN.TOST function from the PowerTOST package.
Value
A list of the arguments (including the computed one).
Examples
ttest.2samp(n1 = 50, delta = 2, sd1 = 5, sides = 1)
ttest.2samp(n1 = NULL, n.ratio = 2, delta = 0.5, sd1 = 1, power = 0.8, sides = 2)
ttest.2samp(n1 = 49, n.ratio = 2, delta = 0.5, sd1 = 1, power = NULL, sides = 2)
ttest.2samp(n1 = 25, n.ratio = 3, delta = 3, sd1 = 4, sd.ratio = 1.5, alpha = 0.025, sides = 1)
ttest.2samp(n1 = NULL, delta = 0.5, sd1 = 1, power = 0.8, sides = 2)
Power calculation for paired t test
Description
Performs power and sample size calculations for a paired t test. Can solve for power, N, delta or alpha.
Usage
ttest.paired(
N = NULL,
delta = NULL,
sd1 = 1,
sd2 = NULL,
rho = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
N |
The sample size; if the observations are paired differences, this is the number of pairs. |
delta |
DeltaA (the true mean difference) - Delta0 (the mean difference under the null). |
sd1 |
The pre standard deviation; defaults to 1. |
sd2 |
The post standard deviation; defaults to the value of sd1. |
rho |
The correlation between pre and post measurements on the same individual. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
ttest.paired(N = NULL, delta = 4, sd1 = 10, sd2 = 10, rho = 0.4, power = 0.8, sides = 2)
Power calculation for one-sample z test
Description
This function performs power and sample size calculations for a one-sample z test which is analogous to a one-sample t test with the variance assumed to be known. This function is provided largely for pedagogical purposes; in general, for real studies, the one-sample t test procedure should be used.
Usage
ztest.1samp(
N = NULL,
delta = NULL,
sd = 1,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
N |
The sample size. |
delta |
muA (the true mean) - mu0 (the mean under the null). |
sd |
The standard deviation; defaults to 1. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
ztest.1samp(N = NULL, delta = 6.5 - 5.7, sd = 2, power = 0.8, sides = 2)
ztest.1samp(N = 40, delta = NULL, sd = 1, power = 0.9, sides = 2)
ztest.1samp(N = NULL, delta = 0.6, sd = 1, power = 0.8, sides = 1)
Power calculation for two-sample z test
Description
This function performs power and sample size calculations for a two-sample z test. which is analogous to a two-sample t test but with the variances assumed to be known. The function allows for unequal sample sizes and/or variances in the two groups. This function is provided largely for pedagogical purposes; in general, for real studies, the two-sample t test procedure should be used.
Usage
ztest.2samp(
n1 = NULL,
n.ratio = 1,
delta = NULL,
sd1 = 1,
sd.ratio = 1,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
n1 |
The sample size for group 1. |
n.ratio |
The ratio n2/n1 between the sample sizes of two groups; defaults to 1 (equal group sizes). |
delta |
DeltaA (true difference mu1 - mu2) - Delta0 (difference under the null). For a noninferiority or superiority by a margin test, the margin should be subtracted, that is, delta = DeltaA - Delta0 - margin. |
sd1 |
The standard deviation for group 1; defaults to 1 (equal standard deviations in the two groups). |
sd.ratio |
The ratio sd2/sd1 between the standard deviations of the two groups. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Details
For a noninferiority or superiority by a margin test, the margin should be subtracted as part of the specification of delta and a one-sided test should be used. See Crespi (2025) for specific guidance.
Value
A list of the arguments (including the computed one).
Examples
ztest.2samp(n1 = NULL, n.ratio = 1, delta = 0.5, sd1 = 1, power = 0.8, sides = 2)
Power calculation for paired z test
Description
This function performs power and sample size calculations for a paired z test which is analogous to a paired t test with variance assumed to be known. This function is provided largely for pedagogical purposes; in general, for real studies, the paired t test procedure should be used.
Usage
ztest.paired(
N = NULL,
delta = NULL,
sd1 = 1,
sd2 = NULL,
rho = NULL,
alpha = 0.05,
power = NULL,
sides = 2,
v = FALSE
)
Arguments
N |
The sample size; the number of pairs. |
delta |
DeltaA (the true mean difference) - Delta0 (the mean difference under the null). |
sd1 |
The pre standard deviation; defaults to 1. |
sd2 |
The post standard deviation; defaults to the value of sd1. |
rho |
The correlation between pre and post measurements on the same individual; defaults to 0. |
alpha |
The significance level (type 1 error rate); defaults to 0.05. |
power |
The specified level of power. |
sides |
Either 1 or 2 (default) to specify a one- or two- sided hypothesis test. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Value
A list of the arguments (including the computed one).
Examples
ztest.paired(N = NULL, delta = 4, sd1 = 10, sd2 = 10, rho = 0.4, power = 0.8, sides = 2)