Friedman test: nonparametric test for blocked data, explained

Updated

The Friedman test compares three or more treatments when each treatment is applied to the same set of blocks: the same machines, operators, batches of material or test panels. It ranks the treatments within each block, so differences between blocks drop out, and then asks whether some treatment consistently ranks higher than the others. It is the rank-based version of a two-way ANOVA without replication, and it extends the paired comparison of the Wilcoxon signed-rank test to more than two treatments.

When to use it

  • Each of several treatments (fluids, tools, recipes, methods) is tried on each of several blocks, and the blocks differ a lot from each other.
  • The data are skewed, contain outliers or are ordinal (for example, panel scores where each judge scores every sample).
  • You want a simple, robust check before or instead of a two-way ANOVA or a general linear model.
  • If the groups are independent (different units in each group), use Kruskal–Wallis instead.

How it works

With k treatments and b blocks, one observation per treatment per block:

  • H₀: the treatments have the same effect (within each block, every ordering of the treatments is equally likely).
  • H₁: at least one treatment tends to give larger or smaller values than the others.

Steps:

  1. Within each block, rank the k values from 1 to k. Tied values in a block share the average rank.
  2. Add up each treatment's ranks over all blocks: R₁ … Rₖ. Under H₀, each should be close to b(k + 1)/2.
  3. Compute the Friedman statistic:
S = 12 / (b · k · (k + 1)) · Σ Rⱼ² − 3b(k + 1)
  1. With ties within blocks, divide by a correction, where t is the size of each group of ties inside a block:
S_adj = S / ( 1 − Σ(t³ − t) / (b · k · (k² − 1)) )

Under H₀, S is close to a chi-square distribution with k − 1 degrees of freedom. The p-value is the upper tail. The approximation is reasonable when b × k is above about 30, or b is above about 10; for smaller designs it is approximate.

A useful companion is Kendall's coefficient of concordance, W = S/(b(k − 1)), which runs from 0 (blocks disagree completely on the order) to 1 (every block ranks the treatments the same way).

Assumptions: blocks are independent of each other; within a block, the treatments are measured under comparable conditions; no interaction that reverses the treatment order from block to block.

Example

A machining plant wants to choose among four cutting fluids (A, B, C and D) for a turning operation. Tool life varies a lot from one lathe to another because of spindle condition and part mix, so the engineer runs each fluid on each of six lathes, in a random order on each lathe. The response is tool life in parts per insert edge:

LatheFluid AFluid BFluid CFluid D
1212236205248
2318341322352
3265270251290
4190214188207
5402420395431
6288301301316
Tool life by cutting fluid on each lathe200300400Tool life (parts per edge)Lathe 1Lathe 2Lathe 3Lathe 4Lathe 5Lathe 6Fluid AFluid BFluid CFluid DCutting fluid
Tool life by cutting fluid on each lathe

Ranks within each lathe (1 = shortest life):

LatheABCD
12314
21324
32314
42413
52314
612.52.54
Rank sum1018.58.523
  • With b = 6 and k = 4, the expected rank sum under H₀ is 6 × 5/2 = 15.
  • S = 12/(6 × 4 × 5) × (10² + 18.5² + 8.5² + 23²) − 3 × 6 × 5 = 14.35.
  • One tie (lathe 6), so S_adj = 14.35/(1 − 6/360) = 14.59.
  • df = 4 − 1 = 3, p-value = 0.0022.
  • Kendall's W = 14.59/(6 × 3) = 0.81: the lathes agree strongly on the order of the fluids.

For comparison, a Kruskal–Wallis test that ignores the lathes gives p = 0.84. The spread between lathes (from about 190 to 430 parts) hides the fluid effect completely unless each lathe is compared with itself.

How to read the results

  • The p-value of 0.0022 says the fluids do not all give the same tool life.
  • The rank sums show the order. Fluid D ranks first on five of six lathes, fluid B second; fluids A and C are at the bottom.
  • In shop terms, fluid D's median tool life is 303 parts against about 276 for A and C, roughly a 10% gain in parts per edge. Whether that pays depends on fluid cost and concentration control. A paired comparison of D against the current fluid, lathe by lathe, gives the size of the gain with an interval.
  • The test does not say which pairs differ. For that, follow up with pairwise comparisons of rank sums (with a multiple-comparison adjustment) or Wilcoxon signed-rank tests on the paired differences.

Common mistakes

  • Ignoring the blocks. Treating the 24 results as four independent groups, as in the Kruskal–Wallis comparison above, buries the treatment effect under block-to-block variation.
  • Running the treatments in the same order on every block. Tool wear, warm-up or operator learning then ride along with the treatment. Randomize the order within each block.
  • Using it with missing cells. The basic Friedman test needs every treatment on every block. With missing data, use a method that handles unbalanced blocks.
  • Overreading small designs. With few blocks, the chi-square p-value is only approximate; exact tables or a larger study give a firmer answer.

Frequently asked questions

What is the difference between the Friedman test and Kruskal–Wallis?

Kruskal–Wallis compares independent groups and ranks all values together. Friedman compares treatments measured on the same blocks and ranks within each block, which removes block-to-block differences.

Is the Friedman test the nonparametric version of repeated measures ANOVA?

Yes, for a design with one treatment factor and one block factor (often subjects or units measured under every condition). It is also the nonparametric counterpart of a two-way ANOVA with one observation per cell.

What is Kendall's W?

A measure of agreement between blocks on the order of the treatments, from 0 to 1. It is a rescaled Friedman statistic, often reported when the blocks are judges ranking products.

How many blocks do I need?

The chi-square approximation becomes reasonable at around 10 blocks, or about 30 observations in total. Fewer blocks can still detect a strong, consistent effect, as in the example, but the p-value is less exact.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab