R: Calculate exact power or sample size for conditional tests...

power2x2 {exact2x2} | R Documentation

## Calculate exact power or sample size for conditional tests 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

### 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`

### Value

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

### 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.

### Note

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.

### Author(s)

Michael P. Fay

### 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

    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)

[Package exact2x2 version 1.6.3 Index]