Skip to content

BCompare groups · Guide test 011

Welch t test

Compares two independent means while allowing unequal variances and sample sizes.

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 · Welch t test

20
25
0.60
1.0
1.8
0.050

Alternative

The statistic's distribution if the design's true effect is real.

Your data

Drag a point or use ↑/↓ to change it
Group 1 · n = 20 · mean 0.96Group 2 · n = 25 · mean −0.10

If H₀ were true

t = 2.60
  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 = .013).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

t=xˉ1−xˉ2s12/n1+s22/n2,ν=(a+b)2a2/(n1−1)+b2/(n2−1)t = \dfrac{\bar x_1-\bar x_2}{\sqrt{s_1^2/n_1+s_2^2/n_2}},\qquad \nu = \dfrac{(a+b)^2}{a^2/(n_1-1)+b^2/(n_2-1)}

With your numbers

t=0.96−(−0.10)1.022/20+1.702/25=2.60,ν=40.28t = \dfrac{0.96-(-0.10)}{\sqrt{1.02^2/20+1.70^2/25}} = 2.60,\qquad \nu = 40.28
xˉ1,xˉ2\bar x_1, \bar x_2
the group means
s1,s2s_1, s_2
each group's own SD (no pooling)
a=s12/n1, b=s22/n2a = s_1^2/n_1,\ b = s_2^2/n_2
the two squared standard errors
ν\nu
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 H0.

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

t=xˉ1−xˉ2−Δ0a+b,ν=(a+b)2a2/(n1−1)+b2/(n2−1)a=s12/n1, b=s22/n2\begin{gathered}t=\frac{\bar x_1-\bar x_2-\Delta_0}{\sqrt{a+b}},\qquad \nu=\frac{(a+b)^2}{a^2/(n_1-1)+b^2/(n_2-1)}\\[5pt] a=s_1^2/n_1,\ b=s_2^2/n_2\end{gathered}

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.

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)
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))
R

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.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 011, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT011.