Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Probability to z-score and vice versa

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 an array.

I have access to numpy, statsmodel, pandas, and scipy (I think).

like image 388
user3084006 Avatar asked Jan 01 '14 01:01

user3084006


People also ask

How do you convert probability to z-score?

To find the probability of LARGER z-score, which is the probability of observing a value greater than x (the area under the curve to the RIGHT of x), type: =1 - NORMSDIST (and input the z-score you calculated).

How do you find probability with z-score and standard deviation?

Conclusion. In a normally distributed data set, you can find the probability of a particular event as long as you have the mean and standard deviation. With these, you can calculate the z-score using the formula z = (x – μ (mean)) / σ (standard deviation).


2 Answers

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

Default Python Probabilities

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 

Density between two points

like image 112
Myles Baker Avatar answered Sep 28 '22 08:09

Myles Baker


Starting in Python 3.8, the standard library provides the NormalDist object as part of the statistics module.

It can be used to get the zscore for which x% of the area under a normal curve lies (ignoring both tails).

We can obtain one from the other and vice versa using the inv_cdf (inverse cumulative distribution function) and the cdf (cumulative distribution function) on the standard normal distribution:

from statistics import NormalDist  NormalDist().inv_cdf((1 + 0.95) / 2.) # 1.9599639845400536 NormalDist().cdf(1.9599639845400536) * 2 - 1 # 0.95 

An explanation for the '(1 + 0.95) / 2.' formula can be found in this wikipedia section.

like image 21
Xavier Guihot Avatar answered Sep 28 '22 06:09

Xavier Guihot