Skip to content

BCompare groups · Guide test 034

Friedman test

Tests treatment differences in complete blocks or repeated measurements using within block ranks.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

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

In Friedman test (repeated measures, ranks), choose Test = Friedman.

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 · Friedman test

10
4
0.40
1.5
0.050

Your data

Drag a point or use ↑/↓ to change it
Condition 1mean 1.17Condition 2mean 0.76Condition 3mean 1.44Condition 4mean 2.01

If H₀ were true

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

The formula

χF2=12nk(k+1)∑jRj2−3n(k+1)\chi^2_F = \dfrac{12}{nk(k+1)}\sum_j R_j^2-3n(k+1)

With your numbers

χF2=9.84,ν=3\chi^2_F = 9.84,\quad \nu = 3
RjR_j
sum over blocks of condition j's within-block rank
n, kn,\ k
blocks and conditions

The verdict

χ²(3) = 9.84, p = .020

p ≤ α = .050: reject H₀

Ranks within each block, so block-to-block differences vanish. The rank analog of repeated-measures ANOVA.

Statistic
9.840
p-value
0.0200
Friedman test on Condition 1: n = 10; Condition 2: n = 10; Condition 3: n = 10; Condition 4: n = 10: χ²(3) = 9.84, p = .020. The p-value is below α = .050, so the data are hard to reconcile with H0.

Friedman test on Condition 1: n = 10; Condition 2: n = 10; Condition 3: n = 10; Condition 4: n = 10: χ²(3) = 9.84, p = .020. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: treatments have identical effects/distributions within complete blocks.

Assumptions

Independent blocks; all k treatments measured in every block; exchangeability within blocks under the null. Additive comparable shapes support a location interpretation.

Formula

Q=12bk(k+1)∑j[Rj−b(k+1)/2]2Q=\frac{12}{bk(k+1)}\sum_j[R_j-b(k+1)/2]^2

Parameters and notation

b is the block count; Rij ranks treatment j within block i; Rj=ΣiRij. Apply the standard within block tie correction.

Structure of the method

Rank treatments separately inside each complete block, sum ranks by treatment, and compare their dispersion with the no-effect center. Within-block tie corrections modify the scaling. Independent permutations of treatment labels inside blocks generate the design-respecting null; the familiar chi-square reference is an approximation for larger suitable layouts.

Estimated and nuisance parameters

Computed quantities are within-block ranks, treatment rank totals, and tie multiplicities. Block-level shifts are removed by ranking rather than explicitly estimated as mean parameters. The block and treatment identifiers are fixed design information, and the effective independent replication is the number of blocks, not the number of cells.

Settings and design choices

Choose alpha, complete-case versus another justified missing-data strategy, asymptotic or block-permutation calibration, and simultaneous follow-up comparisons. A blocked Nemenyi or other rank comparison must use the correct blocked denominator. Selecting only favorable blocks after viewing rankings changes the experiment and its error control.

Fitting and adaptation

Recompute each block's ranks after correcting measurements or treatment assignments. If an observation is missing, do not rank a shortened block and insert it into the complete-block formula; use a suitable incomplete-block method. For new blocks, preserve the treatment definition and evaluate whether blocks remain independent and comparable.

Sensitivity and robustness

Few blocks, few treatments, or extensive ties can make chi-square calibration inaccurate. Treating datasets or participants as independent blocks requires substantive justification. An omnibus rejection concerns treatment differences somewhere; it does not identify a universal winner or show every pair differs. Rank invariance also discards magnitude information.

How to use and calibrate

Use χ²k−1 approximately or independently permute treatment labels within each block.

Example application

Compare four algorithms on the same collection of independent datasets.

Interpretation and pitfalls

Watch out

Do not use independent group ranks. Rejection is omnibus; pairwise follow-ups need multiplicity control.

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

Rows are subjects/blocks and columns are treatments. Page uses the prespecified increasing column order.

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)
b = rng.normal(size=(12,3)) + np.array([0,.3,.7])
print(stats.friedmanchisquare(*b.T))
Output
FriedmanchisquareResult(statistic=np.float64(0.6666666666666572), pvalue=np.float64(0.7165313105737927))
R

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

set.seed(2026)
b <- matrix(rnorm(36)+rep(c(0,.3,.7),each=12),nrow=12,ncol=3)
print(friedman.test(b))
Output
	Friedman rank sum test

data:  b
Friedman chi-squared = 14, df = 2, p-value = 0.0009119

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