biweight_midvariance

astropy.stats.biweight_midvariance(a, c=9.0, M=None, axis=None)[source] [edit on github]

Compute the biweight midvariance.

The biweight midvariance is a robust statistic for determining the midvariance (i.e. the standard deviation) of a distribution. It is given by:

\[\begin{split}C_{bl}= (n')^{1/2} \frac{[\Sigma_{|u_i|<1} (x_i-M)^2(1-u_i^2)^4]^{0.5}} {|\Sigma_{|u_i|<1} (1-u_i^2)(1-5u_i^2)|}\end{split}\]

where \(u_i\) is given by

\[u_{i} = \frac{(x_i-M)}{c MAD}\]

where \(c\) is the tuning constant and \(MAD\) is the median absolute deviation. The midvariance tuning constant c is typically 9.0.

\(n'\) is the number of points for which \(|u_i| < 1\) holds, while the summations are over all \(i\) up to \(n\):

\[\begin{split}n' = \Sigma_{|u_i|<1}^n 1\end{split}\]

This is slightly different than given in the reference below, but results in a value closer to the true midvariance.

For more details, see Beers, Flynn, and Gebhardt (1990); AJ 100, 32.

Parameters:

a : array-like

Input array or object that can be converted to an array.

c : float, optional

Tuning constant for the biweight estimator. Default value is 9.0.

M : float or array-like, optional

Initial guess for the biweight location. An array can be input when using the axis keyword.

axis : int, optional

Axis along which the biweight midvariances are computed. The default (None) is to compute the biweight midvariance of the flattened array.

Returns:

biweight_midvariance : float or ndarray

The biweight midvariance of the input data. If axis is None then a scalar will be returned, otherwise a ndarray will be returned.

Examples

Generate random variates from a Gaussian distribution and return the biweight midvariance of the distribution:

>>> import numpy as np
>>> from astropy.stats import biweight_midvariance
>>> rand = np.random.RandomState(12345)
>>> from numpy.random import randn
>>> bmv = biweight_midvariance(rand.randn(1000))
>>> print(bmv)    
0.986726249291