user2580104
user2580104

Reputation:

Scipy - two tail ppf function for a z value?

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.96... a two-tail distribution should get.

Is there a function in scipy that gives off a two-tailed z-score based on the p-value?

Upvotes: 8

Views: 4249

Answers (1)

miradulo
miradulo

Reputation: 29680

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

Upvotes: 14

Related Questions