As you yourself write, the maximized likelihood given the sample is
$$L(\hat{\sigma}^{2} \mid \mathbf x) = \left(\frac{1}{\sqrt{2\pi\hat{\sigma}^{2}}}\right)^{n}\cdot e^-\frac{\sum_{i=1}^{n} (x_i - \mu)^2}{2\hat{\sigma}^{2}}$$
and you have that
$$\hat{\sigma}^{2}=\frac{\sum_{i=1}^{n} (x_i - \mu)^2}{n}$$
Inserting this into the likelihood we get
$$L(\hat{\sigma}^{2} \mid \mathbf x) = \left(\frac{1}{\sqrt{2\pi\hat{\sigma}^{2}}}\right)^{n}\cdot e^{-(n/2)} $$
Then the Likelihood Ratio is
$$\Lambda = \frac{ \left(\frac{1}{\sqrt{2\pi\sigma_0^2}}\right)^{n/2}\cdot e^{-\frac{\sum_{i=1}^n (X_i - \mu)^2}{2\sigma_0^2}}} {\left(\frac{1}{\sqrt{2\pi\hat{\sigma}^{2}}}\right)^{n}\cdot e^{-(n/2)}} = \left(\frac {\hat{\sigma}^2}{\sigma_0^2}\right)^{n/2} \cdot \exp\left \{-\frac 12\left(\frac{\sum_{i=1}^n (X_i - \mu)^2}{\sigma_0^2}-n\right)\right\}$$
and using again the expression for $\hat \sigma^2$ we get
$$\Lambda = \left(\frac {\hat{\sigma}^2}{\sigma_0^2}\right)^{n/2} \cdot \exp\left \{-\frac n2\left(\frac {\hat{\sigma}^2}{\sigma_0^2}-1\right)\right\}$$
Now, under the null, the random variable denoted
$$z_i^2 = \left(\frac {x_i - \mu}{\sigma_0}\right)^2 \sim \chi^2(1)$$
We have
$$ \frac {\hat{\sigma}^2}{\sigma_0^2} = \frac 1n\sum_{i=1}^{n} \left(\frac {x_i - \mu}{\sigma_0}\right)^2 = \frac 1n \sum_{i=1}^{n}z_i^2$$
So we can write
$$\Lambda = \left(\frac 1n \sum_{i=1}^{n}z_i^2 \right)^{n/2} \cdot \exp\left \{-\frac n2\left( \frac 1n \sum_{i=1}^{n}z_i^2-1\right)\right\}$$
Taking minus log we have
$$-\ln \Lambda = -\frac n2 \ln \left(\frac 1n \sum_{i=1}^{n}z_i^2 \right) +\frac n2\left( \frac 1n \sum_{i=1}^{n}z_i^2-1\right)$$
Manipulating the second term in the RHS,
$$= -\frac n2 \ln \left(\frac 1n \sum_{i=1}^{n}z_i^2 \right) + \sqrt {\frac n 2} \left( \frac {\sum_{i=1}^{n}(z_i^2-1)}{\sqrt {2n}}\right)$$
and multiplying throughout by $\sqrt {\frac 2n}$ we obtain
$$-\sqrt {\frac 2n} \ln \Lambda = -\sqrt {\frac n 2} \ln \left(\frac 1n \sum_{i=1}^{n}z_i^2 \right) + \left( \frac {\sum_{i=1}^{n}(z_i^2-1)}{\sqrt {2n}}\right)$$
The second term in the RHS is a standardized sum of i.i.d $\chi^2(1)$ random variables, each having mean equal to $1$, variance equal to $2$, and so the standard deviation of the sum is $\sqrt {2n}$. This quantity will converge to a $N(0,1)$.
Then (abusing notation a bit),
$$\operatorname{plim}\left(-\sqrt {\frac 2n} \ln \Lambda\right) = \operatorname{plim}\left(-\sqrt {\frac n 2} \right)\cdot \operatorname{plim}\left[\ln \left(\frac 1n \sum_{i=1}^{n}z_i^2 \right)\right] + \operatorname{plim}\left( \frac {\sum_{i=1}^{n}(z_i^2-1)}{\sqrt {2n}}\right) $$
$$= \infty \cdot \left[\ln \left(\operatorname{plim}\frac 1n \sum_{i=1}^{n}z_i^2 \right)\right] + N(0,1)=\infty \cdot \ln (1) + N(0,1) = 0 + N(0,1)$$
(accepting $\infty \cdot 0 =0$)
which means that the quantity
$$Q = -\sqrt {\frac 2n} \ln \Lambda \rightarrow_d N(0,1)$$
if the null hypothesis is true. For a finite sample this quantity is calculated as
$$\hat Q(\hat\sigma^2,\sigma_0^2,n) = \sqrt {\frac n2}\left[\frac {\hat{\sigma}^2}{\sigma_0^2}-1-\ln \left(\frac {\hat{\sigma}^2}{\sigma_0^2}\right)\right]$$
Option A)\begin{align} \bar{x}-0.588&=-0.488\implies \bar{x}=0.1 \\ \bar{x}+0.588&=0.688\implies \bar{x}=0.1 \end{align}
So if the sample mean $\bar{x}$ was $0.1$ the 95% confidence interval for the population mean $\mu$ would be $(-0.488\le \mu \le0.688)$. $0$ is contained within the confidence interval so this is correct.
Option B)\begin{align} \bar{x}-0.588&=-1.96\implies \bar{x}=-1.372 \\ \bar{x}+0.588&=1.96\implies \bar{x}=1.372 \end{align}
So the sample mean $\bar{x}$ is not consistent for both sides of the confidence interval as it should be. This option is incorrect.
Option C)\begin{align} \bar{x}-0.588&=0.422\implies \bar{x}=1.01 \\ \bar{x}+0.588&=1.598\implies \bar{x}=1.01\end{align}So if the sample mean $\bar{x}$ was $1.01$ the 95% confidence interval for the population mean $\mu$ would be $(0.422\le \mu \le1.598)$. $0$ is not contained within the confidence interval so this is rejected.
Option D)\begin{align} \bar{x}-0.588&=0.588\implies \bar{x}=1.176 \\ \bar{x}+0.588&=1.96\implies \bar{x}=1.372 \end{align}
So the sample mean $\bar{x}$ is not consistent for both sides of the confidence interval as it should be. This option is incorrect.
Best Answer
So what you doing is basically a Monte Carlo Estimate of a specific quantile $\delta_{\alpha ,n}$ so that, $P(\delta >\delta_{\alpha ,n}|H_0)=\alpha.$
Your method would be like this:
Your code is almost okay, you have to finally calculate
sort(D)[length(D)*alpha]
. Also, take a much larger value of $N$ than just 25.So, finally, in
R
, your program would be (taking a larger value of N, not 25):I have commented on some parts of your codes and compacted them.