Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quantile functions in Python

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.

like image 441
dsaxton Avatar asked Aug 10 '15 01:08

dsaxton


People also ask

What is quantile function?

In probability and statistics, the quantile function, associated with a probability distribution of a random variable, specifies the value of the random variable such that the probability of the variable being less than or equal to that value equals the given probability.

What is quantile formula?

All methods compute Qp, the estimate for the p-quantile (the k-th q-quantile, where p = k/q) from a sample of size N by computing a real valued index h. When h is an integer, the h-th smallest of the N values, xh, is the quantile estimate.


1 Answers

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
like image 100
dbouz Avatar answered Oct 03 '22 15:10

dbouz