🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Friedman Test — Nonparametric Repeated Measures ANOVA

Nonparametric TestsNonparametric Tests🟢 Free Lesson

Friedman Test

Nonparametric Tests

Nonparametric Repeated Measures ANOVA

When the same subjects are measured under multiple conditions and normality cannot be assumed, the Friedman test ranks observations within each block to detect systematic differences across treatments.

  • Psychology — Compare response times across multiple stimuli within the same participants
  • Food Science — Rate product preferences when panelists taste several brands
  • Ergonomics — Assess workstation designs with repeated measurements on the same workers

Ranks within blocks reveal treatment differences without distributional assumptions.


What You'll Learn

  • 1Explain why observations are ranked inside each block before treatments are compared
  • 2Compute the Friedman chi-square statistic by hand from a table of rank sums
  • 3Decide when the chi-square approximation is trustworthy and what to do with ties
  • 4Run the test in Python, follow up with Nemenyi or pairwise Wilcoxon, and report Kendall's W

The Friedman test is the nonparametric alternative to repeated-measures ANOVA. It is used when the same subjects are measured under k conditions, the outcome is ordinal or clearly non-normal, and you still want a single omnibus answer to the question "do any of these conditions differ?" Rather than modelling raw scores, it throws away the spacing between values and keeps only the ordering, which is exactly what protects it from skew and outliers.

Why the Rows Are Ranked First

A repeated-measures design has a natural nuisance factor: the subject. Some people are simply faster, stronger, or more generous raters than others, and that between-subject variation is usually far larger than the treatment effect you care about. Ranking inside each row removes it in one stroke. The best score in a subject's row always becomes rank 1 and the worst becomes rank k, no matter whether that subject scored high or low in absolute terms. What survives is the within-subject ordering of the treatments.

This is also the source of the test's limits. Because only order is used, a treatment that wins by 0.01 points receives exactly the same rank as one that wins by 50 points, so the test answers "which condition tends to come first?" and stays silent about magnitude. If magnitudes matter and the data are roughly normal, repeated-measures ANOVA or a linear mixed model is the better tool.

SituationPreferred testWhat it assumes
Within-subject, continuous outcome, roughly normalRepeated-measures ANOVANormal residuals, sphericity
Within-subject, ordinal or clearly skewed outcomeFriedman testOrdinal scale, independent subjects
Within-subject, two conditions onlyWilcoxon signed-rankSymmetric difference distribution
Between-subject groups, non-normal outcomeKruskal-Wallis testIndependent groups
Ranked data with many ties across blocksFriedman with tie correctionTies not too numerous

Subjects are the independent units, so the sample size n always means the number of subjects (blocks), never the number of raw observations nk. Confusing the two inflates the statistic by a factor of k and produces confident, wrong conclusions.

The Statistic, Built From the Rank Sums

Once every row holds ranks from 1 to k, sum the ranks of each treatment across the n subjects. Let be the rank sum for treatment j. Under the null hypothesis every treatment is equally likely to land anywhere in a row, so each is expected to be:

The Friedman statistic measures how far the observed rank sums drift from that common expectation:

Subtracting the fixed part centres the quantity at zero, so means perfect agreement between treatments. The reference distribution is chi-square with .

Ties inside a row break the assumption that ranks are a permutation of 1 through k. Assign tied values their average rank, then divide the statistic by the correction factor:

where is the size of the g-th group of tied values and the sum runs over every tied group in the whole table. Dividing by C, which is less than 1, inflates the statistic so that the tie-induced loss of variance is compensated. With no ties every , each term vanishes, and C equals 1.

A Full Numerical Example

Six patients each had three wound dressings applied in random order, and the healing score after seven days is recorded below. Higher is better.

PatientDressing ADressing BDressing C
1121518
2101317
391614
4111419
581215
6141316

Step 1 — rank each row ascending. Patient 3 has A = 9 (rank 1), C = 14 (rank 2), B = 16 (rank 3). Patient 6 has B = 13 (rank 1), A = 14 (rank 2), C = 16 (rank 3). Carrying this out for all six rows gives:

PatientRank ARank BRank C
1123
2123
3132
4123
5123
6213
Rank sumR_A = 7R_B = 12R_C = 17

Step 2 — check the total. Rank sums must add to , and . This cheap check catches most hand-calculation slips.

Step 3 — substitute.

