Winsorizing


Winsorizing or winsorization is the transformation of statistics by limiting extreme values in the statistical data to reduce the effect of possibly spurious outliers. It is named after the engineer-turned-biostatistician Charles P. Winsor. The effect is the same as clipping in signal processing.
The distribution of many statistics can be heavily influenced by outliers. A typical strategy is to set all outliers to a specified percentile of the data; for example, a 90% winsorization would see all data below the 5th percentile set to the 5th percentile, and data above the 95th percentile set to the 95th percentile.
Winsorized estimators are usually more robust to outliers than their more standard forms, although there are alternatives, such as trimming, that will achieve a similar effect.

Example

Consider the data set consisting of:
The data below the 5th percentile lies between −40 and −5, while the data above the 95th percentile lies between 101 and 1053.
Then a 90% winsorization would result in the following:
Python can winsorize data using SciPy library :

from scipy.stats.mstats import winsorize
winsorize

R can winsorize data using the DescTools package:

library
a<-c
DescTools::Winsorize

Distinction from trimming

Note that winsorizing is not equivalent to simply excluding data, which is a simpler procedure, called trimming or truncation, but is a method of censoring data.
In a trimmed estimator, the extreme values are discarded; in a winsorized estimator, the extreme values are instead replaced by certain percentiles.
Thus a winsorized mean is not the same as a truncated mean.
For instance, the 10% trimmed mean is the average of the 5th to 95th percentile of the data, while the 90% winsorized mean sets the bottom 5% to the 5th percentile, the top 5% to the 95th percentile, and then averages the data. In the previous example the trimmed mean would be obtained from the smaller set:
In this case, the winsorized mean can equivalently be expressed as a weighted average of the truncated mean and the 5th and 95th percentiles though in general winsorized statistics need not be expressible in terms of the corresponding trimmed statistic.
More formally, they are distinct because the order statistics are not independent.