BCompare groups · Guide test 012
Yuen trimmed mean test
Compares trimmed means using Winsorized variance estimates to reduce sensitivity to extreme observations.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Yuen's trimmed-means t-test (independent or paired) — Do two groups (or two paired measurements) differ in their trimmed means?
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
Your data
Drag a point or use ↑/↓ to change itIf H₀ were true
- The reference: how t varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .599).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- 20% trimmed mean
- winsorized variance
- 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 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
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.
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))
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.7Sources
- WRS2 — WRS2 · yuenAuthor documentation/source reviewed: WRS2 1.1-7.search.r-project.org
- SciPy independent t testsdocs.scipy.org
- yuensearch.r-project.org
- scipy.stats.ttest_inddocs.scipy.org
- 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.