R/friedman_conover_test.R
friedman_conover_test.RdPerforms Conover's all-pairs comparison test (also known as the Durbin-Conover test) for a two-way balanced complete block design, following a significant Friedman rank sum test. It is the repeated-measures analogue of Conover's test for the Kruskal-Wallis design: the within-block ranks are compared pairwise using the pooled rank variance and the statistic is referred to a t-distribution with \((b - 1)(k - 1)\) degrees of freedom (\(b\) blocks, \(k\) treatments). It should only be used as a post-hoc procedure when the Friedman test is itself significant (Conover, 1999).
If a reference group is specified (via ref.group), then each of the
remaining treatments is compared only to the reference (control) treatment,
and the p-value adjustment for multiple comparisons is computed over only
these k - 1 comparisons (as for dunn_test()).
friedman_conover_test(
data,
formula,
p.adjust.method = "holm",
ref.group = NULL,
detailed = FALSE
)a data.frame containing the variables in the 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.
method to adjust p-values for multiple comparisons. Used when pairwise comparisons are performed. Allowed values include "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none". Default is "holm".
a character string specifying the reference treatment. If specified, each of the treatment levels is compared to the reference (control), and the p-value adjustment is computed over only these comparisons.
logical value. If TRUE, returns the rank-sum estimate and the test method in the output.
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: Test statistic (t-value) used to compute the p-value.
df: degrees of freedom (\((b - 1)(k - 1)\)).
p: p-value.
p.adj: the adjusted p-value.
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.
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\) and let \(A = \sum r^2\) be the sum of the squared within-block ranks. The pairwise statistic for treatments \(i\) and \(j\) is $$t_{ij} = \frac{R_i - R_j}{\sqrt{\dfrac{2\,(b\,A - \sum_j R_j^2)}{(b - 1)(k - 1)}}}$$ referred to a t-distribution with \((b - 1)(k - 1)\) degrees of freedom. This is the Conover (1999) post-hoc, also known as the Durbin-Conover test.
Conover, W. J. (1999) Practical Nonparametric Statistics, 3rd edition. Wiley.
# 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)
#> # A tibble: 1 × 6
#> .y. n statistic df p method
#> * <chr> <int> <dbl> <dbl> <dbl> <chr>
#> 1 score 6 9.33 2 0.00940 Friedman test
# Conover (Durbin-Conover) all-pairs post-hoc
df %>% friedman_conover_test(score ~ treatment | id)
#> # A tibble: 3 × 10
#> .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif
#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 score A B 6 6 4.47 10 0.00119 0.00239 **
#> 2 score A C 6 6 5.59 10 0.000231 0.000692 ***
#> 3 score B C 6 6 1.12 10 0.290 0.290 ns
# Comparison against a reference (control) treatment
df %>% friedman_conover_test(score ~ treatment | id, ref.group = "A")
#> # A tibble: 2 × 10
#> .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif
#> * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 score A B 6 6 4.47 10 0.00119 0.00119 **
#> 2 score A C 6 6 5.59 10 0.000231 0.000462 ***