I'm having trouble finding quantile functions for well-known probability distributions in Python, do they exist? In particular, is there an inverse normal distribution function? I couldn't find anything in either Numpy or Scipy.
Asked
Active
Viewed 1.2k times
9
-
2http://stackoverflow.com/q/24695174/625914 – behzad.nouri Aug 10 '15 at 01:36
-
2... and http://stackoverflow.com/questions/20626994/how-to-calculate-the-inverse-of-the-normal-cumulative-distribution-function-in-p/20627638#20627638 – Warren Weckesser Aug 10 '15 at 02:03
2 Answers
6
Check the .ppf() method of any distribution class in scipy.stats. This is the equivalent of a quantile function (otherwise named as percent point function or inverse CDF)
An example with the exponential distribution from scipy.stats:
# analysis libs
import scipy
import numpy as np
# plotting libs
import matplotlib as mpl
import matplotlib.pyplot as plt
# Example with the exponential distribution
c = 0
lamb = 2
# Create a frozen exponential distribution instance with specified parameters
exp_obj = scipy.stats.expon(c,1/float(lamb))
x_in = np.linspace(0,1,200) # 200 numbers in [0,1], input for ppf()
y_out = exp_obj.ppf(x_in)
plt.plot(x_in,y_out) # graphically check the results of the inverse CDF

dbouz
- 779
- 9
- 14
0
It seems new but I've found this about numpy and quantile. Maybe you can have a look (not tested)

MaxD
- 377
- 2
- 4
- 14
-
2That gives the empirical quantiles of a set of observations, rather than the exact quantiles of a theoretical distribution the poster is asking for. It is new to numpy, but gives the same functionality as the function `np.percentile`. – user2699 Aug 10 '18 at 13:13