Code
qnorm(0.975)[1] 1.959964
The confidence interval usually has the following format:
\[ \text{Estimate} \pm \text{Margin of Error} \]
For example, to get the \(1-\alpha\) confidence interval of the normal population mean, we can start with an i.i.d random sample. Suppose \(X_1, X_2, ..., X_n \sim N(\mu, \sigma^2)\) , the sample mean has the following distribution:
\[ \bar{X}_n \sim N(\mu, \frac{\sigma^2}{n}) \]
Assume \(\sigma^2=1\), we can create a \(Z\) statistic from it:
\[ Z=\frac{\sqrt{n}(\bar{X}_n-\mu)}{1} \sim N(0,1) \]
In a standard normal distribution, we can find two critical values such that
\[ P(-z_{\alpha/2} \leq Z \leq z_{\alpha/2})=1-\alpha \]
For example, to find the critical value for a 95% confidence interval (\(1-\alpha = 0.95\)), use the qnorm() function which returns the quantile(i.e., percentile or critical value) of a standard normal distribution.
So \(z_{0.025}\approx 1.96\). We have
\[ P(-1.96 \leq \frac{\sqrt{n}(\bar{X}_n-\mu)}{1} \leq 1.96) = 0.95 \]
With a calculated sample mean \(\bar{X}\) , the confidence interval for \(\mu\) is
\[ \bar{X}_n \pm 1.96 \frac{1}{\sqrt{n}} \]
Q1: What does “margin of error” mean in this context?
Q2: As the sample size \(n\) increases, how does the margin of error change?
Q3: If we require the interval width to be at most 0.2, what is the minimum sample size \(n\) needed?
In general, suppose \(X_1, ..., X_n\) is a random sample from \(N(\mu, \sigma^2)\) . Assume \(\sigma\) is known, the \(1-\alpha\) confidence interval for \(\mu\) is
\[ \bar{X}_n \pm z_{\alpha/2} \frac{\sigma}{\sqrt{n}} \]
Q3: Given the margin of error to be **no more than** \(2d\) , we have
\[ z_{\alpha/2} \frac{\sigma}{\sqrt{n}}\leq d \]
The required sample size must satisfy
\[ n\geq (\frac{z_{\alpha/2} \sigma}{d})^2 = n^* \]
where \(n^*\) is the optimal fixed sample size.
What if \(\sigma\) is unknown?
In general, suppose \(X_1, ..., X_n\) is a random sample from \(N(\mu, \sigma^2)\) . Assume \(\sigma\) is unknown, the \(1-\alpha\) confidence interval for \(\mu\) is
\[ \bar{X}_n \pm t_{n-1, \alpha/2} \frac{S_n}{\sqrt{n}} \]
Can you find the optimal smallest sample size for a pre-defined margin of error?
Fixed-sample confidence intervals for a population mean have widths that depend on the sample size obtained. However, when the population variance is unknown, no fixed-sample methodology can guarantee a pre-specified estimation error.
Let’s take a pilot sample of size 5 from \(N(10,9)\). The pre-specified margin of error is $d = 1$
| Data | Sample Size | Sample Mean | Interval Width | Stop? |
|---|---|---|---|---|
| 5 | ||||