Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python equivalent of qnorm, qf and qchi2 of R

Tags:

python

r

scipy

I need the quantile of some distributions in python. In r it is possible to compute these values using the qf, qnorm and qchi2 functions.

Is there any python equivalent of these R functions? I have been looking on scipy but I did non find anything.

like image 441
Donbeo Avatar asked Jul 11 '14 10:07

Donbeo


2 Answers

The equivalent of the R pnorm() function is: scipy.stats.norm.cdf() with python The equivalent of the R qnorm() function is: scipy.stats.norm.ppf() with python

like image 188
Eric Vansteenberghe Avatar answered Sep 20 '22 05:09

Eric Vansteenberghe


You may find probability distributions in scipy.stats. Every distribution defines a set of functions, for example if you go to norm distribution and scroll down the page you may find the methods which include

ppf(q, loc=0, scale=1)  # Percent point function (inverse of cdf — percentiles) 

that is what scipy calls Percent point function and does what R q functions does.

For example:

>>> from scipy.stats import norm >>> norm.ppf(.5)  # half of the mass is before zero 0.0 

Same interface for other distributions, say chi^2:

>>> from scipy.stats import chi2 >>> chi2.ppf(.8, df=2) # two degress of freedom 3.2188758248682015 
like image 27
behzad.nouri Avatar answered Sep 18 '22 05:09

behzad.nouri