0

When I tried to run a power.prop.test to perform a power analysis for an A/B testing, it performed well. However, when I tried to draw a plot of sample size needed for a series of "power", I did a for loop, them the console gave me this error.

 p2 <- seq(.1511, .188875, .007555)
 np2 <- length(p2)
 power <- seq(.4, .9, .1)
 npower <- length(power)
 samsize <- array(numeric(np2*npower), dim = c(np2,npower))
 for (i in 1:npower){
   for (j in 1:np2){
     result <- power.prop.test(n = NULL, p1 =.1511, p2 = p2[j], 
                               sig.level = .05, power = power[i],
                               alternative = c("two.sided","one.sided"),
                               strict = FALSE, tol = .Machine$double.eps^.25)
     samsize[j,i] <- ceiling(result$n)
   }
 }

Error in uniroot(function(n) eval(p.body) - power, c(1, 1e+07), tol = tol, : no sign change found in 1000 iterations

#Error message Error in uniroot(function(n) eval(p.body) - power, c(1, 1e+07), tol = tol, : no sign change found in 1000 iterations

I'm wondering how to fix it.

Arun kumar mahesh
  • 2,289
  • 2
  • 14
  • 22
clause_yl
  • 21
  • 4

1 Answers1

1

I suspect it's got something to do with the fact that p2[1] = p1. That implies an infinite sample size.

As an aside: when you have problems in a loop like this, it's very useful to know on which iteration of the loop the problem occurs. Next time, put some print statements at relevant points to ascertain the status of the loop when the error occurs.

Limey
  • 10,234
  • 2
  • 12
  • 32