Power is calculated by power2x2
which calls exact2x2
function repeatedly. Default (strict=FALSE) does not count rejections in the wrong direction.
Sample size is calculated by ss2x2
which calls power2x2
repeatedly finding the lowest sample size that has at least the nominal power, using the uniroot.integer
function from the ssanv
package.
power2x2(p0,p1,n0,n1=NULL,sig.level=0.05,
alternative=c("two.sided","one.sided"),paired=FALSE,
strict=FALSE,tsmethod=NULL,nullOddsRatio=1,
errbound=10^-6,approx=FALSE)ss2x2(p0,p1,power=.80,n1.over.n0=1,sig.level=0.05,
alternative=c("two.sided","one.sided"),paired=FALSE,
strict=FALSE,tsmethod=NULL,nullOddsRatio=1,
errbound=10^-6,print.steps=FALSE, approx=FALSE)
true event rate in control group
true event rate in treatment group
number of observations in control group
number of observations in treatment group (if NULL n1=n0)
significance level (Type I error probability)
minimum power for sample size calculation
ratio of n1 over n0, allows for non-equal sample size allocation
character, either "two.sided" or "one.sided", one sided tests the proper direction according to p0 and p1
use strict interpretation of two-sided test, if TRUE counts rejections in wrong direction
two.sided method, ignored if strict=FALSE, or alternative equals 'less' or 'greater'.
see exact2x2
for details.
null odds ratio value for tests
logical. TRUE gives power for McNemar's test, FALSE are all other tests (see warning)
logical, print steps for calculation of sample size?
bound on error of calculation
give sample size or power using normal approximation only
Both power2x2
and ss2x2
return an object of class 'power.htest'. A list with elements
power to reject
sample size in control group
sample size in treatment group
true event rate in control group
true event rate in treatment group
Significance level (Type I error probability)
alternative hypothesis
note about error bound
description
There may be convergence issues using strict=FALSE with tsmethod="minlike" or "blaker" since the power is not guaranteed to be increasing in the sample size.
When paired=TRUE the model for the power calculation is fairly restrictive. It assumes that there is no correlation between the two groups. A better power function is probably needed for this case.
Assuming X0 ~ Binomial(n0,p0) and X1 ~ Binomial(n1,p1), calculates the power by repeatedly calling exact2x2 and summing probability of rejection. For speed, the function does not calculate the very unlikely values of X0 and X1 unless errbound=0. Power is exact, but may underestimate by at most errbound.
When strict=FALSE we do not count rejections in the wrong direction. This means that we must know the direction of the rejection, so two.sided tests are calculated as one.sided tests (in the correct direction) with level equal to sig.level/2. This is like using the tsmethod='central'.
When approx
=TRUE for power2x2
use a continuity corrected normal approximation (Fleiss, 1981, p. 44). For ss2x2
the calculations may be slow, so use
print.steps=TRUE
to see progress.
Fleiss. JL (1981) Statistical Methods for Rates and Proportions (second edition). Wiley.
See ss.nonadh
function (refinement="Fisher.exact") from the ssanv
package for calculation that accounts for nonadherence in proportion of subjects. That function calls fisher.test
# NOT RUN {
power2x2(.2,.8,12,15)
# calculate sample size with 2:1 allocation to groups
ss2x2(.2,.8,n1.over.n0=2,power=.8,approx=TRUE)
ss2x2(.2,.8,n1.over.n0=2,power=.8,print.steps=TRUE)
# }
Run the code above in your browser using DataLab