statsmodels.robust.scale.scale_trimmed#

statsmodels.robust.scale.scale_trimmed(data, alpha, center='median', axis=0, distr=None, distargs=None)[source]#

Scale estimate based on symmetrically trimmed sample

The scale estimate is robust to a fraction alpha of outliers on each tail. The scale is normalized to correspond to a reference distribution, which is the normal distribution by default.

Parameters:
dataarray_like

dataset, by default (axis=0) observations are assumed to be in rows and variables in columns.

alphafloat in interval (0, 1)

Trimming fraction in each tail. The floor(nobs * alpha) smallest observations are trimmed, and the same number of the largest observations are trimmed. scale estimate is base on a fraction (1 - 2 * alpha) of observations.

center‘median’, ‘mean’, ‘tmean’ or number

center defines how the trimmed sample is centered. ‘median’ and ‘mean’ are calculated on the full sample. tmean is the trimmed mean, calculated with the trimmed sample. If center is array_like then it needs to be scalar or correspond to the shape of the data reduced by axis.

axisint, default is 0

axis along which scale is estimated.

distrNone, ‘raw’ or a distribution instance

Default if distr is None is the normal distribution scipy.stats.norm. This is the reference distribution to normalize the scale. Note: This cannot be a frozen instance, since it does not have an expect method. If distr is ‘raw’, then the scale is not normalized.

distargstuple, optional

Arguments for the distribution.

Returns:
ScaleTrimmedResult

See ScaleTrimmedResult for a description of the attributes.

Examples

for normal distribution

>>> np.random.seed(1)
>>> x = 2 * np.random.randn(100)
>>> scale_trimmed(x, 0.1).scale
1.7479516739879672

for t distribution >>> alpha = 0.1 >>> xt = stats.t.rvs(3, size=1000, scale=2) >>> print(scale_trimmed(xt, alpha, distr=stats.t, distargs=(3,)).scale) 2.0542599264671044

compare to standard deviation of sample >>> xt.std() 3.1457788359130481