binomial.sample.size(p2, p.alt, p=0.5, power=0.8, alpha=0.05, n1=NULL, n2=NULL, prop.n2=1, one.sample=F, alternative="two.sided", expand.args=T, exact.n=F, recompute.power=F, correct=T)
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
.
TRUE
(default), a continuity correction will be used.
data.frame
containg 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
p.alt
or
p2
is given, but
n1
is not, then sample size is computed.
If
p.alt
or
p2
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 test of proportion where
Ho: pi = p Ha: pi = p.alt Pr(reject Ho | Ho is true) = alpha Pr(reject Ho | Ha is true) = powerSample size required to detect
delta = abs(p.alt - p)
:
Z.a = qnorm(1 - alpha/2) {2 sided} Z.a = qnorm(1 - alpha) {1 sided} Z.p = qnorm(power) sd.null = sqrt( p*(1 - p) ) sd.alt = sqrt( p.alt*(1 - p.alt) ) n1 = { (sd.null * Z.a + sd.alt * Z.p) / delta }^2 n1 = n1 + 2 / delta {continuity cor}
Ho: p2 - p = 0 Ha: p2 - p != 0 Pr(reject Ho | Ho is true) = alpha Pr(reject Ho | Ha is true) = powerSample size required to detect
delta = abs(p2 - p)
:
Z.a = qnorm(1 - alpha/2) {2 sided} Z.a = qnorm(1 - alpha) {1 sided} Z.p = qnorm(power) p.pool = (n1*p + n2*p2) / (n1 + n2) = (p + prop.n2*p2) / (1 + prop.n2) sd.null = sqrt( p.pool*(1 - p.pool) * (1 + 1/prop.n2) ) sd.alt = sqrt( p*(1 - p) + p2*(1 - p2)/ prop.n2 ) n1 = { (sd.null * Z.a + sd.alt * Z.p) / delta }^2 n1 = n1 + (prop.n2 + 1) / (prop.n2 * delta) {continuity cor} n2 = prop.n2 * n1
Fleiss, Joseph L. (1981). Statistical Methods for Rates and Proportions. Wiley, New York. Rosner, Bernard (1990). Fundamentals of Biostatistics (Third Edition). PWS-Kent, Boston.
binomial.sample.size(p.alt = c(.6, .7, .8)) binomial.sample.size(p2 = .7, n1 = 100) binomial.sample.size(p = 0.02, p.alt = 0.05, n1 = 500) binomial.sample.size(p = .7, p2 = .85) binomial.sample.size(p = .7, p2 = .85, correct = F) binomial.sample.size(p = .7, p2 = .85, recompute = T) binomial.sample.size(p = .7, p2 = .85, n1 = 100, prop.n2 = 2) binomial.sample.size(p.alt = 0.6, n1 = c(50, 100, 200, 300), alpha = c(.01, .05, .1)) binomial.sample.size(p2 = 0.6, n1 = c(50,100,200,400,800), alpha = c(.01, .05, .1)) binomial.sample.size(p = .25, p2 = .4, alpha = c(.01, 0.02), power = c(0.95, .90)) binomial.sample.size(p = .25, p2 = .4, alpha = c(.01, 0.02), power = c(0.95, .90), expand = F) binomial.sample.size(p = 0.25, p2 = .40, alpha = 0.01, power = 0.95, prop.n2 = c(5:10) / 10)