friedman_nemenyi_test: Nemenyi Post-Hoc Test for Friedman Rank Sums

View source: R/friedman_nemenyi_test.R

friedman_nemenyi_testR Documentation

Nemenyi Post-Hoc Test for Friedman Rank Sums

Description

Performs the Nemenyi (Wilcoxon-Nemenyi-McDonald-Thompson) all-pairs post-hoc test for a two-way balanced complete block design, following a significant Friedman rank sum test. The treatment rank sums are compared pairwise and the test statistic is referred to the studentized range distribution, which already accounts for the multiplicity of the all-pairs comparisons (so, as for tukey_hsd(), there is no separate p-value adjustment step). It should only be used as a post-hoc procedure when the Friedman test is itself significant.

The Nemenyi test is the rank-based, repeated-measures analogue of Tukey's HSD. Unlike friedman_conover_test() (the Durbin-Conover test), it does not borrow the residual rank variance and is therefore more conservative.

See the Datanovia tutorial Friedman Test in R for a worked walkthrough.

Usage

friedman_nemenyi_test(data, formula, detailed = FALSE)

Arguments

data

a data.frame containing the variables in the formula.

formula

a formula of the form a ~ b | c, where a (numeric) is the dependent variable name; b is the within-subjects factor variable (the treatment); and c is the column name containing the individuals/subjects (block) identifier. Should be unique per individual.

detailed

logical value. If TRUE, returns the rank-sum estimate and the test method in the output.

Details

For a balanced complete block design with b blocks and k treatments, the observations within each block are ranked. Let R_j be the sum of the within-block ranks for treatment j. The pairwise statistic for treatments i and j is

q_{ij} = \frac{|R_i - R_j|}{\sqrt{b\,k\,(k+1)/12}}

and the p-value is obtained from the studentized range distribution with k groups and infinite degrees of freedom.

The p-values match PMCMRplus::frdAllPairsNemenyiTest(). That function reports the magnitude of the statistic; the value returned here carries the sign of the rank-sum difference between the two groups, so the two agree only where that difference is positive.

Value

return a data frame with some of the following columns:

  • .y.: the y (outcome) variable used in the test.

  • group1,group2: the compared treatments in the pairwise tests.

  • n1,n2: the number of blocks (subjects) contributing to each treatment.

  • estimate: the rank-sum difference.

  • estimate1, estimate2: the rank sums of the two treatments, respectively.

  • statistic: the studentized-range test statistic.

  • p.adj: the p-value (already adjusted for multiple comparisons via the studentized range distribution).

  • method: the statistical test used to compare groups.

  • p.adj.signif: the significance level of the adjusted p-values.

The returned object has an attribute called args, which is a list holding the test arguments.

References

Nemenyi, P. (1963) Distribution-free Multiple Comparisons. PhD Thesis, Princeton University.

Hollander, M., Wolfe, D. A. (1973) Nonparametric Statistical Methods. Wiley.

See Also

friedman_test, friedman_conover_test, friedman_effsize The Datanovia tutorial: Friedman Test in R.

Examples

# A balanced complete block design: 3 treatments measured on 6 subjects
df <- data.frame(
  id        = factor(rep(1:6, 3)),
  treatment = factor(rep(c("A", "B", "C"), each = 6)),
  score     = c(4, 6, 3, 5, 4, 5,    7, 8, 6, 7, 9, 6,    6, 9, 7, 8, 8, 9)
)

# Omnibus Friedman test
df %>% friedman_test(score ~ treatment | id)

# Nemenyi all-pairs post-hoc
df %>% friedman_nemenyi_test(score ~ treatment | id)

rstatix documentation built on July 24, 2026, 1:06 a.m.