---
title: "TrimmedMean"
language: "en"
type: "Symbol"
summary: "TrimmedMean[list, f] gives the mean of the elements in list after dropping a fraction f of the smallest and largest elements. TrimmedMean[list, {f1, f2}] gives the mean when a fraction f1 of the smallest elements and a fraction f2 of the largest elements are removed. TrimmedMean[list] gives the 5% trimmed mean TrimmedMean[list, 0.05]. TrimmedMean[dist, ...] gives the trimmed mean of a univariate distribution dist."
keywords: 
- location statistic
- modified arithmetic mean
- modified mean
- robust estimate
- robust location estimate
- truncated mean
canonical_url: "https://reference.wolfram.com/language/ref/TrimmedMean.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Descriptive Statistics"
    link: "https://reference.wolfram.com/language/guide/DescriptiveStatistics.en.md"
  - 
    title: "Statistical Moments and Generating Functions"
    link: "https://reference.wolfram.com/language/guide/StatisticalMomentsAndGeneratingFunctions.en.md"
  - 
    title: "Robust Descriptive Statistics"
    link: "https://reference.wolfram.com/language/guide/RobustDescriptiveStatistics.en.md"
  - 
    title: "Date & Time"
    link: "https://reference.wolfram.com/language/guide/DateAndTime.en.md"
related_functions: 
  - 
    title: "Mean"
    link: "https://reference.wolfram.com/language/ref/Mean.en.md"
  - 
    title: "Quantile"
    link: "https://reference.wolfram.com/language/ref/Quantile.en.md"
  - 
    title: "TrimmedVariance"
    link: "https://reference.wolfram.com/language/ref/TrimmedVariance.en.md"
  - 
    title: "WinsorizedMean"
    link: "https://reference.wolfram.com/language/ref/WinsorizedMean.en.md"
  - 
    title: "Median"
    link: "https://reference.wolfram.com/language/ref/Median.en.md"
  - 
    title: "BiweightLocation"
    link: "https://reference.wolfram.com/language/ref/BiweightLocation.en.md"
  - 
    title: "WinsorizedVariance"
    link: "https://reference.wolfram.com/language/ref/WinsorizedVariance.en.md"
  - 
    title: "MeanShiftFilter"
    link: "https://reference.wolfram.com/language/ref/MeanShiftFilter.en.md"
related_tutorials: 
  - 
    title: "Descriptive Statistics"
    link: "https://reference.wolfram.com/language/tutorial/NumericalOperationsOnData.en.md#7135"
---
# TrimmedMean

TrimmedMean[list, f] gives the mean of the elements in list after dropping a fraction f of the smallest and largest elements.

TrimmedMean[list, {f1, f2}] gives the mean when a fraction f1 of the smallest elements and a fraction f2 of the largest elements are removed.

TrimmedMean[list] gives the 5% trimmed mean TrimmedMean[list, 0.05].

TrimmedMean[dist, …] gives the trimmed mean of a univariate distribution dist.

## Details

* ``TrimmedMean`` gives a robust estimate of the mean by excluding extreme values.

* The trimming fraction is determined by the parameters Subscript[``f``, 1] and Subscript[``f``, 2], which indicate the fraction ``f1`` of the smallest elements and the fraction ``f2`` of the largest elements to be removed.

* ``TrimmedMean[list, {f1, f2}]`` gives the mean of ``Sort[list, Less][[1 + ⌊f1 n⌋ ;; n - ⌊f2 n⌋]]``, where ``n`` equals the length of ``list``.

```wl
[image]	[image]	[image]
```

* ``TrimmedMean[{{x1, y1, …}, {x2, y2, …}, …}, f]`` gives ``{TrimmedMean[{x1, x2, …}, f], TrimmedMean[{y1, y2, …}, f], …}``.

* ``TrimmedMean[dist, {f1, f2}]`` gives ``Mean[TruncatedDistribution[Quantile[dist, {f1, 1 - f2}], dist]]`` for a univariate distribution ``dist``.

---

## Examples (23)

### Basic Examples (4)

Trimmed mean after removing extreme values:

```wl
In[1]:= TrimmedMean[{-10, 1, 1, 1, 1, 20}, 0.2]

Out[1]= 1
```

---

Trimmed mean after removing the smallest extreme values:

```wl
In[1]:= TrimmedMean[{-10, 1, 1, 1, 1, 20}, {0.2, 0}]

Out[1]= (24/5)
```

---

Trimmed mean of a list of dates:

