biweight_location#

astropy.stats.biweight.biweight_location(data, c=6.0, M=None, axis=None, *, ignore_nan=False)[source]#

Compute the biweight location.

The biweight location is a robust statistic for determining the central location of a distribution. It is given by:

\[\zeta_{biloc}= M + \frac{\sum_{|u_i|<1} \ (x_i - M) (1 - u_i^2)^2} {\sum_{|u_i|<1} \ (1 - u_i^2)^2}\]

where \(x\) is the input data, \(M\) is the sample median (or the input initial location guess) and \(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 biweight location tuning constant c is typically 6.0 (the default).

If \(MAD\) is zero, then \(M\) (the median, or the input initial location guess if it was provided) will be returned.

If all data values are rejected (\(|u_i| \geq 1\)), for example if the input M is far from the data, then NaN will be returned.

Parameters:
dataarray_like

Input array or object that can be converted to an array. data can be a MaskedArray, an Masked array, or a Quantity.

cfloat, optional

Tuning constant for the biweight estimator (default = 6.0). Must be positive.

Mfloat or array_like, optional

Initial guess for the location. If M is a scalar value, then its value will be used for the entire array (or along each axis, if specified). If M is an array, then it must be an array containing the initial location estimate along each axis of the input array. If None (default), then the median of the input array will be used (or along each axis, if specified).

axisint or tuple of int, optional

The axis or axes along which the biweight locations are computed. If None (default), then the biweight location of the flattened input array will be computed.

ignore_nanbool, optional

Whether to ignore NaN values in the input data.

Returns:
biweight_locationfloat or ndarray

The biweight location of the input data. If axis is None (or includes all axes), then a scalar will be returned. Otherwise, a ndarray will be returned. If data is a Quantity or an Masked array, then the result has the same type. If data is a MaskedArray and axis is not None, then a MaskedArray will be returned.

References

Examples

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

>>> import numpy as np
>>> from astropy.stats import biweight_location
>>> rand = np.random.default_rng(12345)
>>> biloc = biweight_location(rand.standard_normal(1000))
>>> print(biloc)
0.01535330525461019