Reputation: 475
I am moving some code from R to Anaconda Python. The R code uses qnorm
, documented as "quantile function for the normal distribution with mean equal to mean
and standard deviation equal to sd
."
The call and parameters are:
qnorm(p, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE) p vector of probabilities. mean vector of means. sd vector of standard deviations. log.p logical; if TRUE, probabilities p are given as log(p). lower.tail logical; if TRUE (default), probabilities are P[X≤x] otherwise, P[X].
I don't see any equivalent in pandas.Series. Have I missed it, is it on another object, or is there some equivalent in another library?
Upvotes: 5
Views: 4307
Reputation: 534
Just to expand @miradulo answer. If you want to get also qnorm(lower.tail=FALSE)
you can just multiply by -1:
In R:
qnorm(0.8, lower.tail = F)
-0.8416212
In python
from scipy.stats import norm
norm.ppf(0.8) * -1
-0.8416212
Upvotes: 1
Reputation: 29720
A lot of this equivalent functionality is found in scipy.stats. In this case, you're looking for scipy.stats.norm.ppf
.
qnorm(p, mean = 0, sd = 1)
is equivalent to scipy.stats.norm.ppf(q, loc=0, scale=1)
.
import scipy.stats as st
>>> st.norm.ppf([0.01, 0.99])
array([-2.32634787, 2.32634787])
>>> st.norm.ppf([0.01, 0.99], loc=10, scale=0.1)
array([ 9.76736521, 10.23263479])
Upvotes: 12