Here is an example with the results:
I integrates over the Gaussian distribution (mu = 800, sigma = 1) with ~ + -2sigma ppf and the same integral from -infto +inf. For some reason, the second integral leads to zero, but in practice it should be more accurate.
Can someone explain why such an anomaly occurs or where I made a mistake?
code:
from scipy.integrate import quad
import numpy as np
from scipy.stats import norm
def integrand(x):
return x*norm.pdf(x, 800, 1)
print quad(integrand, norm.ppf(0.05, 800,1), norm.ppf(0.95, 800,1))
print quad(integrand, -np.inf, np.inf)
(719.9999999999894, 5.913323331834147e-11)
(0.0, 0.0)
EDIT: By the way, when the average is small (like 2), it works great - the results of both integrals are very close.
source
share