Learn R Programming

exact2x2 (version 1.4.0)

power2x2: Calculate exact power or sample size for two independent binomials.

Description

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.

Usage

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)

Arguments

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 exact2x2 for details.
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

Value

  • Both power2x2 and ss2x2 return an object of class 'power.htest'. A list with elements
  • powerpower to reject
  • n0sample size in control group
  • n1sample size in treatment group
  • p0true event rate in control group
  • p1true event rate in treatment group
  • sig.levelSignificance level (Type I error probability)
  • alternativealternative hypothesis
  • notenote about error bound
  • methoddescription

Warning

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.

Details

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

See Also

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

Examples

Run this code
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