normal.sample.size(mean2, mean.alt, mean=0, sd1=1, sd2=sd1, power=0.8, alpha=0.05, n1=NULL, n2=NULL, prop.n2=1, one.sample=missing(sd2), alternative="two.sided", expand.args=T, exact.n=F, recompute.power=F)
TRUE
, the input arguments will be expanded to build a cross-product table. If
FALSE
, it is assumed the input is matched, and will only be replicated to the
length of the longest vector. Default is
TRUE
.
TRUE
, the computed sample size will not be rounded up. Default is
FALSE
.
TRUE
, after the sample size is computed, the power will be recomputed. This is
only advantageous when the sample size is rounded up. Default is
FALSE
.
data.frame
containing the power, sample size and all of the input which was used
to perform the computations.
This function can be used to calculate sample size, power or minimum detectable
difference. It determines what to compute base on the arguments provided. If
mean.alt
or
mean2
is given, but
n1
is not, then sample size is computed. If
mean.alt
or
mean2
is given along with
n1
, then the power is computed. If only
n1
is provided, the minimum detectable difference is computed using the default
power of 0.80.
The formulas used for computing sample size are:
One Sample:
For a one-sample T-test where
Ho: mu = mean Ha: mu = mean.alt Pr(reject Ho | Ho is true) = alpha Pr(reject Ho | Ha is true) = powerSample size required to detect
delta = abs(mean.alt - mean)
:
Z.a = qnorm(1 - alpha/2) {2 sided} Z.a = qnorm(1 - alpha) {1 sided} Z.p = qnorm(power) n1 = { sd1 * (Z.a + Z.p) / delta }^2
Ho: mean2 - mean = 0 Ha: mean2 - mean != 0 n2 = prop.n2 * n1 Pr(reject Ho | Ho is true) = alpha Pr(reject Ho | Ha is true) = powerSample size required to detect
delta = abs(mean2 - mean)
:
Z.a = qnorm(1 - alpha/2) {2 sided} Z.a = qnorm(1 - alpha) {1 sided} Z.p = qnorm(power) n = { sd1 * (Z.a + Z.p) / delta }^2 n1 = n * (1 + (sd2^2 / prop.n2 * sd1^2)) n2 = prop.n2 * n1
Rosner, Bernard (1990). Fundamentals of Biostatistics (Third Edition). PWS-Kent, Boston. Fisher, Lloyd D. and Van Belle, Gerald (1993). Biostatistics. Wiley, New York.
normal.sample.size(mean.alt = 0.3) # one-sample normal.sample.size(mean2 = 0.3) # two-sample normal.sample.size(mean2 = 0.3, recompute = T) normal.sample.size(mean2 = 0.3, exact.n = T) normal.sample.size(mean2 = 0.3, alt = "greater") normal.sample.size(mean = 100, mean.alt = 94, sd1 = 15, power = 0.9, alt = "less") normal.sample.size(mean=120, mean.alt=c(115, 110), sd1=c(sqrt(625), 30), alpha = c(0.05, 0.01), power = c(0.8,0.9), alt="l") normal.sample.size(mean=120, mean.alt=c(115, 110), sd1=c(sqrt(625), 30), alpha = c(0.05, 0.01), power = c(0.8,0.9), expand=F)