Small sample size error using power calculation for two proportions

334 views Asked by At

I am trying to use power analysis for sample size selection using the pwr library in R.

library(pwr)
pwr.2p2n.test(h = 0.1, n1 = 78, power = 0.8, sig.level = 0.0125)

I get the following error:

Error in uniroot(function(n2) eval(p.body) - power, c(2 + 1e-10, 1e+09)) : f() values at end points not of opposite sign

If I change the sample size (greater) or change the effect size to medium (0.4) then it'll run. Any solutions would be wonderful, thank you.

1

There are 1 answers

1
Ben Bolker On BEST ANSWER

I don't think it's possible to achieve 0.8 power with any sample size in the second group (no matter how large), with your other constraints, e.g.

library(pwr)
pfun <- function(n2) {
    pwr.2p2n.test(h = 0.1, n1 = 78, n2 = n2, sig.level = 0.0125)$power
}
pfun2 <- Vectorize(pfun)

png("ppow.png")
curve(pfun2(x), from = 100, to = 1e9, log="x")
dev.off()

power curve saturating at 0.053

I've "only" tried sample sizes up to 10^9, but it seems that no matter how large you make n2, you can't get power > 0.054 or so with this setup. So this isn't a computational problem, it's a structural/statistical one.