Title: | Power and Sample Size Tools |
---|---|
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). |
Authors: | Catherine M. Crespi [aut, cre], Zichen Liu [aut], Kristen M. McGreevy [ctb] |
Maintainer: | Catherine M. Crespi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.2 |
Built: | 2024-11-25 16:24:27 UTC |
Source: | CRAN |
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.
altprimary( K, n1 = NULL, n.ratio = 1, delta = NULL, Sigma, sd, rho, alpha = 0.025, power = NULL, v = FALSE )
altprimary( K, n1 = NULL, n.ratio = 1, delta = NULL, Sigma, sd, rho, alpha = 0.025, power = NULL, v = FALSE )
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. |
Sozu T, Sugimoto T, Hamasaki T, Evans SR (2015) Sample Size Determination in Clinical Trials with Multiple Endpoints. Springer International Publishing, Switzerland.
A list of the arguments (including the computed one).
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)
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)
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.
anova1way.c.bal( n = NULL, mvec = NULL, cvec = NULL, sd = 1, Rsq = 0, ncov = 0, alpha = 0.05, power = NULL, v = FALSE )
anova1way.c.bal( n = NULL, mvec = NULL, cvec = NULL, sd = 1, Rsq = 0, ncov = 0, alpha = 0.05, power = NULL, v = FALSE )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
anova1way.c.unbal( nvec = NULL, mvec = NULL, cvec = NULL, sd = NULL, Rsq = 0, ncov = 0, alpha = 0.05, v = FALSE )
anova1way.c.unbal( nvec = NULL, mvec = NULL, cvec = NULL, sd = NULL, Rsq = 0, ncov = 0, alpha = 0.05, v = FALSE )
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. |
A list of the arguments (including the computed power).
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)
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)
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'.
anova1way.F.bal( n = NULL, mvec = NULL, sd = 1, Rsq = 0, ncov = 0, alpha = 0.05, power = NULL, v = FALSE )
anova1way.F.bal( n = NULL, mvec = NULL, sd = 1, Rsq = 0, ncov = 0, alpha = 0.05, power = NULL, v = FALSE )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
anova1way.F.unbal( nvec = NULL, mvec = NULL, sd = NULL, Rsq = 0, ncov = 0, alpha = 0.05, v = FALSE )
anova1way.F.unbal( nvec = NULL, mvec = NULL, sd = NULL, Rsq = 0, ncov = 0, alpha = 0.05, v = FALSE )
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. |
A list of the arguments (including the computed power).
anova1way.F.unbal(nvec = c(10, 20, 30), mvec = c(5, 10, 12), sd = 10)
anova1way.F.unbal(nvec = c(10, 20, 30), mvec = c(5, 10, 12), sd = 10)
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.
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 )
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 )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
anova2way.c.unbal( nmatrix = nmatrix, mmatrix = NULL, cvec = NULL, factor = c("a", "b"), sd = NULL, Rsq = 0, ncov = 0, alpha = 0.05, v = FALSE )
anova2way.c.unbal( nmatrix = nmatrix, mmatrix = NULL, cvec = NULL, factor = c("a", "b"), sd = NULL, Rsq = 0, ncov = 0, alpha = 0.05, v = FALSE )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
anova2way.F.bal( n = NULL, mmatrix = NULL, sd = 1, Rsq = 0, ncov = 0, alpha = 0.05, power = NULL, v = FALSE )
anova2way.F.bal( n = NULL, mmatrix = NULL, sd = 1, Rsq = 0, ncov = 0, alpha = 0.05, power = NULL, v = FALSE )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
anova2way.F.unbal( nmatrix = NULL, mmatrix = NULL, sd = NULL, Rsq = 0, ncov = 0, alpha = 0.05, v = FALSE )
anova2way.F.unbal( nmatrix = NULL, mmatrix = NULL, sd = NULL, Rsq = 0, ncov = 0, alpha = 0.05, v = FALSE )
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. |
A list of the arguments (including the computed power).
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)
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)
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.
anova2way.se.bal( n = NULL, mmatrix = NULL, cmatrix = NULL, sd = 1, Rsq = 0, ncov = 0, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
anova2way.se.bal( n = NULL, mmatrix = NULL, cmatrix = NULL, sd = 1, Rsq = 0, ncov = 0, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
anova2way.se.unbal( nmatrix = NULL, mmatrix = NULL, cmatrix = NULL, sd = 0, Rsq = 0, ncov = 0, alpha = 0.05, sides = 2, v = FALSE )
anova2way.se.unbal( nmatrix = NULL, mmatrix = NULL, cmatrix = NULL, sd = 0, Rsq = 0, ncov = 0, alpha = 0.05, sides = 2, v = FALSE )
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. |
A list of the arguments (including the computed power).
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)
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)
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.
chisq.gof( p0vec = NULL, p1vec = NULL, N = NULL, alpha = 0.05, power = NULL, v = FALSE )
chisq.gof( p0vec = NULL, p1vec = NULL, N = NULL, alpha = 0.05, power = NULL, v = FALSE )
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. |
A list of the arguments (including the computed one).
chisq.gof(p0vec = c(0.5, 0.3, 0.2), p1vec = c(0.7, 0.15, 0.15), N = 50)
chisq.gof(p0vec = c(0.5, 0.3, 0.2), p1vec = c(0.7, 0.15, 0.15), N = 50)
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.
chisq.indep(pmatrix = NULL, N = NULL, alpha = 0.05, power = NULL, v = FALSE)
chisq.indep(pmatrix = NULL, N = NULL, alpha = 0.05, power = NULL, v = FALSE)
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. |
A list of the arguments (including the computed one).
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)
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)
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.
ci.mean( N = NULL, halfwidth = NULL, sd = 1, alpha = 0.05, power = NULL, cond = FALSE, v = FALSE )
ci.mean( N = NULL, halfwidth = NULL, sd = 1, alpha = 0.05, power = NULL, cond = FALSE, v = FALSE )
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. |
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.
A list of the arguments (including the computed one).
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)
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)
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.
ci.meandiff( n1 = NULL, n.ratio = 1, halfwidth = NULL, sd = 1, alpha = 0.05, power = NULL, cond = FALSE, v = FALSE )
ci.meandiff( n1 = NULL, n.ratio = 1, halfwidth = NULL, sd = 1, alpha = 0.05, power = NULL, cond = FALSE, v = FALSE )
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. |
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.
A list of the arguments (including the computed one).
ci.meandiff(n1 = NULL, halfwidth = 0.25, power = 0.8) ci.meandiff(n1 = 134, halfwidth = 0.25, cond = TRUE)
ci.meandiff(n1 = NULL, halfwidth = 0.25, power = 0.8) ci.meandiff(n1 = 134, halfwidth = 0.25, cond = TRUE)
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.
coprimary.t( K, n1 = NULL, n.ratio = 1, delta = NULL, Sigma, sd, rho, alpha = 0.025, power = NULL, M = 10000, v = FALSE )
coprimary.t( K, n1 = NULL, n.ratio = 1, delta = NULL, Sigma, sd, rho, alpha = 0.025, power = NULL, M = 10000, v = FALSE )
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. |
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.
A list of the arguments (including the computed one).
# 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)
# 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)
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.
coprimary.z( K, n1 = NULL, n.ratio = 1, delta = NULL, Sigma, sd, rho, alpha = 0.025, power = NULL, v = FALSE )
coprimary.z( K, n1 = NULL, n.ratio = 1, delta = NULL, Sigma, sd, rho, alpha = 0.025, power = NULL, v = FALSE )
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. |
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.
A list of the arguments (including the computed one).
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)
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)
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.
corr.1samp( N = NULL, rho0 = 0, rhoA = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
corr.1samp( N = NULL, rho0 = 0, rhoA = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
A list of the arguments (including the computed one).
corr.1samp(N = 100, rhoA = 0.2, sides = 1) corr.1samp(N = 100, rho0 = 0.2, rhoA = 0.4, sides = 1)
corr.1samp(N = 100, rhoA = 0.2, sides = 1) corr.1samp(N = 100, rho0 = 0.2, rhoA = 0.4, sides = 1)
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.
corr.2samp( n1 = NULL, n.ratio = 1, rho1 = NULL, rho2 = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
corr.2samp( n1 = NULL, n.ratio = 1, rho1 = NULL, rho2 = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
A list of the arguments (including the computed one).
corr.2samp(n1 = 300, rho1 = 0.3, rho2 = 0.1, sides = 1)
corr.2samp(n1 = 300, rho1 = 0.3, rho2 = 0.1, sides = 1)
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.
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 )
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 )
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. |
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.
A list of the arguments (including the computed one).
crt.long.cont(m = 30, J1 = 8, delta = 0.3, icc = 0.05, cac = 0.4, sac = 0.5)
crt.long.cont(m = 30, J1 = 8, delta = 0.3, icc = 0.05, cac = 0.4, sac = 0.5)
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.
crt.means.r(m, icc, cac, sac)
crt.means.r(m, icc, cac, sac)
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. |
The computed correlation.
crt.means.r(m = 30, icc = 0.05, cac = 0.4, sac = 0.5)
crt.means.r(m = 30, icc = 0.05, cac = 0.4, sac = 0.5)
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.
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 )
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 )
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. |
For help selecting a reasonable value for sigma.u, consider using the crt.varexplore function.
A list of the arguments (including the computed one).
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)
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)
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.
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 )
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 )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
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 )
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 )
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. |
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.
A list of the arguments (including the computed one).
crt.parallel.hte(beta = 1, m = 27, J1 = 20, sd.x = 12.7, sd.yx = 71, icc.x = 0.08, icc.yx = 0.04)
crt.parallel.hte(beta = 1, m = 27, J1 = 20, sd.x = 12.7, sd.yx = 71, icc.x = 0.08, icc.yx = 0.04)
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.
crt.varexplore(pc, pt, print = TRUE)
crt.varexplore(pc, pt, print = TRUE)
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. |
The use of this function is illustrated in Crespi CM (2025) Power and Sample Size in R.
A list of the arguments and a dataframe of outputs.
crt.varexplore(pc = 0.25, pt = 0.15) output <- crt.varexplore(pc = 0.25, pt = 0.15, print = FALSE) output$pc
crt.varexplore(pc = 0.25, pt = 0.15) output <- crt.varexplore(pc = 0.25, pt = 0.15, print = FALSE) output$pc
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.
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 )
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 )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
es.anova.f(means = NULL, sd = NULL, v = TRUE)
es.anova.f(means = NULL, sd = NULL, v = TRUE)
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. |
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
Various calculated f effect sizes.
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)
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)
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.
es.d(delta = NULL, sd = 1)
es.d(delta = NULL, sd = 1)
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. |
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
A list of the arguments and the d effect size.
es.d(delta = 6.5 - 5.7, sd = 0.4)
es.d(delta = 6.5 - 5.7, sd = 0.4)
Computes the f-squared (r^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).
es.fsq(Rsq = 0.02)
es.fsq(Rsq = 0.02)
Rsq |
The squared sample multiple correlation coefficient. |
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
A list of the arguments and the f^2 effect size.
es.fsq(Rsq = 0.02)
es.fsq(Rsq = 0.02)
Takes as input the outcome proportions in two groups and returns the h effect size as defined by Cohen (1988).
es.h(p1 = NULL, p2 = NULL)
es.h(p1 = NULL, p2 = NULL)
p1 |
The outcome proportion in group 1. |
p2 |
The outcome proportion in group 2. |
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
A list of the arguments and the h effect size.
es.h(p1 = 0.8, p2 = 0.6)
es.h(p1 = 0.8, p2 = 0.6)
Calculates the q effect size for comparing two correlation coefficients. Based on Cohen (1988).
es.q(rho1 = NULL, rho2 = NULL)
es.q(rho1 = NULL, rho2 = NULL)
rho1 |
The correlation coefficient in group 1. |
rho2 |
The correlation coefficient in group 2. |
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
A list of the arguments and the q effect size.
es.q(rho1 = 0.3, rho2 = 0.1)
es.q(rho1 = 0.3, rho2 = 0.1)
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).
es.w(p0vec = NULL, p1vec = NULL, pmatrix = NULL)
es.w(p0vec = NULL, p1vec = NULL, pmatrix = NULL)
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. |
Cohen J (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd edition. Lawrence Erlbaum Associates, Hillsdale, New Jersey
A list of the arguments and the w effect size.
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))
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))
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.
irgtt.bin( m = NULL, J = NULL, n = NULL, p1 = NULL, p2 = NULL, icc = 0, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
irgtt.bin( m = NULL, J = NULL, n = NULL, p1 = NULL, p2 = NULL, icc = 0, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
irgtt.cont( m = NULL, J = NULL, n = NULL, delta = NULL, sd = 1, icc = 0, Theta = 1, alpha = 0.05, power = NULL, sides = 2, tol = .Machine$double.eps^0.25, v = FALSE )
irgtt.cont( m = NULL, J = NULL, n = NULL, delta = NULL, sd = 1, icc = 0, Theta = 1, alpha = 0.05, power = NULL, sides = 2, tol = .Machine$double.eps^0.25, v = FALSE )
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. |
tol |
The desired accuracy (convergence tolerance) for uniroot. |
v |
Either TRUE for verbose output or FALSE (default) to output computed argument only. |
Power is solved for using noncentral t or F distribution; other quantities (for example, sample sizes) are solved for using normal approximation.
A list of the arguments (including the computed one).
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)
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)
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.
irt.hte( n1 = NULL, n.ratio = 1, beta = NULL, sd.x = NULL, sd.yx = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
irt.hte( n1 = NULL, n.ratio = 1, beta = NULL, sd.x = NULL, sd.yx = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
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.
A list of the arguments (including the computed one).
irt.hte(n1 = 540, n.ratio = 1, beta = 1, sd.x = 12.7, sd.yx = 71)
irt.hte(n1 = 540, n.ratio = 1, beta = 1, sd.x = 12.7, sd.yx = 71)
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.
mlrF.overall( N = NULL, p = NULL, Rsq = NULL, fsq = NULL, alpha = 0.05, power = NULL, random = FALSE, v = FALSE )
mlrF.overall( N = NULL, p = NULL, Rsq = NULL, fsq = NULL, alpha = 0.05, power = NULL, random = FALSE, v = FALSE )
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. |
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).
A list of the arguments (including the computed one).
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)
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)
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.
mlrF.partial( N = NULL, p = NULL, q = NULL, pc = NULL, Rsq.red = NULL, Rsq.full = NULL, alpha = 0.05, power = NULL, v = FALSE )
mlrF.partial( N = NULL, p = NULL, q = NULL, pc = NULL, Rsq.red = NULL, Rsq.full = NULL, alpha = 0.05, power = NULL, v = FALSE )
N |
The sample size. |
p |
The number of control predictors. |
q |
The number of test predictors. |
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. |
A list of the arguments (including the computed one).
mlrF.partial(N = 80, p = 3, q = 2, Rsq.red = 0.25, Rsq.full = 0.35) mlrF.partial(N = 150, p = 4, pc = 0.2)
mlrF.partial(N = 80, p = 3, q = 2, Rsq.red = 0.25, Rsq.full = 0.35) mlrF.partial(N = 150, p = 4, pc = 0.2)
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.
ms.varexplore(pc, pt, print = TRUE)
ms.varexplore(pc, pt, print = TRUE)
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. |
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.
A list containing the calculated OR and a dataframe of outputs.
ms.varexplore(pc = 0.1, pt = 0.2) output <- ms.varexplore(pc = 0.1, pt = 0.2, print = FALSE) output$OR
ms.varexplore(pc = 0.1, pt = 0.2) output <- ms.varexplore(pc = 0.1, pt = 0.2, print = FALSE) output$OR
Performs power and sample size calculations for a multisite trial with a binary outcome. Can solve for power, J, m or alpha.
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 )
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 )
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. |
In a multisite trial design, participants are randomized to conditions within site. Consider using ms.varexplore to select plausible values for sigma.u.
A list of the arguments (including the computed one).
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)
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)
Performs power and sample size calculations for a multisite trial with a continuous (normal) outcome variable. Can solve for power, J, m or alpha.
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 )
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 )
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. |
In a multisite trial design, participants are randomized to conditions within site.
A list of the arguments (including the computed one).
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)
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)
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.
multisite.hte( m = NULL, alloc.ratio = 1, J = NULL, VR = NULL, alpha = 0.05, power = NULL, v = FALSE )
multisite.hte( m = NULL, alloc.ratio = 1, J = NULL, VR = NULL, alpha = 0.05, power = NULL, v = FALSE )
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. |
See Crespi CM (2025) for details.
A list of the arguments (including the computed power).
multisite.hte(m = 10, J = 30, VR = 8 / 36)
multisite.hte(m = 10, J = 30, VR = 8 / 36)
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.
prop.1samp( N = NULL, p0 = NULL, pA = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
prop.1samp( N = NULL, p0 = NULL, pA = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
prop.2samp( n1 = NULL, n.ratio = 1, p1 = NULL, p2 = NULL, margin = 0, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
prop.2samp( n1 = NULL, n.ratio = 1, p1 = NULL, p2 = NULL, margin = 0, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
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.
A list of the arguments (including the computed one).
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)
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)
Performs power and sample size calculation for McNemar test of two correlated proportions using normal approximation. Can solve for power, N or alpha.
prop.paired( N = NULL, p1 = NULL, p2 = NULL, phi = NULL, paid = NULL, dpr = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
prop.paired( N = NULL, p1 = NULL, p2 = NULL, phi = NULL, paid = NULL, dpr = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
Either p1, p2 and phi, OR paid and dpr must be specified.
A list of the arguments (including the computed one).
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)
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)
Performs power and sample size calculations for a test of equivalence for two proportions. Can solve for power, n1, n.ratio or alpha.
prop.test.equiv( n1 = NULL, n.ratio = 1, p1 = NULL, p2 = NULL, margin = NULL, alpha = 0.05, power = NULL, v = FALSE )
prop.test.equiv( n1 = NULL, n.ratio = 1, p1 = NULL, p2 = NULL, margin = NULL, alpha = 0.05, power = NULL, v = FALSE )
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. |
A list of the arguments (including the computed one).
prop.test.equiv(n1 = NULL, p1 = 0.5, p2 = 0.5, margin = 0.1, alpha = 0.05, power = 0.8)
prop.test.equiv(n1 = NULL, p1 = 0.5, p2 = 0.5, margin = 0.1, alpha = 0.05, power = 0.8)
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.
propodds(pC, OR, n1, n.ratio = 1, alpha = 0.05, power = NULL, v = FALSE)
propodds(pC, OR, n1, n.ratio = 1, alpha = 0.05, power = NULL, v = FALSE)
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. |
Whitehead J. (1993) Sample size calculations for ordered categorical data. Statistics in Medicine, 12(24):2257–2271
A list of the arguments (including the computed one).
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)
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)
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.
ranksum( n1 = NULL, n.ratio = 1, p = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
ranksum( n1 = NULL, n.ratio = 1, p = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
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.
A list of the arguments (including the computed one).
ranksum(n1 = 10, n.ratio = 1, p = 0.8, alpha = 0.05, power = NULL, sides = 2)
ranksum(n1 = 10, n.ratio = 1, p = 0.8, alpha = 0.05, power = NULL, sides = 2)
For a binary outcome, computes the relative efficiency (ratio of the variances) of a cluster randomized trial with varying cluster sizes to that of a cluster randomized trial with constant cluster sizes, assuming equal total number of subjects.
re.clustsize.bin(m, m.sd, pc, pt, sigma.u)
re.clustsize.bin(m, m.sd, pc, pt, sigma.u)
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. |
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.
The computed RE.
re.clustsize.bin(m = 60, m.sd = 45, pc = 0.25, pt = 0.15, sigma.u = 0.3)
re.clustsize.bin(m = 60, m.sd = 45, pc = 0.25, pt = 0.15, sigma.u = 0.3)
For a continuous outcome, computes the relative efficiency (ratio of the variances) of a cluster randomized trial with varying cluster sizes to that of a cluster randomized trial with constant cluster sizes, assuming equal total number of subjects.
re.clustsize.cont(m, m.sd, icc)
re.clustsize.cont(m, m.sd, icc)
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. |
The computed RE.
re.clustsize.cont(m = 25, m.sd = 15, icc = 0.05)
re.clustsize.cont(m = 25, m.sd = 15, icc = 0.05)
Performs power and sample size calculations for a test of relative risk, p2/p1. Can solve for power, N1, n.ratio or alpha.
relrisk( n1 = NULL, n.ratio = 1, p1 = NULL, p2 = NULL, RR0 = 1, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
relrisk( n1 = NULL, n.ratio = 1, p1 = NULL, p2 = NULL, RR0 = 1, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
A list of the arguments (including the computed one).
relrisk(n1 = NULL, n.ratio = 1/6, p1 = 0.1, p2 = 0.1 * 2, power = 0.8)
relrisk(n1 = NULL, n.ratio = 1/6, p1 = 0.1, p2 = 0.1 * 2, power = 0.8)
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.
signedrank( N = NULL, ps = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
signedrank( N = NULL, ps = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
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.
A list of the arguments (including the computed one).
signedrank(N = 20, ps = 0.87, power = NULL, sides = 2)
signedrank(N = 20, ps = 0.87, power = NULL, sides = 2)
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.
signtest(N = NULL, p = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE)
signtest(N = NULL, p = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE)
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. |
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.
A list of the arguments (including the computed one).
signtest(N = 40, p = 0.7, power = NULL, alpha = 0.05, sides = 1)
signtest(N = 40, p = 0.7, power = NULL, alpha = 0.05, sides = 1)
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.
slr( N = NULL, beta10 = 0, beta1A = NULL, var.x = NULL, sigma.e = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
slr( N = NULL, beta10 = 0, beta1A = NULL, var.x = NULL, sigma.e = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
A list of the arguments (including the computed one).
# Yi = beta0 + beta1 * Xi + ei, i = 1,...,N slr(N = 100, beta10 = 1, beta1A = 1.5, var.x = 25, sigma.e = 10, sides = 1)
# Yi = beta0 + beta1 * Xi + ei, i = 1,...,N slr(N = 100, beta10 = 1, beta1A = 1.5, var.x = 25, sigma.e = 10, sides = 1)
This function computes power and sample size for a one-sample t test. Can solve for power, N, delta, sd or alpha.
ttest.1samp( N = NULL, delta = NULL, sd = 1, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
ttest.1samp( N = NULL, delta = NULL, sd = 1, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
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 )
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 )
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. |
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.
A list of the arguments (including the computed one).
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)
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)
Performs power and sample size calculations for a paired t test. Can solve for power, N, delta or alpha.
ttest.paired( N = NULL, delta = NULL, sd1 = 1, sd2 = 1, rho = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
ttest.paired( N = NULL, delta = NULL, sd1 = 1, sd2 = 1, rho = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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 1. |
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. |
A list of the arguments (including the computed one).
ttest.paired(N = NULL, delta = 4, sd1 = 10, sd2 = 10, rho = 0.4, power = 0.8, sides = 2)
ttest.paired(N = NULL, delta = 4, sd1 = 10, sd2 = 10, rho = 0.4, power = 0.8, sides = 2)
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.
ztest.1samp( N = NULL, delta = NULL, sd = 1, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
ztest.1samp( N = NULL, delta = NULL, sd = 1, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
A list of the arguments (including the computed one).
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)
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)
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.
ztest.2samp( n1 = NULL, n.ratio = 1, delta = NULL, sd1 = 1, sd.ratio = 1, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
ztest.2samp( n1 = NULL, n.ratio = 1, delta = NULL, sd1 = 1, sd.ratio = 1, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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. |
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.
A list of the arguments (including the computed one).
ztest.2samp(n1 = NULL, n.ratio = 1, delta = 0.5, sd1 = 1, power = 0.8, sides = 2)
ztest.2samp(n1 = NULL, n.ratio = 1, delta = 0.5, sd1 = 1, power = 0.8, sides = 2)
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.
ztest.paired( N = NULL, delta = NULL, sd1 = 1, sd2 = 1, rho = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
ztest.paired( N = NULL, delta = NULL, sd1 = 1, sd2 = 1, rho = NULL, alpha = 0.05, power = NULL, sides = 2, v = FALSE )
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 1. |
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. |
A list of the arguments (including the computed one).
ztest.paired(N = NULL, delta = 4, sd1 = 10, sd2 = 10, rho = 0.4, power = 0.8, sides = 2)
ztest.paired(N = NULL, delta = 4, sd1 = 10, sd2 = 10, rho = 0.4, power = 0.8, sides = 2)