[SciPy-Dev] two new scipy.stats requests code included:

Jon Stein oneday2one at icloud.com
Mon Oct 15 05:53:57 EDT 2018


Scipy-dev,

Two additions to the scipy.stats module are missing and needed:

One addition is needed for a one sample z-test including confidence interval when the population mean and standard deviation are known:

def ztest(array_A, population_mean, population_stdv, level_of_confidence~example: .95):
    z_statistic = (array_A.mean() - population_stdv) / (population_stdv / math.sqrt(len(array_A)))
    p_value = (st.norm.cdf(z_stat))
    standard_error = population_stdv / math.sqrt(len(array_A))
    margin_of_error = st.norm.ppf(level_of_confidence) * standard_error
    MoE = margin_of_error
    return('z statistic =', z_statistic, 'p-value =', p_value, array_A.mean() - MoE, array_A.mean() + MoE)

And one addition is needed for a one-sample z-test for a categorical sample (*not quantitative*):

def ztest_1sample_categorical(sample_proportion, population_proportion, sample_size):
    sp, pp = sample_proportion, population_proportion
    z = (sp - pp) / math.sqrt((pp * (1 - pp)) / sample_size)
    p = st.norm.cdf(z)
    return('z statistic =', z, 'p value =', p)

Let me know what you think.
Jon Stein

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20181015/cd7a1712/attachment.html>


More information about the SciPy-Dev mailing list