Description Usage Arguments Details Value Warning Note Author(s) References See Also Examples
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.
1 2 3 4 5 6 7 8 9 | 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)
|
p0 |
true event rate in control group |
p1 |
true event rate in treatment group |
n0 |
number of observations in control group |
n1 |
number of observations in treatment group (if NULL n1=n0) |
sig.level |
significance level (Type I error probability) |
power |
minimum power for sample size calculation |
n1.over.n0 |
ratio of n1 over n0, allows for non-equal sample size allocation |
alternative |
character, either "two.sided" or "one.sided", one sided tests the proper direction according to p0 and p1 |
strict |
use strict interpretation of two-sided test, if TRUE counts rejections in wrong direction |
tsmethod |
two.sided method, ignored if strict=FALSE, or alternative equals 'less' or 'greater'.
see |
nullOddsRatio |
null odds ratio value for tests |
paired |
logical. TRUE gives power for McNemar's test, FALSE are all other tests (see warning) |
print.steps |
logical, print steps for calculation of sample size? |
errbound |
bound on error of calculation |
approx |
give sample size or power using normal approximation only |
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.
Both power2x2
and ss2x2
return an object of class 'power.htest'. A list with elements
power |
power to reject |
n0 |
sample size in control group |
n1 |
sample size in treatment group |
p0 |
true event rate in control group |
p1 |
true event rate in treatment group |
sig.level |
Significance level (Type I error probability) |
alternative |
alternative hypothesis |
note |
note about error bound |
method |
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.
The calculations in ss2x2 can be slow when p0 is close to p1 and/or the power is large. If p0 and p1 are close with large power, it may be safer to first calculate ss2x2 with approx=TRUE to see what the starting value will be close to. If the starting sample sizes are large (>100), it may take a while.
Note when strict=FALSE (default), the two.sided results at the 0.05 level for Fisher's exact test are like the one.sided Fisher's exact test at the 0.025 level.
Michael P. Fay
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
1 2 3 4 |
Loading required package: exactci
Loading required package: ssanv
Power for Fisher's Exact Test
power = 0.8475728
n0 = 12
n1 = 15
p0 = 0.2
p1 = 0.8
sig.level = 0.05
alternative = two.sided
nullOddsRatio = 1
NOTE: errbound= 1e-06
Approximate Power for Fisher's Exact Test
power = 0.8
p0 = 0.2
p1 = 0.8
n0 = 9.340086
n1 = 18.68017
sig.level = 0.05
alternative = two.sided
strict = FALSE
tsmethod = NULL
nullOddsRatio = 1
NOTE: errbound= 1e-06
[1] "starting calculation at n0= 8 n1= 16"
[1] "n0=8 n1=16 power=0.704214110731463"
[1] "n0=16 n1=32 power=0.9781897271243"
[1] "n0=12 n1=24 power=0.921321775957463"
[1] "n0=10 n1=20 power=0.850961443071942"
[1] "n0=9 n1=18 power=0.799603779627725"
Power for Fisher's Exact Test
power = 0.8509614
n0 = 10
n1 = 20
p0 = 0.2
p1 = 0.8
sig.level = 0.05
alternative = two.sided
nullOddsRatio = 1
NOTE: errbound= 1e-06
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.