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?
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 .
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.
Calculates the inverse of the normal cumulative distribution for the specified mean and standard deviation. Written by CFI Team. Updated June 12, 2022.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With