Probability to z-score and vice versa in python

守給你的承諾、 提交于 2019-12-17 15:16:32

问题


I have numpy, statsmodel, pandas, and scipy(I think)

How do I calculate the z score of a p-value and vice versa?

For example if I have a p value of 0.95 I should get 1.96 in return.

I saw some functions in scipy but they only run a z-test on a array.


回答1:


>>> import scipy.stats as st
>>> st.norm.ppf(.95)
1.6448536269514722
>>> st.norm.cdf(1.64)
0.94949741652589625

As other users noted, Python calculates left/lower-tail probabilities by default. If you want to determine the density points where 95% of the distribution is included, you have to take another approach:

>>>st.norm.ppf(.975)
1.959963984540054
>>>st.norm.ppf(.025)
-1.960063984540054



来源:https://stackoverflow.com/questions/20864847/probability-to-z-score-and-vice-versa-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!