```wl
In[1]:= RandomDate[6]

Out[1]= {DateObject[{2024, 4, 27, 0, 38, 46.2511}, "Instant", "Gregorian", -5.], DateObject[{2024, 10, 20, 22, 2, 27.031}, "Instant", "Gregorian", -5.], DateObject[{2024, 3, 4, 22, 39, 17.0503}, "Instant", "Gregorian", -5.], DateObject[{2024, 12, 25, 22, 58, 29.8844}, "Instant", "Gregorian", -5.], DateObject[{2024, 1, 5, 21, 48, 15.1744}, "Instant", "Gregorian", -5.], DateObject[{2024, 12, 26, 0, 51, 44.2641}, "Instant", "Gregorian", -5.]}

In[2]:= TrimmedMean[%]

Out[2]= DateObject[{2024, 7, 18, 23, 9, 49.9426}, "Instant", "Gregorian", -5.]
```

---

Trimmed mean of a symbolic distribution:

```wl
In[1]:= TrimmedMean[ExponentialDistribution[λ]]

Out[1]= (18 - 19 Log[19] + 18 Log[20]/18 λ)
```

### Scope (10)

#### Data (9)

Exact input yields exact output:

```wl
In[1]:= TrimmedMean[{1, 20, 3, 4}, 2 / 5]

Out[1]= (7/2)

In[2]:= TrimmedMean[{Sqrt[2], E, Pi, Pi ^ 2, 1, 2, 3}, 1 / 4]

Out[2]= (1/5) (5 + Sqrt[2] + E + π)
```

---

Approximate input yields approximate output:

```wl
In[1]:= TrimmedMean[{5., 10., 4., 25., 2., 1.}, 0.2]

Out[1]= 5.25

In[2]:= TrimmedMean[N[{5, 10, 4, 25, 2, 1}, 30], 0.2]

Out[2]= 5.25000000000000000000000000000
```

---

``TrimmedMean`` for a matrix gives columnwise means:

```wl
In[1]:= TrimmedMean[RandomReal[1, {50, 2}], .1]

Out[1]= {0.505479, 0.380264}
```

---

Trimmed mean works with large arrays:

```wl
In[1]:= TrimmedMean[RandomReal[1, 10 ^ 6], 1 / 100]

Out[1]= 0.500205

In[2]:= TrimmedMean[RandomReal[1, {10 ^ 5, 5}]]

Out[2]= {0.500179, 0.499209, 0.500229, 0.500484, 0.499184}
```

---

``SparseArray`` data can be used just like dense arrays:

```wl
In[1]:= sp = SparseArray[{{i_, i_} :> i, {i_, j_} /; j == i + 1 :> i - 1}, {100, 10}, 1];

In[2]:= TrimmedMean[sp]

Out[2]= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
```

---

Trimmed mean of a ``TimeSeries`` :

```wl
In[1]:=
ts = TemporalData[TimeSeries, {{{3, 8, 4, 11, 9, 2}}, {{{1, 3, 5, 7, 8, 10}}}, 1, {"Continuous", 1}, 
  {"Discrete", 1}, 1, {ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, False, 
 10.1];

In[2]:= TrimmedMean[ts, 1 / 6]//N

Out[2]= 6.
```

Trimmed mean depends only on the values:

```wl
In[3]:= TrimmedMean[ts["Values"], 1 / 6]//N

Out[3]= 6.
```

---

Trimmed mean works with data involving quantities:

```wl
In[1]:= data = Quantity[RandomReal[1, 6], "Meters"]

Out[1]= {Quantity[0.569715, "Meters"], Quantity[0.165186, "Meters"], Quantity[0.952671, "Meters"], Quantity[0.855585, "Meters"], Quantity[0.981888, "Meters"], Quantity[0.0222484, "Meters"]}

In[2]:= TrimmedMean[data]

Out[2]= Quantity[0.591216, "Meters"]
```

---

Compute trimmed mean of dates:

```wl
In[1]:= dates = WolframLanguageData[All, "DateIntroduced"];

In[2]:= DateHistogram[dates]

Out[2]= [image]

In[3]:= TrimmedMean[dates]

Out[3]= DateObject[{2009, 9, 25}, "Day"]
```

---

Compute trimmed mean of times:

```wl
In[1]:= RandomTime[3]

Out[1]= {TimeObject[{0, 23, 47.6431}, "Instant"], TimeObject[{6, 41, 35.8222}, "Instant"], TimeObject[{22, 56, 48.0332}, "Instant"]}

In[2]:= TrimmedMean[%]

Out[2]= TimeObject[{10, 0, 43.8328}, "Instant", -5.]
```

List of times with different time zone specifications:

```wl
In[3]:= {TimeObject[{12}, TimeZone -> 0], TimeObject[{12}, TimeZone -> 2], TimeObject[{12}, TimeZone -> "Asia/Tokyo"]}

Out[3]= {TimeObject[{12}, "Hour", 0.], TimeObject[{12}, "Hour", 2.], TimeObject[{12}, "Hour", "Asia/Tokyo"]}

In[4]:= TrimmedMean[%]

Out[4]= TimeObject[{1, 20, 0}, "Instant", "Asia/Tokyo"]

In[5]:= %["TimeZone"]

Out[5]= "Asia/Tokyo"
```

