# Trimmed, weighted mean

The trimmed mean (or truncated mean) is a robust version of the mean, designed to be robust to outliers. I am wondering what is the right trimmed version of a weighted average.

If I have a sample with data points $$x_1,\dots,x_n$$, and I want to trim one point from each end (i.e., be robust to a single outlier), the trimmed mean is $$\text{trimmed mean} = {1 \over n-2} \sum_{i=2}^{n-1} x_{(i)},$$ where $$x_{(i)}$$ is the $$i$$th largest value from the sample (i.e., put $$x_1,\dots,x_n$$ in increasing order, then call them $$x_{(1)},\dots,x_{(n)}$$). This is robust to a single outlier (a single value that gets wildly corrupted), and also robust to small errors in any single value (small errors in a single value cause only small changes in the trimmed mean). This makes sense to me.

Suppose instead of computing a mean, I want to compute a weighted mean, but I want to do it in a way that is robust. In other words, I have data points $$x_1,\dots,x_n$$ with weights $$w_1,\dots,w_n$$. The weighted mean is $$\text{weighted mean} = \sum_{i=1}^n w_i x_i.$$ This is not robust to outliers; a single value that is corrupted by a large amount can cause an unbounded error in the weighted mean. What is the robust version of the trimmed mean, for weighted means?

The obvious scheme would be to do the same as for the ordinary trimmed mean, and discard the smallest and largest $$x$$-value: $$\text{candidate} = {\sum_{i=2}^{n-1} w_{(i)} x_{(i)} \over \sum_{i=2}^{n-1} w_{(i)}},$$ where $$x_{(i)}$$ is as defined above and $$w_{(i)}$$ is the weight associated to $$x_{(i)}$$. This too is robust to a single wildly corrupted value. However, it smells a little bit dubious to me. For instance, if I have the values $$0,1,100,199,200$$ in my sample, with weights $$1,1,1,1000,1$$, then this would give me $$(1 \times 1 + 1 \times 100 + 1000 \times 199)/1002$$, and small changes or errors in the value 199 would have a fairly large influence on the final mean. Perhaps that is just a consequence of having a large weight, but it makes me wonder whether I have the right notion of weighted, trimmed mean.

I wonder if perhaps instead I should be looking at both the values and the weights when deciding which value to trim. For example, I could sort $$w_1x_1,\dots,w_nx_n$$ in increasing order, letting the result be $$w_{}x_{},\dots,w_{[n]}x_{[n]}$$, and then use $$\text{alternative} = {\sum_{i=2}^{n-1} w_{[i]}x_{[i]} \over \sum_{i=2}^{n-1} w_{[i]}}.$$ This too is robust to a single outlier (a single value that is wildly corrupted cannot cause unbounded error in the final estimate), but seems like it might better limit the influence of small errors in any one data point. However it too smells a bit dubious to me for reasons I am not sure how to articulate.

Is there a "right" generalization of the trimmed mean, to weighted means? Or how should I think about the options and their tradeoffs?

I have difficulty articulating the goals or requirements clearly. I suspect there are at least three that one might hope for: breakdown point (a change or error to any one data point cannot cause unbounded change to the estimate), local sensitivity (a small change or error to any one data point will have limited influence over the estimate, to the extent possible), and efficiency (low variance in the estimate); but I'm not sure whether I'm thinking clearly about the goals.

• Often, weighted data are just a notational convenience, instead of having a dataset that says, 2,2,2, 5,5, 7, 8, 9,9,9,9, you have 2(3),5(2),7(1),8(1),9(4). In that case, you can expand the dataset into the full listing format & trim as normal. If the weights mean something else, I guess the solution would depend on what they mean & why. Jan 22, 2021 at 20:35

Let's start with sampling weights: the data are sampled from a larger population and $$w_i$$ is the reciprocal of the sampling probability for observation $$i$$.
Now, it could be that you have a 'gross error contamination' model: units are sampled from the population and measured, and something goes wrong with the measurement process sometimes. In that case, the error contamination happens at measurement time, after sampling, and your trimming shouldn't depend on the weights. You'll just need to take account of the discarded weights to rescale. If you sort by measured $$x$$, then $$\bar X = \frac{\sum_{2}^{n-1} w_ix_i}{\sum_2^{n-1} w_i}$$
On the other hand, you might just have a model that says $$x$$ is long-tailed, so that you want to reduce the impact of (correctly measured) outliers. In that case, the trimming should happen to the population variable and should depend on the weights. You still want to sort by $$x_i$$, but $$\bar X = \frac{\sum_{2}^{n-1} w^*_ix_i}{\sum_2^{n-1} w^*_i}$$ where $$w^*_i$$ are defined to remove the first 1/nth and last 1/nth from the weights. If $$w_1$$ (after ordering by $$x$$) is greater than $$1/n$$, $$w^*_1=w_1-1/n$$, otherwise $$w^*_1=0$$ and $$w^*_2$$ gets reduced as well. You're estimating the population $$\alpha$$-trimmed mean functional $$\int_\alpha^{1-\alpha} x\, d\mathbb{F}(x)$$, with $$\alpha=1/n$$.
With frequency weights (as in @gung's comment), the 'gross error' idea doesn't really make sense. If you have $$w_i$$ identical observations it's unlikely that they are contaminated by gross errors. Errors would be more likely to give you single observations. Even the model of long-tailed $$x$$ is a bit strange with frequency weights, since long tails will tend to give you unique observations in the tails. If you did have frequency weights, you'd probably want to treat them like the second case of sampling weights, but you'd also probably want to look carefully at what was going on.