# Pwr.chisq.test error in R

I am now trying to estimate the sample size needed to test the conversion rate of a website. pwr.chisq.test always gives me an error message when I have a low conversion rate:

```
# conversion rate for two groups
p1 = 0.001
p2 = 0.0011
# degree of freedom
df = 1
# effect size
w = ES.w1(p1,p2)
pwr.chisq.test(w,
df = 1,
power=0.8,
sig.level=0.05)
**Error in uniroot(function(N) eval(p.body) - power, c(1 + 1e-10, 1e+05)) :
f() values at end points not of opposite sign**
```

However, if I have a larger value for p1 and p2, this code works fine.

```
# conversion rate for two groups
p1 = 0.01
p2 = 0.011
# degree of freedom
df = 1
# effect size
w = ES.w1(p1,p2)
pwr.chisq.test(w,
df = 1,
power=0.8,
sig.level=0.05)
```

Calculating squared energy squared

`w = 0.01 N = 78488.61 df = 1 sig.level = 0.05 power = 0.8`

NOTE: N - number of observations

source to share

I think there is a "numerical" explanation for this. If you look at the code of the function, you can see that the number of samples is calculated using `uniroot`

and must belong to the interval whose boundaries are set to `1e-10`

and `1e5`

. The error message states that this interval does not give you a result: in your case, the upper limit is too small.

Knowing that we can just take a wider interval:

```
w <- 0.00316227766016838
k <- qchisq(0.05, df = 1, lower = FALSE)
p.body <- quote(pchisq(k, df = 1, ncp = N * w^2, lower = FALSE))
N <- uniroot(function(N) eval(p.body) - 0.8, c(1 + 1e-10, 1e+7))$root
```

The "solution" `N=784886.1`

... that's a **huge** number of observations.

source to share