# Why is the sample standard deviation used in the z-test?

The assumption of the z-test is that the population standard deviation $$\sigma$$ is known. With this in mind I tried to manually compute the p-value for a (one-tailed) z-test that the sample mean $$\bar{X}$$ is greater than 0, and compare it with the z-test p-value given by a popular stats toolbox.

Naively, I thought that if the population standard deviation $$\sigma$$ is known, I would use it to normalize my mean $$\bar{X}$$:

$$z=\frac{\bar{X}}{\sigma/\sqrt{N}}$$

However, the toolbox is not even asking for the population standard deviation $$\sigma$$. By testing, I found that it uses the sample standard deviation $$\hat{\sigma}$$.

Why is that? Is this the general logic of the z-test and if yes, why would we not make use of the known population standard deviation?

For reference, this is the toolbox z-test I tried: https://www.statsmodels.org/dev/generated/statsmodels.stats.weightstats.ztest.html#statsmodels.stats.weightstats.ztest

Generally, population parameters are unknown so we have to estimate them. If $$\bar{x}$$ is the sample mean, and $$\hat{s}$$ the sample standard deviation, then the statistic
$$\dfrac{\bar{x}}{\hat{s} / \sqrt{n}}$$
technically has t-distribution. However, when $$n$$ is sufficiently large, the sampling distribution of this statistic is very close to a normal distribution. So close that using the normal in place of the student-t to compute p values leads to nominal differences.
• Thanks! So would you say that the formally correct way would be to use the population standard deviation in my formula above? And if I don't know $\sigma$ anyway then just use a t-test? I found it weird that a popular toolbox wouldn't allow me to perform a formally correct z-test by supplying $\sigma$ & hence though I might have missed something. Sep 3, 2023 at 13:19
• It would be correct to do a t-test since you don't know $\sigma$ and have to estimate it, but if $n$ is large enough then the difference is very small between the two approaches. Sep 3, 2023 at 13:21
• As mentioned in my post I specifically assume that I know $\sigma$. Sep 3, 2023 at 13:23
• Here is where I would disagree. One would just use a t-test in case of unknown $\sigma$ (which statsmodels also offers). If a toolbox is additionally providing a z-test, then it's strange that you can't compute formally correct z/p-values with the test. Sep 3, 2023 at 13:52