Solution (source code)

= Solution

Write $\bar X=n^{-1}\sum_iX_i$, $Q=\sum_i(X_i-\bar X)^2$, and $Q_0=\sum_i(X_i-\mu_0)^2=Q+n(\bar X-\mu_0)^2$. The normal <likelihood> is proportional to $(\sigma^2)^{-n/2}\exp[-\sum_i(X_i-\mu)^2/(2\sigma^2)]$. Its unrestricted maximizers are $\widehat\mu=\bar X$, $\widehat\sigma^2=Q/n$. Under the null the <variance> maximizer is $Q_0/n$. Substitution gives the <generalized likelihood-ratio test> statistic
$$
\Lambda=\left(\frac Q{Q_0}\right)^{n/2}
=\left(1+\frac{T^2}{n-1}\right)^{-n/2},\qquad
T=\frac{\sqrt n(\bar X-\mu_0)}S,\quad S^2=\frac Q{n-1}.
$$
The ratio decreases as $|T|$ increases, so the likelihood-ratio rejection region is two-sided in $T$. Under $H_0$, $\sqrt n(\bar X-\mu_0)/\sigma$ is standard normal and $Q/\sigma^2$ is independent chi-squared with $n-1$ degrees of freedom. Independence follows by resolving the isotropic Gaussian sample vector into its projection on the constant vector and its orthogonal complement. Hence $T$ has the exact <Student t-distribution> with $n-1$ degrees of freedom.

For a chosen <significance level> $\alpha$, compute the <sample mean> and the sample <standard deviation> with denominator $n-1$, and \b[reject precisely when]
$$
\boxed{|T|>t_{n-1,\,1-\alpha/2}.}
$$
Equivalently, report the two-sided $p$-value $2[1-F_{t_{n-1}}(|T|)]$. This requires $n\geq2$ and positive population <variance>; $S>0$ holds almost surely under that model. The nuisance <variance> is removed by the exact null distribution, so one should not substitute a normal critical value or a large-sample chi-squared approximation. This is the <normal-mean likelihood ratio with unknown variance>.