Step 4 — compare to the reference distribution. With , the critical value at is 5.991. Because 8.333 exceeds it, the p-value is smaller than 0.05; the exact tail probability for a chi-square of 8.333 on 2 degrees of freedom is 0.0155. We reject the null hypothesis: healing scores are not exchangeable across the three dressings.

Assumptions and Where They Bend

The test needs far less than ANOVA, but it is not assumption-free.

  1. Independent subjects. The blocks must not influence one another; repeated measurements on the same machine or the same classroom violate this.
  2. At least ordinal measurement. Any scale on which "greater than" is well defined qualifies.
  3. A consistent treatment effect. If dressing A wins for three patients and loses badly for three others, the rank sums even out and the test finds nothing, even though a large interaction is present.
  4. Sufficient n for the chi-square approximation. It is adequate from about n = 5 subjects with k = 3 conditions, but with k = 5 or more you should push n above 10 or compute an exact permutation p-value.

Power is noticeably weaker than a parametric equivalent when the data really are normal — Friedman needs roughly 15 to 20 percent more subjects to reach the same power as repeated-measures ANOVA. That is the premium you pay for robustness.

Post-Hoc Analysis: Locating the Difference

Rejecting the omnibus null only says that something differs. To say what differs, use one of two follow-ups.

The Nemenyi test compares every pair of mean ranks with a single critical difference:

where is the studentized range statistic divided by . For and conditions, . Our example gives:

Mean ranks are 1.167 for A, 2.000 for B, and 2.833 for C, so the observed differences are:

PairMean rank differenceExceeds CD = 1.353?
A vs B0.833No
A vs C1.667Yes
B vs C0.833No

Only A versus C separates. The Nemenyi test controls the family-wise error rate across all comparisons, which makes it safe and also conservative — with small n it often finds nothing even when the omnibus test is significant.

Pairwise Wilcoxon signed-rank tests are the alternative. They have more power for individual contrasts but must be adjusted, typically with Bonferroni: with three comparisons, each test runs at . A popular middle ground is to treat the pairwise tests as exploratory and report them with their raw p-values plus an explicit note that they are uncorrected.

Kendall's W: Quantifying Agreement

A significant p-value still does not say how large the effect is. Kendall's coefficient of concordance does, and it is a direct transform of the statistic you already have:

For the worked example, . W ranges from 0 (the treatments are ranked in completely different orders by different subjects, no agreement) to 1 (every subject ranks them identically). The conventional reading is 0.1 as a small effect, 0.3 as medium, and 0.5 as large, so 0.694 is a strong, consistent preference for dressing C. In inter-rater work the same coefficient is read as agreement among judges, which is why you will meet it under two different names.

Reproducing the Analysis in Python and R

python
import numpy as np
from scipy import stats

scores = np.array([
    [12, 15, 18],
    [10, 13, 17],
    [ 9, 16, 14],
    [11, 14, 19],
    [ 8, 12, 15],
    [14, 13, 16],
])
a, b, c = scores[:, 0], scores[:, 1], scores[:, 2]

stat, p = stats.friedmanchisquare(a, b, c)
n, k = scores.shape
print(f"Friedman chi2({k-1}) = {stat:.4f}, p = {p:.5f}")

W = stat / (n * (k - 1))
label = 'small' if W < 0.1 else 'medium' if W < 0.3 else 'large'
print(f"Kendall's W = {W:.4f} ({label} effect)")

# Nemenyi critical difference at alpha = 0.05
q_alpha = 2.343
cd = q_alpha * np.sqrt(k * (k + 1) / (6 * n))
mean_ranks = np.mean(stats.rankdata(scores, axis=1), axis=0)
print("mean ranks:", np.round(mean_ranks, 3), "CD =", round(cd, 3))

# Pairwise Wilcoxon with Bonferroni correction
pairs = [('A vs B', a, b), ('A vs C', a, c), ('B vs C', b, c)]
alpha_bonf = 0.05 / len(pairs)
for name, x, y in pairs:
    _, pw = stats.wilcoxon(x, y, alternative='two-sided')
    flag = 'significant' if pw < alpha_bonf else 'ns'
    print(f"  {name}: p = {pw:.4f} -> {flag}")
dressings <- data.frame(
  patient = 1:6,
  A = c(12, 10, 9, 11, 8, 14),
  B = c(15, 13, 16, 14, 12, 13),
  C = c(18, 17, 14, 19, 15, 16)
)

res <- friedman.test(as.matrix(dressings[, -1]))
print(res)

