# Calculate moments given density values

Suppose I have given a finite number of grid values belonging to a probability density function. Moreover, I have the associated values of the density support. For instance:

support density value
0.06    0.07
-0.04   0.11
-0.02   0.52
0.00    1.56
0.02    7.87
0.04    19.18
0.06    13.66
0.08    3.40
0.10    0.98
0.13    0.33
0.15    0.14
0.17    0.07
0.19    0.00
0.22    0.43
0.24    0.01



Does anyone know the formula to calculate the first four moments of the distribution?

I would appreciate any help. Many thanks in advance!

• You could interpolate the density and then numerically integrate this function? You know, $E[X]=\int_\mathbb{R} xf_X(x)dx$ etc... – Alex Jul 4 at 13:15

The key is:

$$\mathbf{E}[X^k] = \sum_{i=1}^n x_i^k p(x_i)$$

($$X$$ discrete variable, $$x_i$$ realizations, and $$p(x_i)$$ realization probabilities)

See this link for further details.

• Great, this helps a lot! thanks! – Walter Jul 4 at 13:27
• @Walter Glad to help. Unless you are waiting for other answers, please consider marking this answer as accepted (marking procedure available here: stackoverflow.com/help/someone-answers) – ir7 Jul 4 at 13:35
• As the densities do not yet sum to one, please also consider proper normalisation, no? – Kermittfrog Jul 5 at 6:29
• @Kermittfrog Good point. If they don’t add up to one, one needs to normalize them. See, for example, math.stackexchange.com/questions/278418/… – ir7 Jul 5 at 16:45

Just to add, you did not mention which kind of momement. These calculated by formula in ir7 are called general moments. However, there are also:

• Central moments defined as $$E[X-EX]^k$$
• Standardized moments defined as $$E\big[\frac{X-EX}{\sigma(X)}\big]^k$$,

where $$EX$$ is first general moment (expected value) and $$\sigma(X)$$ is second general moment (standard deviation).

Note that for $$k=1$$ the central moment and standardized moment are always 0. For $$k=2$$, the standardized moment is always 1.