Reputation:
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
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
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
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.
Upvotes: 14