Kruskal-Wallis Test with Details on Pairwise Comparisons

Kruskal-Wallis test with details on pairwise comparisons

One other approach besides kruskal::agricolae mentioned by Marek, is the Nemenyi-Damico-Wolfe-Dunn test implemented in the help page for oneway_test in the coin package that uses multcomp. Using hadley's setup and reducing the B= value for the approximate() function so it finishes in finite time:

#updated translation of help page implementation of NDWD
NDWD <-
independence_test(dv ~ iv, data = sum_codings1, distribution = approximate(B = 10000),
ytrafo = function(data) trafo(data, numeric_trafo = rank_trafo),
xtrafo = mcp_trafo(iv = "Tukey"))

### global p-value
print(pvalue(NDWD))

### sites (I = II) != (III = IV) at alpha = 0.01 (page 244)
print(pvalue(NDWD, method = "single-step"))

More stable results on that larger dataset may require increasing the B value and increasing the user's patience.

Jan: 2012: There was recently a posting on R-help claiming unexpected results from this method so I forwarded that email to the maintainer. Mark Difford said he had confirmed the problems and offered an alternate tests with the nparcomp package: https://stat.ethz.ch/pipermail/r-help/2012-January/300100.html

There were also in the same week a couple of other suggestions on rhelp for post-hoc contrasts to KW tests:
kruskalmc suggested by Mario Garrido Escudero and
rms::polr followed by rms::contrasts suggested by Frank Harrell https://stat.ethz.ch/pipermail/r-help/2012-January/300329.html

Nov 2015: Agree with toto_tico that help page code of coin package has been changed in the intervening years. The ?independence_test help page now offers a multivariate-KW test and the ?oneway_test help page has replace its earlier implementation with the code above usng the independence_test function.

Kruskal-Wallis and post-hoc analysis in R

  1. heteroskedasticity seems to be the thing you're most worried about -- why go to Kruskal Wallis rather than just a Welch adjustment? However it happens that your standard deviations are almost constant (3.9, 4.8, 4.7). Why would that very modest amount of change in spread by of concern?

  2. a rejection of the omnibus null doesn't necessarily imply any of the individual comparisons will be significant.

  3. formal hypothesis tests of assumptions aren't necessarily useful -- we don't necessarily believe any of the assumptions are exactly true, what matters is their impact on your inference, which a p-value in a hypothesis test really doesn't tell you. (You might easily reject the null of constant variance, but if the standard deviations by group don't change by a substantial amount (possibly by a good deal more than you can detect by a test, depending on sample size), it may hardly matter. On the other hand, failure to reject in small samples should be no consolation at all.

Function to Conduct a Kruskal Wallis Tests for Multiple Comparison of Variables using R

Instead of the summary, we may use tidy

library(purrr)
Outcomes <- setdiff(Outcomes, "Center.Freq") # Centre.Freq column not present
map_dfr(setNames(Outcomes, Outcomes), function(my) {
f <- as.formula(paste(my, "~Species", sep=""))
broom::tidy(kruskal.test(f, data=New_Acoustic_Parameters))
}, .id = "Outcomes")

-output

# A tibble: 8 × 5
Outcomes statistic p.value parameter method
<chr> <dbl> <dbl> <int> <chr>
1 Low.Freq 2.03 0.362 2 Kruskal-Wallis rank sum test
2 High.Freq 0.252 0.881 2 Kruskal-Wallis rank sum test
3 Peak.Freq 3.53 0.171 2 Kruskal-Wallis rank sum test
4 Delta.Freq 1.66 0.436 2 Kruskal-Wallis rank sum test
5 Delta.Time 1.35 0.509 2 Kruskal-Wallis rank sum test
6 Peak.Time 2.41 0.299 2 Kruskal-Wallis rank sum test
7 Start.Freq 4.35 0.114 2 Kruskal-Wallis rank sum test
8 End.Freq 2.19 0.334 2 Kruskal-Wallis rank sum test

Running multiple Kruskal Wallis test with lapply taking long. Easier solution?

Take a look at kruskaltests in the Rfast package. For the KWR data.frame, it appears it would be something like:

allKWR <- Rfast::kruskaltests(as.matrix(KWR[,1:124306]), as.numeric(as.factor(KWR$Group)))


Related Topics



Leave a reply



Submit