Likelihood-ratio test for a normal variance (source code)

= Likelihood-ratio test for a normal variance
{title2=$W=q-n-n\log(q/n),\quad Q\sim\chi_{n-1}^2$}

For an independent <normal distribution> sample with unknown mean, test $\sigma^2=\sigma_0^2$ against unrestricted positive variance. Put $q=\sum_i(x_i-\bar x)^2/\sigma_0^2$ and assume $n\geq2$. Profiling the mean and variance gives the <likelihood ratio> $\lambda(q)=(q/n)^{n/2}e^{(n-q)/2}$ for a nondegenerate sample. Its logarithmic derivative $\tfrac12(n/q-1)$ changes sign at $n$, so small ratios select a lower and an upper tail.

Under the <null hypothesis>, <Cochran's theorem> gives $Q\sim\chi_{n-1}^2$. The exact size-$\alpha$ cutoffs $0<q_1<n<q_2$ therefore satisfy
$$
F_{n-1}(q_1)+1-F_{n-1}(q_2)=\alpha,\qquad n\log(q_2/q_1)=q_2-q_1.
$$
The second equation makes the two boundary ratios equal. Rejection on $q\leq q_1$ or $q\geq q_2$ is consequently the exact <likelihood-ratio test>, and its tails need not have equal probability. For a large sample, the <Wilks theorem> instead calibrates $W=-2\log\lambda$ by $\chi_1^2$. A <Bartlett correction for a normal variance with unknown mean> improves this asymptotic calibration; it is unnecessary when using the exact $Q$ distribution.