Skip to content

BCompare groups · Guide test 012

Yuen trimmed mean test

Compares trimmed means using Winsorized variance estimates to reduce sensitivity to extreme observations.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Yuen trimmed mean test

20
22
0.80
1.0
1.6
0.050

Your data

Drag a point or use ↑/↓ to change it
Group 1 · n = 20 · mean 0.90Group 2 · n = 22 · mean 0.39

If H₀ were true

t = 0.54
  1. The reference: how t varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .599).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

t=xˉt1−xˉt2d1+d2,dj=(nj−1)swj2hj(hj−1)t = \dfrac{\bar x_{t1}-\bar x_{t2}}{\sqrt{d_1+d_2}},\qquad d_j = \dfrac{(n_j-1)s^2_{wj}}{h_j(h_j-1)}

With your numbers

t=0.82−0.520.56=0.54,ν=16.87t = \dfrac{0.82-0.52}{0.56} = 0.54,\qquad \nu = 16.87
xˉtj\bar x_{tj}
20% trimmed mean
swj2s^2_{wj}
winsorized variance
hjh_j
observations left after trimming

The verdict

t(16.87) = 0.54, p = .599, Δ_tr = 0.30

p > α = .050: compatible with H₀

Effect size: difference in 20% trimmed means Δ_tr = 0.301

Trimming makes the comparison resistant to outliers and heavy tails while keeping most of a t test's power. The estimand is the trimmed mean, not the mean.

Statistic
0.536
p-value
0.5992
Yuen trimmed mean test on Group 1: n = 20; Group 2: n = 22: t(16.87) = 0.54, p = .599, Δ_tr = 0.30. The p-value is above α = .050, so the data are compatible with H0.

Yuen trimmed mean test on Group 1: n = 20; Group 2: n = 22: t(16.87) = 0.54, p = .599, Δ_tr = 0.30. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: the two population γ trimmed means are equal; H1: they differ.

Assumptions

Independent samples and a prespecified trimming fraction 0≤γ<1/2. The target is a trimmed mean. Sufficient observations must remain after trimming; approximate inference relies on regularity around the trimming quantiles.

Formula

gj=⌊γnj⌋, hj=nj−2gj, dj=(nj−1)sWj2hj(hj−1)tY=xˉt1−xˉt2d1+d2ν=(d1+d2)2d12/(h1−1)+d22/(h2−1)\begin{gathered}g_j=\lfloor\gamma n_j\rfloor,\ h_j=n_j-2g_j,\ d_j=\frac{(n_j-1)s_{Wj}^2}{h_j(h_j-1)}\\[5pt] t_Y=\frac{\bar x_{t1}-\bar x_{t2}}{\sqrt{d_1+d_2}}\\[5pt] \nu=\frac{(d_1+d_2)^2}{d_1^2/(h_1-1)+d_2^2/(h_2-1)}\end{gathered}

Parameters and notation

x̄t1 and x̄t2 are group trimmed means; sWj² is variance after replacing each trimmed tail by its nearest retained value, computed with denominator nj−1.

Structure of the method

Sort each group, remove an equal prespecified fraction from both tails for the mean, and Winsorize rather than delete those tails when estimating variability. Retained sample sizes and Winsorized variances form a Welch-like standard error and degrees of freedom. Ordinary t testing of the shortened vectors is not equivalent.

Estimated and nuisance parameters

Estimate two population trimmed means and their variance estimates from Winsorized observations. The retained counts depend deterministically on original sizes and the chosen trimming fraction. The trim fraction itself is a design choice, and the estimand differs from the ordinary population mean whenever tails are asymmetric or influential.

Settings and design choices

Choose trimming, sidedness, alpha, bootstrap versus analytic calibration, and integer versus fractional trimming convention. A conventional twenty-percent trim is an illustration, not a universal optimum. Record the number retained per group; apparently equal fractions can yield different effective trimming in small samples because of flooring.

Fitting and adaptation

Refit trimmed means and Winsorized scale together after any sample change. Resampling must recalculate trimming and Winsorization inside every replicate. For a new population, reconsider whether tail values are contamination or the scientific phenomenon; changing the trim fraction changes the hypothesis rather than simply fine-tuning precision.

Sensitivity and robustness

Too few retained cases make variance estimates unstable or undefined. Masses at trimming cutoffs and discrete outcomes complicate asymptotic regularity. Trimming can conceal important rare harms or tail effects even while improving central-location robustness. Report both the robust target and descriptive tail information when scientifically relevant.

How to use and calibrate

Choose γ before analysis, sort each group, trim gj observations from each end for its mean, Winsorize for variance, and compare tY with tν. Bootstrap calibration is another option when implemented for this estimand.

Example application

Compare typical values from two independent heavy tailed populations using a prespecified 20% trimmed mean.

Interpretation and pitfalls

Watch out

This is not a test of ordinary means, and trimming can remove scientifically important tail differences. The Winsorized variance and retained sample size must both appear in the standard error.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Twenty percent is trimmed from each tail. Inference concerns population trimmed means.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
groups = [rng.normal(m,1,20) for m in (0,.4,.8)]
print(stats.ttest_ind(groups[0],groups[1],equal_var=False,trim=.2))
Output
TtestResult(statistic=np.float64(-2.4096095017592316), pvalue=np.float64(0.02681176830119894), df=np.float64(18.12201950872675))
R

Validated — Executed successfully in the validation environment · needs WRS2

set.seed(2026)
d <- data.frame(value=c(rnorm(20),rnorm(20,.4),rnorm(20,.8)), group=factor(rep(c("A","B","C"),each=20)))
print(WRS2::yuen(value~group,data=subset(d,group!="C"),tr=.2))
Output
Call:
WRS2::yuen(formula = value ~ group, data = subset(d, group != 
    "C"), tr = 0.2)

Test statistic: 3.499 (df = 20.17), p-value = 0.00224

Trimmed mean difference:  -0.97509 
95 percent confidence interval:
-1.5561     -0.3941 

Explanatory measure of effect size: 0.7

Sources

Statistics guide v4 (historical):
R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 012, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT012.