#### Distributions (1)

The trimmed mean for a univariate distribution:

```wl
In[1]:= TrimmedMean[NormalDistribution[1.3, .2]]

Out[1]= 1.3

In[2]:= TrimmedMean[BinomialDistribution[10, 1 / 2]]

Out[2]= (1640/319)

In[3]:= TrimmedMean[WeibullDistribution[α, β]]

Out[3]=
(10/9) (Piecewise[{{β*(Gamma[1 + 1/α, Log[20/19]] - Gamma[1 + 1/α, Log[20]]), 
   Log[20/19]^(1/α) > 0 && Log[20/19]^(1/α) - Log[20]^(1/α) < 0 && β > 0}}, 0])
```

### Applications (3)

Obtain a robust estimate of location when outliers are present:

```wl
In[1]:= TrimmedMean[{1, 5, 2, 6, 10, 10 ^ 5, 5, 4, -200, 5}, .1]//N

Out[1]= 4.75
```

Extreme values have a large influence on the ``Mean`` :

```wl
In[2]:= Mean[{1, 5, 2, 6, 10, 10 ^ 5, 5, 4, -200, 5}]//N

Out[2]= 9983.8
```

---

Simulate a trajectory with heavy-tailed measurement noise:

```wl
In[1]:=
n[] := RandomVariate[CauchyDistribution[0, 1.2]]
f[] := {u Cos[u] + n[], u Sin[u] + n[]};
data = Table[f[], {u, 0, 6π, 1 / 100}];
```

The underlying signal and simulated path with noise:

```wl
In[2]:= {ParametricPlot[{u Cos[u], u Sin[u]}, {u, 0, 6π}], pd = ListPlot[data, AspectRatio -> 1]}

Out[2]= {[image], [image]}
```

Smooth the trajectory using a moving ``TrimmedMean`` :

```wl
In[3]:= td = TimeSeries[data, {0., 6π}, ValueDimensions -> 2];

In[4]:= smooth[r_] := MovingMap[TrimmedMean, td, {Quantity[r, "Events"], Center}, "ReflectedDifferences"]
```

Increasing the block size gives a smoother trajectory:

```wl
In[5]:= Quiet@Table[ParametricPlot[Evaluate[smooth[r]["PathFunction"][t]], {t, 0, 6π}], {r, {25, 50, 100}}]

Out[5]= {[image], [image], [image]}
```

---

Find a trimmed mean for the heights of children in a class:

```wl
In[1]:=
heights = Quantity[{134, 143, 131, 140, 145, 136, 131, 136, 143, 136, 133, 145, 147, 
	        150, 150, 146, 137, 143, 132, 142, 145, 136, 144, 135, 141}, "Centimeters"];

In[2]:= ListPlot[heights, Filling -> Axis, AxesLabel -> Automatic]

Out[2]= [image]

In[3]:= TrimmedMean[heights]//N

Out[3]= Quantity[140., "Centimeters"]
```

Compare a few trimmed means:

```wl
In[4]:= (tmeans = Table[TrimmedMean[heights, f], {f, {.05, .2, .45}}])//N

Out[4]= {Quantity[140., "Centimeters"], Quantity[140.13333333333333, "Centimeters"], Quantity[141., "Centimeters"]}

In[5]:=
n = Length[heights];
ListPlot[Join[{heights}, Table[{{0, m}, {n, m}}, {m, tmeans}]], Joined -> {False, True, True, True}, Filling -> {1 -> 0}, AxesLabel -> Automatic, PlotLegends -> {"heights", .05, .2, .45}]

Out[5]= [image]
```

Plot the trimmed mean as a function of trimmed fraction:

```wl
In[6]:= trimMean[f_ ? NumericQ] /; 0 ≤ f < 0.5 := TrimmedMean[heights, f]

In[7]:= Plot[trimMean[f], {f, 0, 0.49}, AxesLabel -> {f}]

Out[7]= [image]
```

### Properties & Relations (5)

A 0% ``TrimmedMean`` is equivalent to ``Mean`` :

```wl
In[1]:= TrimmedMean[Range[10], 0]

Out[1]= (11/2)

In[2]:= Mean[Range[10]]

Out[2]= (11/2)
```

---

``TrimmedMean`` approaches ``Median`` as ``f`` approaches 1/2:

