9

I am searching for a python equivalent of the norminv function in Matlab.

Or in other words (from the above description): I am searching for the "Normal inverse cumulative distribution function" in python, or probably in the stats part of scipy (Or maybe numpy?)

I would guess that it exists in scipy, but probably under another name than in matlab, or in matlabs help page. However I am not sure of this functions other names, or exact workings, so I am having a hard time finding it. And unfortunately it's not simply the "Inverse normal cumul…" instead of the "Normal inverse cumul…"

JC_CL
  • 2,346
  • 6
  • 23
  • 36

1 Answers1

2

It depends exactly on what you want. If you want the cdf of a distribution that is the inverse of the normal distribution, you want invgauss, "An inverse Gaussian continuous random variable.". To get the cdf, you would need to use the invgauss.cdf method. Adapted from the documentation:

from scipy.stats import invgauss
mu = 0.145462645553
vals = invgauss.ppf([0.001, 0.5, 0.999], mu)
res = invgauss.cdf(vals, mu)

On the other hand, if you want the inverse of the cdf of the normal distribution, you want the ppf method of the norm distribution, which is the "Percent point function (inverse of cdf — percentiles)."

TheBlackCat
  • 9,791
  • 3
  • 24
  • 31
  • I don't think this is correct: [Inverse Gaussian Distribution](http://en.wikipedia.org/wiki/Inverse_Gaussian_distribution) – knedlsepp Mar 31 '15 at 14:26
  • From the scipy 0.10.0 release notes: "The deprecated name `invnorm` was removed from `scipy.stats.distributions`, this distribution is available as `invgauss`." – TheBlackCat Mar 31 '15 at 14:32
  • I'm just not sure if the *inverse gaussian cdf* is the same as: *the inverse of the gaussian cdf*. I'm just cross checking this. – knedlsepp Mar 31 '15 at 14:36
  • 2
    Ok. Reason why this must be incorrect: The inverse of the normal cumulative distribution function is a function defined on the interval `[0,1]`, whereas the distribution function of the so called *inverse gaussian distribution* has support `(0,Inf)` as listed on wikipedia. This means those must be two different things as I suspected. The OP wants the function `norm.ppf` used in the question I linked as duplicate. – knedlsepp Mar 31 '15 at 14:47
  • Point taken. I have expanded the answer to cover both possibilities. – TheBlackCat Mar 31 '15 at 14:50
  • Ah, you mentioned `ppf` while I was adding it to the answer. – TheBlackCat Mar 31 '15 at 14:52
  • *a distribution that is the inverse of the normal distribution* is still not correct. As I understand it the *inverse normal distribution* is not *the inverse of the normal distribution*. I think it is just some unfortunate way of naming it, as it has *some* relation to the gaussian distribution. – knedlsepp Mar 31 '15 at 14:56
  • Damn, why are there so many functions that are all almost called the same, yet are called different in all their implementations… Unfortunately I dont have matlab, so I cant do some quick checks to see which of the python functions produces the same output as matlab. However I could install octave, which seems to have a [norminv](http://octave.sourceforge.net/octave/function/norminv.html) function. I'll play around with the various possibilities and report back. – JC_CL Mar 31 '15 at 15:04
  • 2
    OK, so assuming `norminv` in octave is indeed the same as `norminv` in matlab (Octaves documentation is quite short, and I suck at statistics) the python equivalent seems indeed to be `norm.ppf` from `scipy.stats`: octave-`octave:9> norminv(0.9) ans = 1.2816 octave:10> norminv(0.5) ans = 0` Python-`In [35]: stats.norm.ppf(0.9) Out[35]: 1.2815515655446004 In [36]: stats.norm.ppf(0.5) Out[36]: 0.0 ` – JC_CL Mar 31 '15 at 15:15
  • I can confirm those two test cases with matlab `>> norminv(0.9) = 1.2816` `>> norminv(0.5) = 0` – Nick Aug 09 '16 at 18:50