BCompare groups · Guide test 011
Welch t test
Compares two independent means while allowing unequal variances and sample sizes.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Two-sample t-test (Welch / Student, or z test) — Do two independent groups differ in their mean?
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 · Welch t test
Alternative
The statistic's distribution if the design's true effect is real.
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 = .013).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- the group means
- each group's own SD (no pooling)
- the two squared standard errors
- Welch–Satterthwaite degrees of freedom, usually not a whole number
The verdict
t(40.28) = 2.60, p = .013, d = 0.74
p ≤ α = .050: reject H₀
Effect size: Cohen's d (pooled SD) d = 0.739
Each group keeps its own variance, so unequal spreads do not bias the test; the price is a few degrees of freedom. It is R's default for good reason.
- Statistic
- 2.598
- p-value
- 0.0130
Welch t test on Group 1: n = 20; Group 2: n = 25: t(40.28) = 2.60, p = .013, d = 0.74. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: μ1−μ2=Δ0; H1: the contrast differs.
Assumptions
Independent observations within and between groups. Population variances may differ. Normal samples support the Welch–Satterthwaite approximation; larger well behaved samples can support mean inference without exact normality.
Formula
Parameters and notation
a and b are estimated variances of group means; ν is generally noninteger. The reference distribution is tν.
Structure of the method
Separate group variance estimates determine the standard error of the mean contrast. A Welch–Satterthwaite calculation approximates uncertainty in that denominator with generally fractional degrees of freedom. The resulting t tail is an approximation, not an exact equal-variance Student law with merely a different denominator.
Estimated and nuisance parameters
Estimate each group mean and variance independently. The estimated variances of the means enter both the standard error and degrees-of-freedom calculation. The null difference, group labels, and alternative direction are fixed inputs. Do not round the calculated degrees of freedom before evaluating the tail.
Settings and design choices
Set the estimand, direction, confidence level, exclusion policy, and any multiple-comparison adjustment. There is no need to tune an equal-variance threshold. Sample allocation and minimum group sizes are design considerations; a large total sample cannot compensate automatically for one extremely small, highly variable group.
Fitting and adaptation
Recompute separate variances and degrees of freedom after changes to the sample. If dependence is present, replace the independent-groups variance construction with an appropriate joint model. Bootstrap alternatives should preserve group membership and target the mean difference, rather than treating pooled label permutation as universally exact.
Sensitivity and robustness
Welch handles unequal variances, but not arbitrary heavy-tailed distributions, outlier contamination, or correlated observations. Very small estimated variances and extreme variance ratios can destabilize results. Examine mean-based intervals and raw-data summaries; switching to a rank or trimmed-mean method changes the target being tested.
How to use and calibrate
Calculate separate group variances and the Welch degrees of freedom, then obtain a t tail and interval using √(a+b). Do not round ν to an integer unnecessarily.
Example application
Compare two independent mean outcomes when one group has many more observations or substantially more variability.
Interpretation and pitfalls
Watch out
Welch addresses unequal variances, not dependence, gross outliers, or an inappropriate mean estimand. It is not the paired t test and does not become a median test for skewed data.
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
Two-sided test; report the estimated mean or mean difference and its confidence interval alongside the p-value.
Validated — Executed successfully in the validation environment · needs numpy, scipy
import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
x = np.array([4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0])
y = np.array([4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9])
print(stats.ttest_ind(x,y,equal_var=False))
Output
TtestResult(statistic=np.float64(2.6255698469620965), pvalue=np.float64(0.019096993635301575), df=np.float64(15.004528301886793))
Validated — Executed successfully in the validation environment · needs Base/standard library
x <- c(4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0)
y <- c(4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9)
print(t.test(x,y,var.equal=FALSE))
Output
Welch Two Sample t-test
data: x and y
t = 2.6256, df = 15.005, p-value = 0.0191
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.1129301 1.0870699
sample estimates:
mean of x mean of y
5.3 4.7Sources
- SciPy independent t testsdocs.scipy.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 011, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT011.