Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In "statsmodels" Python library, why does z-test not require Population standard deviation?

So to execute a z-test in python, I have seen people doing:

from statsmodels.stats.weightstats import ztest as ztest
# IQ levels of 20 patients post medication
data = [88, 92, 94, 94, 96, 97, 97, 97, 99, 99,
            105, 109, 109, 109, 110, 112, 112, 113, 114, 115]

ztest(data, value=100) # value is mean

Why is the Population standard deviation (std) not required in the argument? How does the library apply the z-test formula without getting the population std?

like image 454
Rushank Savant Avatar asked Aug 09 '26 23:08

Rushank Savant


1 Answers

If you examine the source code for the statsmodels ztest method (available at https://www.statsmodels.org/dev/\_modules/statsmodels/stats/weightstats.html#ztest) you will see that the sample variance, and hence standard deviation, is computed internally by that method.

The default method for computing the standard deviation is "pooled", where the standard deviation of the samples is assumed equal in the case of a two-sample z-test. You can set the usevar argument to "unequal" to have the ztest method compute the standard deviation of the samples separately.

like image 123
paisanco Avatar answered Aug 12 '26 13:08

paisanco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!