uncondPower2x2: Calculate power or sample size for any 2x2 test.

Description Usage Arguments Details Value See Also Examples

View source: R/uncondPower2x2.R

Description

The function Power2x2 and SS2x2 calculates the power or sample size for any 2x2 test, while the function uncondPower2x2 calculates power for only tests supported by uncondExact2x2Pvals.

Usage

1
2
3
4
5
6
7
Power2x2(n1, n2, theta1, theta2, alpha, pvalFunc, ...)

uncondPower2x2(n1,n2, theta1, theta2, alpha, ...)

SS2x2(theta1, theta2, alpha, pvalFunc, power=0.90, 
  n1start=10, increaseby=1, n2.over.n1=1,  
  maxiter=50, printSteps=TRUE, ...)

Arguments

n1

sample size in group 1

n2

sample size in group 2

theta1

probability of success in group 1

theta2

probability of success in group 2

alpha

significance level

pvalFunc

function that inputs x1,n1,x2,n2 and outputs a p-value.

power

target power

n1start

value of n1 for first iteration

increaseby

positive integer, how much to increase n1 by for each iteration

n2.over.n1

ratio of n2/n1

maxiter

maximum number of iterations

printSteps

logical, should the power and sample size be printed after each iteration?

...

arguments passed to uncondExact2x2Pvals (for uncondPower2x2), or to Power2x2 (for SS2x2). Not used and saved for future use for Power2x2.

Details

The function Power2x2 is a very simple function to calculate power. It calculates power where rejection is when the p-value from pvalFunc is less than or equal to alpha. The function SS2x2 repeatedly calls Power2x2 as it increases the sample size, stopping when the power is greater than 'power'.

The function uncondPower2x2 is similar except the p-values are calculated by uncondExact2x2Pvals.

Value

the power functions return only the power. The sample size function returns a list of class 'htest.power'.

See Also

For power and sample size for conditional exact tests (e.g., Fisher's exact tests) see power2x2 and ss2x2. For power for the boundary-optimized rejection region (BORR) test see powerBorr.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(exact2x2)
Power2x2(3,4,.1,.9,0.025, pvalFunc=
  function(x1,n1,x2,n2){
      boschloo(x1,n1,x2,n2, alternative="greater", 
        or=1,tsmethod="central", midp=TRUE)$p.value
  }
)
## 
## Not run: 
SS2x2(.1,.9,0.025, n1start=5, pvalFunc=
           function(x1,n1,x2,n2){
             boschloo(x1,n1,x2,n2, alternative="greater", 
                      or=1,tsmethod="central", midp=TRUE)$p.value
           }
)

## End(Not run)

Example output

Loading required package: exactci
Loading required package: ssanv
[1] 0.6908733
n1=5n2=5power=0.8221923711
n1=6n2=6power=0.904626841815

     rejection determined by pvalFunc 

          power = 0.9046268
         theta1 = 0.1
         theta2 = 0.9
             n1 = 6
             n2 = 6
      sig.level = 0.025

exact2x2 documentation built on Dec. 11, 2021, 9:43 a.m.