```wl
In[1]:= data = RandomVariate[CauchyDistribution[0, 1], 1000];

In[2]:= md = Median[data]

Out[2]= -0.0112343

In[3]:= Plot[{TrimmedMean[data, f], md}, {f, 0.1, .499}, AxesLabel -> {f}]

Out[3]= [image]
```

---

``TrimmedMean`` of a distribution is the mean of its ``TruncatedDistribution`` :

```wl
In[1]:= \[ScriptCapitalD]  = NormalDistribution[a, b];

In[2]:= TrimmedMean[\[ScriptCapitalD], {.5, 0}]

Out[2]= 0.56419 (1.77245 a + 1.41421 b)
```

Mean of the ``TruncatedDistribution`` with appropriate bounds:

```wl
In[3]:= td = TruncatedDistribution[Quantile[\[ScriptCapitalD], {.5, 1}], \[ScriptCapitalD]];

In[4]:= Mean[td]

Out[4]= 0.56419 (1.77245 a + 1.41421 b)
```

---

``TrimmedMean`` of a sample gives an estimate of the mean of a truncated distribution:

```wl
In[1]:=
\[ScriptCapitalD]  = NormalDistribution[];
data = RandomVariate[\[ScriptCapitalD], 10 ^ 6];

In[2]:= TrimmedMean[data, {.5, 0}]

Out[2]= 0.799639
```

Mean of the ``TruncatedDistribution`` with appropriate bounds:

```wl
In[3]:= td = TruncatedDistribution[Quantile[\[ScriptCapitalD], {.5, 1}], \[ScriptCapitalD]];

In[4]:= Mean[td]

Out[4]= 0.797885
```

---

``TrimmedMean`` drops the data beyond a certain quantile level, then computes the sample mean:

```wl
In[1]:=
len = 100;
f = 1 / 10;
data = RandomReal[1, len];

In[2]:= data1 = Part[Sort[data], 1 + Floor[len f] ;; len - Floor[len f]];

In[3]:= TrimmedMean[data, f] == Mean[data1]

Out[3]= True
```

``WinsorizedMean`` clips the data beyond a certain quantile level, then computes the sample mean:

```wl
In[4]:= data2 = Clip[data, {RankedMin[data, 1 + Floor[len f]], RankedMax[data, 1 + Floor[len f]]}];

In[5]:= WinsorizedMean[data, f] == Mean[data2]

Out[5]= True
```

Plot the sorted data against the sample with elements removed and the clipped sample:

```wl
In[6]:=
d0 = Transpose[{Range[1, len], Sort@data}];
d1 = Transpose[{Range[1 + Floor[len f], len - Floor[len f]], data1}];
d2 = Transpose[{Range[1, len], Sort@data2}];

In[7]:= ListPlot[{d0, d1, d2}, Filling -> {2 -> 0}, PlotLegends -> {"data", "data1", "data2"}]

Out[7]= [image]
```

### Possible Issues (1)

``TrimmedMean`` requires numeric values:

```wl
In[1]:= TrimmedMean[{a, b, c}, .1]
```

TrimmedMean::arg1: The first argument {a,b,c} is expected to be a numeric vector or matrix.

```wl
Out[1]= TrimmedMean[{a, b, c}, 0.1]
```

## See Also

* [`Mean`](https://reference.wolfram.com/language/ref/Mean.en.md)
* [`Quantile`](https://reference.wolfram.com/language/ref/Quantile.en.md)
* [`TrimmedVariance`](https://reference.wolfram.com/language/ref/TrimmedVariance.en.md)
* [`WinsorizedMean`](https://reference.wolfram.com/language/ref/WinsorizedMean.en.md)
* [`Median`](https://reference.wolfram.com/language/ref/Median.en.md)
* [`BiweightLocation`](https://reference.wolfram.com/language/ref/BiweightLocation.en.md)
* [`WinsorizedVariance`](https://reference.wolfram.com/language/ref/WinsorizedVariance.en.md)
* [`MeanShiftFilter`](https://reference.wolfram.com/language/ref/MeanShiftFilter.en.md)

## Tech Notes

* [Descriptive Statistics](https://reference.wolfram.com/language/tutorial/NumericalOperationsOnData.en.md#7135)

## Related Guides

* [Descriptive Statistics](https://reference.wolfram.com/language/guide/DescriptiveStatistics.en.md)
* [Statistical Moments and Generating Functions](https://reference.wolfram.com/language/guide/StatisticalMomentsAndGeneratingFunctions.en.md)
* [Robust Descriptive Statistics](https://reference.wolfram.com/language/guide/RobustDescriptiveStatistics.en.md)
* [Date & Time](https://reference.wolfram.com/language/guide/DateAndTime.en.md)

## History

* [Introduced in 2007 (6.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn60.en.md) \| [Updated in 2017 (11.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn111.en.md) ▪ [2024 (14.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn141.en.md)