1
$\begingroup$

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

$\endgroup$
2

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
5
  • $\begingroup$ 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. $\endgroup$
    – monade
    Sep 3, 2023 at 13:19
  • 1
    $\begingroup$ 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. $\endgroup$ Sep 3, 2023 at 13:21
  • $\begingroup$ As mentioned in my post I specifically assume that I know $\sigma$. $\endgroup$
    – monade
    Sep 3, 2023 at 13:23
  • 1
    $\begingroup$ Like I mentioned in my answer, when the data are large then the use of a z as opposed to a t test can still lead to valid conclusions. The authors of statsmodels know that pop parameters are rarely known in practice so it doesn't make sense to write a function for an applied stats library to specify the pop parameters. $\endgroup$ Sep 3, 2023 at 13:28
  • $\begingroup$ 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. $\endgroup$
    – monade
    Sep 3, 2023 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.