Convert Z-score (Z-value, standard score) to p-value for normal distribution in Python

后端 未结 7 1820
野趣味
野趣味 2020-12-12 18:19

How does one convert a Z-score from the Z-distribution (standard normal distribution, Gaussian distribution) to a p-value? I have yet to find the magical function in Scipy\'

7条回答
  •  自闭症患者
    2020-12-12 18:46

    Aha! I found it: scipy.special.ndtr! This also appears to be under scipy.stats.stats.zprob as well (which is just a pointer to ndtr).

    Specifically, given a one-dimensional numpy.array instance z_scores, one can obtain the p-values as

    p_values = 1 - scipy.special.ndtr(z_scores)
    

    or alternatively

    p_values = scipy.special.ndtr(-z_scores)
    

提交回复
热议问题