Paradoxical result when computing a confidence interval when population standard deviation is not known I have been trying to construct a $1-\alpha$ confidence interval for the mean. The distribution from which a sample is drawn is exponential distribution with density:
$$p(x) = \frac{1}{\beta}e^{-x/\beta}$$
The exponential distribution has mean $\mu=\beta$ and standard deviation $\sigma=\beta$. As far as my knowledge is concerned, for a sample $X_1, X_2, \cdots, X_n$ of size $n$, the confidence interval :
$$\left(\bar{X}_n-z_{\alpha/2}\frac{\sigma}{\sqrt{n}}, \bar{X}_n+z_{\alpha/2}\frac{\sigma}{\sqrt{n}}\right)$$
should trap the true $\mu$ with $1-\alpha$ chance (I am not saying that this interval contains $\mu$ with probability $1-\alpha$; that will be wrong since $\mu$ is not a random variable).
However, this assumes that population standard deviation $\sigma$ is known. Since I want to simulate a situation where that too needs to be estimated, I constructed the forllowing interval:
$$\left(\bar{X}_n-t_{\alpha/2}\frac{\hat{\sigma}}{\sqrt{n}}, \bar{X}_n+t_{\alpha/2}\frac{\hat{\sigma}}{\sqrt{n}}\right)$$
where, $$\hat{\sigma}=\sqrt{\frac{1}{n-1}\sum_{i=1}^n (X_i-\bar{X}_n)^2}$$
and $t_{\alpha/2}$ is the critical t-value obtained for the Student's t-distribution for $n-1$ degrees of freedom.
I wrote a small python script to verify that with this modification, the constructed interval is indeed $95\%$ confidence interval when $\alpha=0.05$. For my simulations, I chose $n=10$, so that we have $9$ degrees of freedom, $t_{\alpha/2}=2.262$. I could verify that the first interval where population variance is known indeed contains true $\mu$ around $95\%$ of the time. (I generate $10000$ intervals and count how many contain the known $\mu$). However, the second one seems to contain $\mu$ only $90\%$ of the time. I am not sure why even after correctly choosing the correct critical $t$ this is happening. If I increase $t_{\alpha/2}=3.182$ corresponding to 3 degrees of freedom, I do get $95\%$ interval again! But of course this makes no sense because the degrees of freedom is $9$ in this case. Any idea what is happening?
 A: If you have a random sample of size $n$ from $\mathsf{Exp}(\mathrm{rate}=1/\beta),$ (with mean $\beta),$ then $\bar X/\beta \sim
\mathsf{Gamma}(\mathrm{shape}=n,\mathrm{rate} = n).$
Thus a 95% CI for $\beta$ is of the form
$\left(\frac{\bar X}{U},\, \frac{\bar X}{L}\right),$ where $L$ and $U$
cut probability $0.025$ from lower and upper tails, respectively of
$\mathsf{Gamma}(n,n).$
For example, let's take a random sample of size $n=30$ from
an exponential distribution with mean $\mu = 15.$ In R below,
I got $\bar X =14.08$ and 95% CI $(10.14,\, 20.86),$ which
does happen to contain $\mu = 15.$ Of course, with real data
from a real population, one never knows for sure if the 95% CI
covers the unknown $\mu.$
set.seed(1234)
x = rexp(30, 1/15)
summary(x)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
 0.05992  4.10425 11.88384 14.07736 24.64535 45.78687 
mean(x)/qgamma(c(.975,.025), 30, 30)
[1] 10.14004 20.86475

Three additional runs with no seed specified, gave
intervals $(12.89,\, 26.52),$ $(7.36,\, 15.15),$ and
$(11.02,\, 22.67).$ But a run using todays date as set.seed(418)
missed the mark with CI $(15.29,\, 31.46).$
