Skip to main content
`Ctrl`+`K`
scipy.stats.Mixture.

# moment

Mixture.moment(order=1, kind='raw', *, method=None)

  Raw, central, or standard moment of positive integer order.

  In terms of probability density function \(f(x)\) and support \(\chi\), the “raw” moment (about the origin) of order \(n\) of a continuous random variable \(X\) is:

  \[\mu'_n(X) = \int_{\chi} x^n f(x) dx\]

  The “central” moment is the raw moment taken about the mean, \(\mu = \mu'_1\):

  \[\mu_n(X) = \int_{\chi} (x - \mu) ^n f(x) dx\]

  The “standardized” moment is the central moment normalized by the \(n^\text{th}\) power of the standard deviation \(\sigma = \sqrt{\mu_2}\) to produce a scale invariant quantity:

  \[\tilde{\mu}_n(X) = \frac{\mu_n(X)} {\sigma^n}\]

  The definitions for discrete random variables are analogous, with sums over the support replacing the integrals.

  Parameters:
    orderint

      The integer order of the moment; i.e. \(n\) in the formulae above.

    kind{‘raw’, ‘central’, ‘standardized’}

      Whether to return the raw (default), central, or standardized moment defined above.

    method{None, ‘formula’, ‘general’, ‘transform’, ‘normalize’, ‘quadrature’, ‘cache’}

      The strategy used to evaluate the moment. By default (`None`), the infrastructure chooses between the following options, listed in order of precedence.

      - `'cache'`: use the value of the moment most recently calculated via another method

      - `'formula'`: use a formula for the moment itself

      - `'general'`: use a general result that is true for all distributions with finite moments; for instance, the zeroth raw moment is identically 1

      - `'transform'`: transform a raw moment to a central moment or vice versa (see Notes)

      - `'normalize'`: normalize a central moment to get a standardized or vice versa

      - `'quadrature'`: numerically integrate (or, in the discrete case, sum) according to the definition

      Not all method options are available for all orders, kinds, and distributions. If the selected method is not available, a `NotImplementedError` will be raised.

  Returns:
    outarray

      The moment of the random variable of the specified order and kind.

  See also

  `pdf`
  `mean`
  `variance`
  `standard_deviation`
  `skewness`
  `kurtosis`

  Notes

  Not all distributions have finite moments of all orders; moments of some orders may be undefined or infinite. If a formula for the moment is not specifically implemented for the chosen distribution, SciPy will attempt to compute the moment via a generic method, which may yield a finite result where none exists. This is not a critical bug, but an opportunity for an enhancement.

  The definition of a raw moment in the summary is specific to the raw moment about the origin. The raw moment about any point \(a\) is:

  \[E[(X-a)^n] = \int_{\chi} (x-a)^n f(x) dx\]

  In this notation, a raw moment about the origin is \(\mu'_n = E[x^n]\), and a central moment is \(\mu_n = E[(x-\mu)^n]\), where \(\mu\) is the first raw moment; i.e. the mean.

  The `'transform'` method takes advantage of the following relationships between moments taken about different points \(a\) and \(b\).

  \[E[(X-b)^n] = \sum_{i=0}^n E[(X-a)^i] {n \choose i} (a - b)^{n-i}\]

  For instance, to transform the raw moment to the central moment, we let \(b = \mu\) and \(a = 0\).

  The distribution infrastructure provides flexibility for distribution authors to implement separate formulas for raw moments, central moments, and standardized moments of any order. By default, the moment of the desired order and kind is evaluated from the formula if such a formula is available; if not, the infrastructure uses any formulas that are available rather than resorting directly to numerical integration. For instance, if formulas for the first three raw moments are available and the third standardized moments is desired, the infrastructure will evaluate the raw moments and perform the transforms and standardization required. The decision tree is somewhat complex, but the strategy for obtaining a moment of a given order and kind (possibly as an intermediate step due to the recursive nature of the transform formula above) roughly follows this order of priority:

  1. Use cache (if order of same moment and kind has been calculated)

  2. Use formula (if available)

  3. Transform between raw and central moment and/or normalize to convert between central and standardized moments (if efficient)

  4. Use a generic result true for most distributions (if available)

  5. Use quadrature

  References

  [1]

  Moment, Wikipedia, https://en.wikipedia.org/wiki/Moment_(mathematics)

  Examples

  Instantiate a distribution with the desired parameters:

      >>> from scipy import stats
      >>> X = stats.Normal(mu=1., sigma=2.)

  Evaluate the first raw moment:

      >>> X.moment(order=1, kind='raw')
      1.0
      >>> X.moment(order=1, kind='raw') == X.mean() == X.mu
      True

  Evaluate the second central moment:

      >>> X.moment(order=2, kind='central')
      4.0
      >>> X.moment(order=2, kind='central') == X.variance() == X.sigma**2
      True

  Evaluate the fourth standardized moment:

      >>> X.moment(order=4, kind='standardized')
      3.0
      >>> X.moment(order=4, kind='standardized') == X.kurtosis(convention='non-excess')
      True