Skip to content

BCompare groups · Guide test 014

Welch ANOVA

Tests equality of several means without requiring equal group variances.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with one of these methods:

In One-way ANOVA (Welch / classic), choose Test = Welch's ANOVA.

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 ANOVA

3
12
0.50

Group i has true mean (i − 1) × spread.

2.50
0.050

Your data

Drag a point or use ↑/↓ to change it
Group 1 · n = 12 · mean −0.45Group 2 · n = 12 · mean 0.62Group 3 · n = 12 · mean 0.46

If H₀ were true

F = 2.63
  1. The reference: how F 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 = .097).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

F∗=∑iwi(xˉi−x~)2/(k−1)1+2(k−2)k2−1∑i(1−wi/W)2ni−1,wi=nisi2F^* = \dfrac{\sum_i w_i(\bar x_i-\tilde x)^2/(k-1)}{1+\frac{2(k-2)}{k^2-1}\sum_i \frac{(1-w_i/W)^2}{n_i-1}},\qquad w_i = \dfrac{n_i}{s_i^2}

With your numbers

F∗=2.63,ν1=2, ν2=19.90F^* = 2.63,\qquad \nu_1 = 2,\ \nu_2 = 19.90
wiw_i
precision weight of group i (size over variance)
x~\tilde x
the precision-weighted grand mean
WW
the sum of the weights

The verdict

F(2, 19.90) = 2.63, p = .097

p > α = .050: compatible with H₀

Groups with noisy data get less weight, so one wide group cannot inflate F. Prefer it to the classic F whenever spreads may differ.

Statistic
2.628
p-value
0.0971
Welch ANOVA on Group 1: n = 12; Group 2: n = 12; Group 3: n = 12: F(2, 19.90) = 2.63, p = .097. The p-value is above α = .050, so the data are compatible with H0.

Welch ANOVA on Group 1: n = 12; Group 2: n = 12; Group 3: n = 12: F(2, 19.90) = 2.63, p = .097. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: all k independent population means are equal; H1: some differ.

Assumptions

Independent groups with finite variances and enough observations to estimate them. Unequal variances are allowed. Approximation is most defensible for normal or moderately well behaved samples.

Formula

wj=nj/sj2, W=∑jwj, xˉw=∑jwjxˉj/W, B=∑j(1−wj/W)2nj−1FW=∑jwj(xˉj−xˉw)2/(k−1)1+2(k−2)B/(k2−1)ν2=k2−13B\begin{gathered}w_j=n_j/s_j^2,\ W=\sum_jw_j,\ \bar x_w=\sum_jw_j\bar x_j/W,\ B=\sum_j\frac{(1-w_j/W)^2}{n_j-1}\\[5pt] F_W=\frac{\sum_jw_j(\bar x_j-\bar x_w)^2/(k-1)}{1+2(k-2)B/(k^2-1)}\\[5pt] \nu_2=\frac{k^2-1}{3B}\end{gathered}

Parameters and notation

wj are inverse mean variance weights; B produces the finite sample adjustment; numerator degrees of freedom are k−1.

Structure of the method

Compute inverse estimated mean-variance weights, a precision-weighted common mean, and a corrected between-group quadratic form. The Welch correction and denominator degrees of freedom depend on group sizes and weight leverage. Evaluate the resulting F reference using fractional degrees of freedom rather than rounding them.

Estimated and nuisance parameters

Estimate each group mean, variance, and its resulting precision weight. The weighted common mean is a null comparison construct and generally differs from the sample-size-weighted grand mean. The number of groups and the equality-of-means restriction define the tested subspace, not an optimization-selected cluster count.

Settings and design choices

Choose alpha, the mean estimand, a prespecified transformation if needed, and subsequent unequal-variance contrasts. Solver tuning is unnecessary for the closed-form statistic. If robust trimming is desired, use its proper Winsorized-variance extension and explicitly change the estimand rather than silently trimming then applying this formula.

Fitting and adaptation

Recompute all group weights, the common mean, and degrees of freedom when samples change. Refitting is statistical recalculation rather than neural fine-tuning. A simulation-based calibration should reproduce group-specific null variances and sample allocation; unrestricted pooled permutation is not generally exact when group distributions differ under equal means.

Sensitivity and robustness

Small noisy groups may produce uncertain precision estimates, and zero variance causes singular weighting. Severe skew or heavy tails can degrade the F approximation even though variances are allowed to differ. Report group summaries and intervals; omnibus rejection alone does not establish monotonicity or pairwise significance.

How to use and calibrate

Compute FW and compare with Fk−1,ν2. If individual group differences are needed, use contrasts that also allow unequal variances, such as Games–Howell for pairwise comparisons.

Example application

Compare mean response across four independent groups with markedly different standard deviations and sample sizes.

Interpretation and pitfalls

Watch out

Tiny or zero variance groups can dominate inverse variance weighting. This is not a robust outlier method and does not address dependent observations.

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

Omnibus test across independent groups; use the model assumptions in this entry and plan multiplicity-adjusted follow-up comparisons.

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(__import__("statsmodels.stats.oneway",fromlist=["anova_oneway"]).anova_oneway(groups,use_var="unequal"))
Output
AnovaResult(statistic=np.float64(11.781776709790458), pvalue=np.float64(0.00011085753537703958), df=(2.0, np.float64(36.825494297940246)), df_num=2.0, df_denom=np.float64(36.825494297940246), nobs_total=np.float64(60.0), n_groups=3, means=array([-0.09684371,  0.61021021,  1.38121647]), nobs=array([20., 20., 20.]), vars_=array([0.54821158, 0.81067911, 1.38385309]), use_var='unequal', welch_correction=True, df2=None, df_num2=None, pvalue2=None)
R

Validated — Executed successfully in the validation environment · needs Base/standard library

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(oneway.test(value~group,d,var.equal=FALSE))
Output
	One-way analysis of means (not assuming equal variances)

data:  value and group
F = 7.9191, num df = 2.00, denom df = 37.82, p-value = 0.001341

Sources

Statistics guide v4 (historical):
Python: Executed successfully in the validation environment · R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Unavailable local dependencies: statsmodels. Python: Not run in the reference's review: Unavailable local dependencies: statsmodels. No installation attempted. R: Reviewed but not run: R wasn't available to the reference's authors.

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