0

I am trying to get the E(x) for a lognormal random variable using scipy.stats.expect.

Using the fit() module, the shape, loc and scale parameters are

shape = 0.9577226550971423, loc=-1.1217451814333423, scale=0.744230342110942

The expected value output is

from scipy.stats import lognorm
scipy.stats.lognorm.expect(lambda x:1, args=(0.9577226550971423,), loc=-1.1217451814333423, scale=0.744230342110942, lb=0.1, ub=1.5)

Output: 0.20809733881415318

However when calculating it manually using the pdf chart the value is closer to 0.5. Chart below:

enter image description here

would you be able to explain where I am wrong in this?

talonmies
  • 70,661
  • 34
  • 192
  • 269
  • Perhaps, you could share the data too? Expected value of the log normal distribution is quite sensitive to upper and lower bounds. Maybe, you should just enforce `lb=0` and let upper bound go to infinity. This way, it models your data better and gives expected value closer to 0.5 (which you expect). What do you think? – Tirth Patel Dec 15 '20 at 12:56

1 Answers1

0

Have you tried adding conditional=True to the kwargs of the function expect() ?
This won't make a huge difference as your upper and lower bounds are relatively close to the support of the lognormal distribution, but still, it will add precision (see Calculating conditional expectation with scipy.stats).

Also, maybe the problem comes from the fitting that isn't good in the first place (see Scipy: lognormal fitting.