# Why can we use empirical standard deviation when computing mean confidence intervals

I'm reviewing some basic statistics, and I'm asking myself questions on things I used to take for granted when I first saw them years ago. I'm going to state things as I understand them, so there might be a mistake in the following.

Consider a random variable $$X$$ following a distribution of mean $$\mu$$ and standard deviation $$\sigma$$. We measure $$n$$ samples of $$X$$, and observe an empirical mean $$\bar{x}$$ and empirical std $$s$$.

Because we're observing samples, $$\bar{x}$$ and $$s$$ are random variables themselves. We should therefore not use $$\bar{x}$$ and $$\mu$$ interchangeably, and the same goes for $$s$$ and $$\sigma$$. Instead, people compute confidence interval on $$\mu$$ based on $$\bar{x}$$. By the central limit theorem, if $$n$$ is large enough, we can say that $$\bar{x} \sim N(\mu,\frac{\sigma}{\sqrt{n}})$$.

When computing confidence intervals, we usually use $$\sigma_{\bar{x}} = \frac{s}{\sqrt{n}}$$. If all of this is correct, my question is the following: since both $$s$$ and $$\bar{x}$$ are random variables, why does it seems to be ok to consider $$s=\sigma$$ when computing confidence intervals for $$\mu$$?

Nearly everything you wrote is accurate, but the conclusion you draw at the end is based on a misapprehension; namely that the standard error of the mean when the variance is unknown, the quantity $$s/\sqrt{n}$$, is equal to the standard deviation of the sampling distribution of the mean, which is asymptotically $$\sigma/\sqrt{n}$$. These are not equal since the former is a statistic and the latter is a function of the unknown parameter $$\sigma$$.
That said, the former estimates the latter, in the same way that $$\bar x$$ estimates $$\mu$$.
The source of this confusion comes from the notion that the construction of the confidence interval is based on some "recipe" in which the confidence limits may be expressed in the form $$\bar x \pm t_{n-1, \alpha} \frac{s}{\sqrt{n}},$$ where $$t_{n-1, \alpha}$$ is some "critical value" that depends on the desired level of confidence and the sample size. While the formula is correct, the origin of this formula isn't by analogy with the corresponding parameters; that is to say, the interval estimate isn't constructed from some expression like $$\mu \pm t_{n-1,\alpha} \frac{\sigma}{\sqrt{n}}.$$ This is incorrect. The interval estimate comes from inverting a hypothesis test. Specifically, we want to control the Type I error $$\alpha$$ so that $$\Pr\left[\frac{|\bar X - \mu_0|}{s/\sqrt{n}} > c \;\Bigl| \Bigr. \, H_0 \right] = \alpha,$$ for the hypothesis $$H_0 : \mu = \mu_0 \quad \text{vs.} \quad H_a : \mu \ne \mu_0$$ and $$c$$ is some critical value that depends on $$\alpha$$. The statistic on the LHS of the inequality is (without the absolute value) is Student $$t$$-distributed when $$H_0$$ is true, thus $$c$$ is a quantile of the Student $$t$$ distribution. A derivation of the confidence interval from this condition can be seen in many introductory textbooks in statistics, or you can follow the example for a known variance from Wikipedia and generalize it for the unknown variance case.