Scipy - two tail ppf function for a z value?

前端 未结 1 1690
旧巷少年郎
旧巷少年郎 2021-02-09 03:42

Using the ppf function from scipy.stat.norm, I get a one-tail result, for example, ppf(.95) gives off 1.644... rather than

相关标签:
1条回答
  • 2021-02-09 03:56

    What you're looking for is quite simply

    In [12]: def normz(val):
       ....:     return scipy.stats.norm.ppf((1+val)/2)
       ....: 
    In [13]: normz(0.95)
    Out[13]: 1.959963984540054
    

    This is because of the symmetric nature of the normal distribution. A 95% confidence interval covers 95% of the normal curve, and as a result the probability of acquiring a value outside this 95% is less than 5% (due to its shape). Then recalling that the normal curve is symmetric, the area in each tail is equivalent to

    enter image description here

    so in your case, the area in each tail is 0.025.

    As a result, in order to use scipy.stats.normal.ppf() with C, you must use the symmetric nature of the normal distribution and

    enter image description here

    to obtain a suitable lower/upper tail probability 0.975 to use with scipy.stats.norm.ppf(). This graph could help you visualize the concept.

    enter image description here

    0 讨论(0)
提交回复
热议问题