# Is it possible to estimate moments using data from a PDF?

I'm new to Cross Validate, so sorry if I make any mistakes in my question. Any correction/advice would be welcome. My doubt is a rather basic one, but I'm strugling with this idea.

Supose I have some set of data and that I estimate a univariate nonparametric density estimation over some empirical variable Z, returning a PDF with two axis: x (the values of the variable) and y ( the probability density - which when integrated gives the probability of x happening).

Is it possible to recover with some degree of accuracy the moments of the original distribution Z (mean, variance, etc) using the bins of x and y returned from the PDF?

It seems that the median would be relatively straighfoward, since you would only have to integrate the area under the plot A and then find the first point which has area over 50% of A, but the others, if possible, are scaping me.

• Sure, just evaluate $\int_{-\infty}^\infty x^mf(x)dx$ numerically. Jul 15, 2017 at 21:53
• Unless you intend "density" to encompass discrete probability functions, density is not probability, so if you have a continuous KDE what is on the y axis is not "probability of x happening". Jul 15, 2017 at 22:42
• Do you have the original kernel and bandwidth? Since a KDE is a mixture it's possible to compute the moments of the mixture (though they can get a bit unwieldy if you need a lot of moments) Jul 15, 2017 at 22:43
• Thanks for your inputs, guys! My question originated from the poor parametric fit that I was getting from evaluating numerically the moments of the distribution. I thought that I was doing something theoretically wrong. Now, it seems that what I was doing was correct, so I will double check my code with the guys from stack overflow. And @Glen_b, of course you are correct. The area under the graph would be correctly called probability, not the function by itself. Sorry for being imprecise. Edited my text to avoid confusion. Jul 17, 2017 at 22:58
• I should add that estimating moments via a KDE won't necessarily give unbiased estimates; variance will be biased up (you'd end up estimating the sum of the population variance and the square of the bandwidth) and the 4th central moment would also be biased (though not consistently up or down -- toward that of the kernel, I suspect) Jul 17, 2017 at 23:04

1. You could use method of moments: $E(X^m) \approx \frac1n \sum_{i=1}^n X_i^m$
2. As Alex suggested, you could evaluate the integral numerically with your empirical CDF: $E(X^m) \approx \int x^m d\hat F(x)$ or use bootstrap.