# Effect size and post-hoc in one pass
chi2 <- unname(res$statistic)
n <- nrow(dressings); k <- ncol(dressings) - 1
cat("Kendall's W =", round(chi2 / (n * (k - 1)), 4), "\n")

pairwise.wilcox.test(
  reshape(dressings, direction = "long", varying = 2:4)$value,
  reshape(dressings, direction = "long", varying = 2:4)$time,
  paired = TRUE, p.adjust.method = "bonferroni"
)

💡Ties are common in rating data

When panelists use a 1 to 5 scale, ties inside a block are almost guaranteed. SciPy's friedmanchisquare does not correct for ties, so on heavily tied data prefer R's friedman.test, which applies the correction, or an exact permutation routine.

Reporting the Result

A complete report answers four questions: what was tested, what the statistic was, whether it was significant, and how large the effect was.

Healing scores differed significantly across the three dressings, , , Kendall's . Post-hoc pairwise Wilcoxon tests with Bonferroni correction showed that dressing C outscored dressing A ().

If you report only the p-value you force the reader to guess the design, and if you omit W you have given no indication of whether the finding would matter outside the sample.

Common Mistakes

Running the test on independent groups

Fix: Friedman requires the same subjects in every condition; for independent groups use Kruskal-Wallis instead.

Reporting the omnibus p-value as if it identified a winner

Fix: Follow up with Nemenyi or Bonferroni-corrected pairwise Wilcoxon tests before naming any treatment.

Treating nk observations as the sample size

Fix: n is the number of subjects. With 6 patients and 3 conditions you have 6 independent units, not 18.

Quoting chi-square without an effect size

Fix: Always report Kendall's W, computed as chi-square divided by n(k-1).

Best Practices

  • Randomize the order of conditions within each subject so that practice and fatigue do not masquerade as treatment effects
  • Check the rank-sum totals against nk(k+1)/2 before trusting any hand calculation
  • State the tie-handling policy when your outcome has few distinct values
  • Report the test statistic, degrees of freedom, p-value and Kendall's W in every write-up

Key Takeaways

  • Ranks are computed inside each subject's row, which eliminates between-subject variability without any distributional assumption
  • The statistic is 12/(n k (k+1)) times the sum of squared rank sums minus 3n(k+1), referenced to chi-square with k-1 degrees of freedom
  • Kendall's W = chi-square divided by n(k-1) converts the test into an effect size running from 0 to 1
  • Nemenyi's critical difference or Bonferroni-corrected pairwise Wilcoxon tests are required to name which condition differs
  • Friedman discards magnitude: use it for ordinal or skewed data, not when effect size in original units matters

Interview Questions

Q1: Why rank within subjects rather than across the whole sample?

Between-subject variability usually dwarfs the treatment effect. Ranking inside each row maps every subject's best and worst score to the same ranks, so the nuisance spread cancels and only the ordering of treatments contributes to the statistic.

Q2: How do you compute the Friedman statistic from rank sums?

With n subjects and k conditions, chi-square = 12/(n k (k+1)) times the sum of the squared rank sums, minus 3n(k+1), compared against chi-square with k-1 degrees of freedom. A quick sanity check is that the rank sums must total nk(k+1)/2.

Q3: What does Kendall's W tell you that the p-value does not?

W measures concordance: 0 means subjects rank the treatments in unrelated orders, 1 means identical rankings. It is scale-free and sample-size-free, so it answers how consistent and how large the effect is, which the p-value cannot.

Q4: When would you choose pairwise Wilcoxon tests over Nemenyi?

Nemenyi controls the family-wise error rate over all pairs but is conservative, especially at small n. Pairwise Wilcoxon tests with a Bonferroni or Holm adjustment have more power on a small set of planned contrasts, at the cost of assuming symmetric difference distributions.

Frequently Asked Questions

Is the Friedman test the same as a nonparametric repeated-measures ANOVA?

It plays that role, but it is not a rank-transformed ANOVA. There is no variance decomposition and no sphericity condition, and the reference distribution is chi-square rather than F. Because it uses only within-row ordering it is more robust than ANOVA to skew and outliers, and slightly less powerful when the data really are normal.

What do I do if the Friedman test is significant but no pair survives correction?

This is a normal outcome with small samples: the omnibus test pools evidence across all conditions, while each pairwise test sees only part of it. Report the omnibus result, present the pairwise p-values as exploratory, and either collect more subjects or pre-register one or two planned contrasts so the follow-up does not have to pay for every possible comparison.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-14

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Statistics Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement