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.
- alpha
floatininterval(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”, “med”, “mean”, “tmean”}
orarray_like,optional center defines how the trimmed sample is centered. ‘median’ (or the alias ‘med’) 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. Default is ‘median’.
- axis
int,optional Axis along which scale is estimated. The default is 0.
- distr
None, “raw” ordistributioninstance,optional 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.
- distargs
tupleorNone,optional Arguments for the distribution.
- Returns:
ScaleTrimmedResultSee
ScaleTrimmedResultfor 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