Austin Johnson
Austin Johnson

Reputation: 747

Scipy.stats norm vs lognorm

To the find the probability a number is greater than x using scipy.stats.norm you could write a function like this 1-scipy.stats.norm(55.98,12.29).cdf(64) returning 0.257 meaning that given a mean of 55.98 and a standard deviation of 12.29, there is a 25.7% probability your random observation will be greater than 64? If I wanted to find the logarithmic normal distribution could I do the same with the scipy.stats.lognorm function? 1-scipy.stats.lognorm(55.98,12.29).cdf(64) ?

Upvotes: 0

Views: 438

Answers (1)

Matt Miguel
Matt Miguel

Reputation: 1375

You have the correct interpretation for the normal distribution.

For lognorm, the scipy parameterization is a little weird.

Suppose X is a normally distributed random variable with mean mu and std dev sigma. If Y is defined such that X = ln(Y), then Y has a log normal distribution.

To represent Y in scipy, you do this:

from scipy.stats import lognorm
from math import exp

#using smaller numbers for this example
mu=1
sigma=2
X=norm(mu,sigma)
X.mean() #1.0
X.var() # 4.0

Y = lognorm(s=sigma,scale=exp(mu))
Y.mean() # 20.085536923187668
Y.var() #21623.037001313976

This produces the same result as the wikipedia lognorm formulas for:

  • mean = exp(mu + sigma^2/2)
  • variance = (exp(sigma^2)-1)(exp(2mu+sigma^2)

In all cases in scipy, the .cdf(x) method gives you the probability that the random variable is less than or equal to x.

Upvotes: 1

Related Questions