Simulation Assignment 1: Sequential CI
Goal: Use simulation to show the asymptotic normality and coverage validity of the purely sequential confidence interval at \(\alpha = 0.05\) and margin of error \(d=0.5\).
Step 1: Generate a pilot sample of size \(n_0=5\) from \(N(0,1)\) distribution.
Step 2: Check with the stopping rule to see if
\[
n\geq \frac{z_{\alpha/2}^2 S_n^2}{d^2}
\] where \(z_{\alpha/2} =\) qnorm(0.025), \(S_n^2\) is the variance of the pilot sample, \(d=0.5\) is the predefined maximum margin of error.
Equivalently, you can compute the width of the confidence interval using the pilot sample, and compare it with the margin of error \(d\). Please note interval width is \(2d\) when margin of error is \(d\).
Step 3: Stop sampling once the stopping condition is met. Otherwise, take one more data from $N(0,1) and repeat step 2.
Step 4: Record the confidence interval width and compare it with the pre-specified margin of error for this iteration.
Step 5: Repeat Step 1 to Step 4 at least 1000 times. Compute the coverage probability as the proportion of intervals that contain the true parameter value. (\(\mu=0\)). Compare this proportion with your pre-defined confidence level (say 0.95.)
(Better to have) Step 6: Record the stopping sample size and sequential estimation \(\bar{X}_N\) in each iteration. Is \(N\) close to the theoretical optimal fixed sample size \(n^*=\left( \frac{z_{\alpha/2}^2 \sigma^2}{d^2}\right)^2\)? Is \(\bar{X}_N\) still approximately a normal distribution?