# Using neyman-pearson to reach a chi-square test for the variance of a population

In the Wikipedia page on the Neyman-Pearson Lemma, they discuss the example where there are $$n$$ iid Normal RVs with a known mean and a population variance that is the null hypothesis, and another that is the alternative hypothesis. They get the test statistic $$\Sigma (x_i - \mu)^2$$

They then jump to saying "we should reject $$H_0$$ if $$\Sigma (x_i - \mu)^2$$ is sufficiently large and that we can get the critical value by scaling the test-statistic to become a chi-square distribution, they never explain why.

Various sites online explain that basically converting the test statistic to become the sample variance over the population variance will turn the formula into a chi-square distribution. They do it as follows:

$$\chi^2_{n-1} = \frac{(n-1)\frac{\Sigma (x_i - \mu)^2}{n-1}}{\sigma_0^2}$$

$$\chi^2_{n-1} = \frac{(n-1)s^2}{\sigma_0^2}$$

But then I am confused as to how this would relate to a significance value $$\alpha$$. Like if it is $$\alpha = 0.05$$, how does this translate back into our original problem of "debunking/rejecting the null hypothesis"

Not looking for the answer, I just want some help explaining why the test statistic is the way it is.

Neyman-Pearson says reject for $$Q = \sum_i (X_i - \mu)^2 > c,$$ with $$c$$ chosen so that $$P(Q > c) = \alpha$$ under $$H_0.$$ Then the problem is to find the numerical value of $$c.$$

Under $$H_0,$$ we have that $$Z_i = (X_i - \mu)/\sigma_0$$ is standard normal so that $$Z_i^2\sim \mathsf{Chisq}(1).$$ Thus $$Q/\sigma_0^2 \sim\mathsf{Chisq}(n).$$ We can use printed chi-squared tables or software to find the number $$b$$ with $$P(Q/\sigma_0^2 > b) = \alpha.$$ What is $$c$$ in terms of $$b?$$

Addendum: Below we simulate a million samples, each with $$n = 5$$ observations from $$\mathsf{Norm}(100, 15).$$

In the histogram at left we show that a histogram of simulated values of $$(n-1)S^2/\sigma^2$$ (called dist.1) fits $$\mathsf{Chisq(4)}$$ (solid curve), but not $$\mathsf{Chisq(5)},$$ as mentioned in a Comment. Informally, one says that one degree of freedom has been 'lost' estimating unknown $$\mu.$$

By contrast, the histogram at right illustrates that simulated values of $$nQ/\sigma^2$$ (called 'dist2) do fit $$\mathsf{Chisq}(5),$$ as in the discussion above.

R code for the simulation is shown below (but not the code to make the histograms).

set.seed(409)  # for reproducibility
m = 10^6;  n = 5;  mu = 100;  sg = 15
x = rnorm(m *n, mu, sg);  MAT = matrix(x, nrow=m)
s.sq = apply(MAT, 1, var)
dist.1 = (n-1)*s.sq/sg^2 col="brown", lwd=2, lty="dotted")
q = rowSums((MAT - mu)^2)
dist.2 = q/sg^2
`
• If I understand you correctly, stating that $P(Q / \sigma_0^2 > b)$ would mean that $c=\frac{b}{\sigma_0^2}$, and that $Q/\sigma_0^2 = \chi_n^2$ but then why do the websites convert our Q into the sample standard deviation and have $\chi_{n-1}^2 = \frac{(n-1)\frac{Q}{(n-1)}}{\sigma_0^2}$ ? Apr 8, 2019 at 21:20
• Your 1st sentence fragment is OK. Addressing the rest: When $\mu$ is known [as I surmised from your $\sum_i (X_I - \mu)^2],$ you have $Q/\sigma_0^2 \sim \mathsf{Chisq}(n).$ When $\mu$ is unknown and estimated by $\bar X,$ then $(n-1)S^2/\sigma_0^2 \sim \mathsf{Chisq}(n-1),$ which is somewhat more difficult to prove. // Just as inference on $\mu$ uses either z or t test depending on whether $\sigma$ is known or not, respectively; inference on $\sigma$ is slightly different depending on whether $\mu$ is known or not. Apr 8, 2019 at 22:35
• So $\mu$ is known, you are correct. Second, if it is not known, is it ok to use the estimator? I've studied estimators, and I know why the formula works, I guess my question is: "is it fine to use an estimator for hypothesis testing"? and why would that work, intuitively? Apr 8, 2019 at 22:40
• If $\mu$ known ok to use $Q$ as discussed in my Answ. If $\mu$ not known must use $S^2$ as discussed in my previous Comment. Two separate situations. Don't mix them. Apr 8, 2019 at 22:43
• The dist'n of $(n-1)S^2/\sigma^2$ is not trivial to derive, but it is easy to simulate; see Addendum. Apr 10, 2019 at 1:50