Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the inverse of the log normal cumulative distribution function in python?

How do I calculate the inverse of the log normal cumulative distribution function in python? I'm trying to translate some functions from Excel that uses the function [LOGINV][1]

For example

LOGINV(0,005;2;0,5) yields 2,0382373

where 0,005 is the probability, 2 is the mean and 0,5 is the std.

Does scipy.stats have a similar function that I may apply?

like image 282
GeoPy Avatar asked May 04 '16 09:05

GeoPy


People also ask

How do you find the inverse of a cumulative normal distribution?

x = norminv( p ) returns the inverse of the standard normal cumulative distribution function (cdf), evaluated at the probability values in p . x = norminv( p , mu ) returns the inverse of the normal cdf with mean mu and the unit standard deviation, evaluated at the probability values in p .

How is CDF calculated in Python?

The easiest way to calculate normal CDF probabilities in Python is to use the norm. cdf() function from the SciPy library. What is this? The probability that a random variables takes on a value less than 1.96 in a standard normal distribution is roughly 0.975.

What is Norminv in Python?

Calculates the inverse of the normal cumulative distribution for the specified mean and standard deviation. Written by CFI Team. Updated June 12, 2022.


1 Answers

Yes:

from scipy import stats
import numpy as np
stats.lognorm(0.5, scale=np.exp(2)).ppf(0.005)

from http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.stats.lognorm.html

Please check the meaning of your quantities. Actually 2 and 0.5 are the mean and the std-deviation of the random variable Y=exp(X), where X is the log-normal defined in the code (as also written in the excel documentation). The mean and the std-deviation of the distribution defined in the code are 8.37 and 4.46

like image 195
Ruggero Turra Avatar answered Oct 06 '22 00:10

Ruggero Turra