moment_raw2cen

mdtools.statistics.moment_raw2cen(rm, axis=-1)[source]

Calculate the \(n\)-th central moment \(\mu_n\) from the first \(n\) raw moments \(m_n\).[1]

\[\mu_n = \langle (x - \mu)^n \rangle = \sum_{k=0}^{n} {n \choose k} (-1)^{n-k} m_k \mu^{n-k}\]

with the \(k\)-th raw moment \(m_k = \langle x^k \rangle\) and the mean \(\mu = m_1\).

Parameters:
  • rm (array_like) – Array containing the first \(n\) raw moments. The raw moments must be ordered along the given axis by the raw moments’ order (i.e. 1st raw moment first, 2nd raw moment second, …). The array must not contain the \(0\)-th raw moment (which is anyway always 1).

  • axis (int, optional) – The axis along which the raw moments are ordered.

Returns:

cm (scalar or numpy.ndarray) – The \(n\)-th central moment, where \(n\) is given by numpy.asarray(rm).shape[-1].

Notes

This function cannot return the \(0\)-th central moment. Anyway, this is always 1.

References

Examples

1-dimensional input arrays:

>>> # 1st central moment (is always zero).
>>> rm = np.array([3])
>>> mdt.stats.moment_raw2cen(rm)
0
>>> # 2nd central moment (<x^2> - <x>^2 = variance)
>>> rm = np.array([ 3, 11])
>>> mdt.stats.moment_raw2cen(rm)
2
>>> # 3rd central moment
>>> rm = np.array([ 3, 11, 49])
>>> mdt.stats.moment_raw2cen(rm)
4
>>> # 4th central moment
>>> rm = np.array([  3,  11,  49, 253])
>>> mdt.stats.moment_raw2cen(rm)
16
>>> # The first central moment is always zero.
>>> [mdt.stats.moment_raw2cen([rm]) for rm in [0, 1/3, 4, 7/3]]
[0, 0.0, 0, 0.0]

2-dimensional input arrays:

>>> rm = np.array([[ 3, 11, 49]])
>>> mdt.stats.moment_raw2cen(rm)
array([4])
>>> ax = 0
>>> rm = np.array([[   3,   11,   49],
...                [  13,  121, 2403]])
>>> mdt.stats.moment_raw2cen(rm, axis=ax)
array([4, 0, 2])
>>> ax = 1
>>> mdt.stats.moment_raw2cen(rm, axis=ax)
array([   4, 2078])

3-dimensional input arrays:

>>> rm = np.array([[[ 3, 11, 49]]])
>>> mdt.stats.moment_raw2cen(rm)
array([[4]])
>>> ax = 0
>>> rm = np.array([[[   3,   11,   49],
...                 [  13,  121, 2403]],
...
...                [[   1,    9,    51],
...                 [   2,   87,  2605]]])
>>> mdt.stats.moment_raw2cen(rm, axis=ax)
array([[      -8,     -112,    -2350],
       [    -167,   -14554, -5771804]])
>>> ax = 1
>>> mdt.stats.moment_raw2cen(rm, axis=ax)
array([[4, 0, 2],
       [1, 6, 4]])
>>> ax = 2
>>> mdt.stats.moment_raw2cen(rm, axis=ax)
array([[   4, 2078],
       [  26, 2099]])