1

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.

Kreitz Gigs
  • 369
  • 1
  • 9

1 Answers1

2

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.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Thanks Ben, I just came to same conclusion after iteratively changing the two sample sizes and seeing how high power would increase and had the same findings with pwr and the function "wp.prop" from package "WebPower". – Kreitz Gigs Aug 16 '21 at 22:03