# kruskal wallis significativo (kruskal.test) y dunn test (dunn.test) no significativo en R

## Question:

I am new to using the R programming language and I have tried with it to do a Kruskal Wallis and then a Dunn test (with Bonferroni correction) using data from 6 species of fish, 15 months of sampling, different number of samples (between 25 and 45 replications per month) between months and the nature of the data is the number of animals present in a given space. My samples are neither normal nor homoscedastic (I have tried log and square root transformations with no success). I want to know which months are different from which months for each of the species. I have 3 problems related to the dunn test:

1. The Kruskal Wallis (package kruskal.test) for the rockfish gave me a p-value of 0.01, therefore significant (there are significant mean differences between months). Surprisingly the dunn test (package dunn.test) did not give me any combination of groups (in this case months) with significant p value.
2. For the fish Anoplopoma fimbria the problem was another. Kruskal Wallis gave me a significant p-value but in the dunn test in certain combinations of months, let's say AB for giving a generic name to a couple of months gave me a p-value was not significant and BA (the same combination in opposite order ) gave me meaning. The same thing happened with a given month (which I will generically call A) with the same month (combination A with A and combination A with A again). This has been repeated for the other species.
3. I tried an alpha = 0.05 for the dunn test and repeated again with an alpha = 0.01 to see if the results were less chaotic (many combinations of months possible). The result was exactly the same. The same p values.

If it helps here I leave the script I used and the result it gave me for rockfish and below for Anoplopoma fimbria :

``````> rockfish.krustal.wallis <-read.table(file.choose(), header=T)
> names(rockfish.krustal.wallis)
> library("dunn.test", lib.loc="~/R/win-library/3.2")
> dunn.test(rockfish\$counts, g=rockfish\$months, kw=TRUE, method = "Bonferroni", alpha = 0.01)
``````

# The result of the Kruskal Wallis for rockfish:

``````  Kruskal-Wallis rank sum test

data: x and group
Kruskal-Wallis chi-squared = 29.2316, df = 13, p-value = 0.01
``````

# Here is the result of the dunn test for rockfish:

``````    Comparison of x by group
(Bonferroni)
Col Mean-|
Row Mean |      apr13      apr14      aug13      des13      feb13      feb14
---------+------------------------------------------------------------------
apr14 |   0.879015
|     1.0000
|
aug13 |   0.832672  -0.060825
|     1.0000     1.0000
|
des13 |   1.187794   0.273902   0.341798
|     1.0000     1.0000     1.0000
|
feb13 |   0.771037  -0.080607  -0.022883  -0.348631
|     1.0000     1.0000     1.0000     1.0000
|
feb14 |  -1.034189  -1.895217  -1.866861  -2.238531  -1.757098
|     1.0000     1.0000     1.0000     1.0000     1.0000
|
jan14 |   0.850220  -0.050744   0.010750  -0.333754   0.033296   1.892852
|     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000
|
jul13 |   2.160807   1.209424   1.296702   0.963946   1.255722   3.234036
|     1.0000     1.0000     1.0000     1.0000     1.0000     0.0555
|
jun13 |   1.057552   0.167672   0.231966  -0.103183   0.244048   2.082939
|     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000
|
mar13 |  -0.629163  -1.587098  -1.552930  -1.964295  -1.440244   0.518166
|     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000
|
may13 |   0.467668  -0.412120  -0.357916  -0.702341  -0.318816   1.493055
|     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000
|
nov13 |   2.297948   1.364141   1.451952   1.128504   1.405573   3.348685
|     0.9812     1.0000     1.0000     1.0000     1.0000     0.0369
|
oct13 |   1.566284   0.660026   0.733611   0.403551   0.722355   2.600473
|     1.0000     1.0000     1.0000     1.0000     1.0000     0.4236
|
sep13 |   2.415561   1.502453   1.589976   1.276179   1.539858   3.440949
|     0.7148     1.0000     1.0000     1.0000     1.0000     0.0264
Col Mean-|
Row Mean |      jan14      jul13      jun13      mar13      may13      nov13
---------+------------------------------------------------------------------
jul13 |   1.296949
|     1.0000
|
jun13 |   0.223169  -1.044262
|     1.0000     1.0000
|
mar13 |  -1.580526  -3.077551  -1.793553
|     1.0000     0.0950     1.0000
|
may13 |  -0.371446  -1.656015  -0.584947   1.140412
|     1.0000     1.0000     1.0000     1.0000
|
nov13 |   1.453266   0.189546   1.203587   3.200510   1.802746
|     1.0000     1.0000     1.0000     0.0624     1.0000
|
oct13 |   0.728849  -0.535397   0.495401   2.366799   1.085285  -0.706602
|     1.0000     1.0000     1.0000     0.8164     1.0000     1.0000
|
sep13 |   1.592075   0.364092   1.346645   3.297191   1.931592   0.175774
|     1.0000     1.0000     1.0000     0.0444     1.0000     1.0000
Col Mean-|
Row Mean |      aug13      des13      feb13      feb14      jan14      jul13      jun13      mar13      may13      nov13      oct13
---------+-------------------------------------------------------------------------------------------------------------------------
des13 |   0.341798   0.771037  -0.080607  -0.022883  -0.348631  -1.034189  -1.895217  -1.866861  -2.238531  -1.757098   0.850220
|     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000
|
feb13 |  -0.022883  -0.348631  -1.034189  -1.895217  -1.866861  -2.238531  -1.757098   0.850220  -0.050744   0.010750  -0.333754
|     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000
|
feb14 |  -1.866861  -2.238531  -1.757098   0.850220  -0.050744   0.010750  -0.333754   0.033296   1.892852   2.160807   1.209424
|     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000
|
jan14 |   0.010750  -0.333754   0.033296   1.892852   2.160807   1.209424   1.296702   0.963946   1.255722   3.234036   1.296949
|     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     0.0555     1.0000
|
jul13 |   1.296702   0.963946   1.255722   3.234036   1.296949   1.057552   0.167672   0.231966  -0.103183   0.244048   2.082939
|     1.0000     1.0000     1.0000     0.0555     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000
|
jun13 |   0.231966  -0.103183   0.244048   2.082939   0.223169  -1.044262  -0.629163  -1.587098  -1.552930  -1.964295  -1.440244
|     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000
|
mar13 |  -1.552930  -1.964295  -1.440244   0.518166  -1.580526  -3.077551  -1.793553   0.467668  -0.412120  -0.357916  -0.702341
|     1.0000     1.0000     1.0000     1.0000     1.0000     0.0950     1.0000     1.0000     1.0000     1.0000     1.0000
|
may13 |  -0.357916  -0.702341  -0.318816   1.493055  -0.371446  -1.656015  -0.584947   1.140412   2.297948   1.364141   1.451952
|     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     1.0000     0.9812     1.0000     1.0000
|
nov13 |   1.451952   1.128504   1.405573   3.348685   1.453266   0.189546   1.203587   3.200510   1.802746   1.566284   0.660026
|     1.0000     1.0000     1.0000     0.0369     1.0000     1.0000     1.0000     0.0624     1.0000     1.0000     1.0000
|
oct13 |   0.733611   0.403551   0.722355   2.600473   0.728849  -0.535397   0.495401   2.366799   1.085285  -0.706602   2.415561
|     1.0000     1.0000     1.0000     0.4236     1.0000     1.0000     1.0000     0.8164     1.0000     1.0000     0.7148
|
sep13 |   1.589976   1.276179   1.539858   3.440949   1.592075   0.364092   1.346645   3.297191   1.931592   0.175774   0.862608
|     1.0000     1.0000     1.0000     0.0264     1.0000     1.0000     1.0000     0.0444     1.0000     1.0000     1.0000
``````

# El script para Anoplopoma fimbria:

``````> rockfish.krustal.wallis <-read.table(file.choose(), header=T)
> names(rockfish.krustal.wallis)
> library("dunn.test", lib.loc="~/R/win-library/3.2")
> dunn.test(Anoplopoma_fimbria.krustal.wallis\$counts, g=Anoplopoma_fimbria.krustal.wallis\$months, kw=TRUE, method = "Bonferroni", alpha = 0.01)
``````

# The result of the Kruskal Wallis test:

``````Kruskal-Wallis rank sum test

data: x and group
Kruskal-Wallis chi-squared = 346.7977, df = 13, p-value = 0
``````

# The result of the dunn test for Anoplopoma fimbria:

``````                          Comparison of x by group
(Bonferroni)
Col Mean-|
Row Mean |      apr13      apr14      aug13      des13      feb13      feb14
---------+------------------------------------------------------------------
apr14 |  -0.138335
|     1.0000
|
aug13 |  -5.721434  -5.397150
|     0.0000     0.0000
|
des13 |   0.032365   0.169603   5.753273
|     1.0000     1.0000     0.0000
|
feb13 |   1.137404   1.233460   6.490391   1.107091
|     1.0000     1.0000     0.0000     1.0000
|
feb14 |   1.256426   1.351363   6.867965   1.224587   0.057956
|     1.0000     1.0000     0.0000     1.0000     1.0000
|
jan14 |   0.770631   0.882201   6.435592   0.738524  -0.406975  -0.488439
|     1.0000     1.0000     0.0000     1.0000     1.0000     1.0000
|
jul13 |  -8.945967  -8.377165  -2.085009  -8.983885  -9.496393  -10.21129
|     0.0000     0.0000     1.0000     0.0000     0.0000     0.0000
|
jun13 |  -6.948265  -6.588580  -1.257306  -6.979824  -7.639835  -8.066820
|     0.0000     0.0000     1.0000     0.0000     0.0000     0.0000
|
mar13 |   1.345278   1.441622   7.566550   1.309824   0.013835  -0.052773
|     1.0000     1.0000     0.0000     1.0000     1.0000     1.0000
|
may13 |  -3.802618  -3.551380   1.735224  -3.833581  -4.674006  -4.949562
|     0.0065     0.0174     1.0000     0.0057     0.0001     0.0000
|
nov13 |  -3.099127  -2.855706   2.672702  -3.131493  -4.040003  -4.305158
|     0.0883     0.1954     0.3424     0.0791     0.0024     0.0008
|
oct13 |   0.677506   0.791471   6.298163   0.645667  -0.485328  -0.569802
|     1.0000     1.0000     0.0000     1.0000     1.0000     1.0000
|
sep13 |  -0.235718  -0.092986   5.351330  -0.267277  -1.333887  -1.458183
|     1.0000     1.0000     0.0000     1.0000     1.0000     1.0000
Col Mean-|
Row Mean |      jan14      jul13      jun13      mar13      may13      nov13
---------+------------------------------------------------------------------
jul13 |  -9.748741
|     0.0000
|
jun13 |  -7.647328   0.577645
|     0.0000     1.0000
|
mar13 |   0.489597   11.82495   8.879660
|     1.0000     0.0000     0.0000
|
may13 |  -4.512609   4.040237   2.945542  -5.406943
|     0.0003     0.0024     0.1467     0.0000
|
nov13 |  -3.845064   5.315158   3.926306  -4.740202   0.837716
|     0.0055     0.0000     0.0039     0.0001     1.0000
|
oct13 |  -0.086014   9.537097   7.501867  -0.579365   4.394957   3.726238
|     1.0000     0.0000     0.0000     1.0000     0.0005     0.0088
|
sep13 |  -0.985667   8.370717   6.553333  -1.562332   3.489703   2.786240
|     1.0000     0.0000     0.0000     1.0000     0.0220     0.2426
Col Mean-|
Row Mean |      aug13      des13      feb13      feb14      jan14      jul13      jun13      mar13      may13      nov13      oct13
---------+-------------------------------------------------------------------------------------------------------------------------
des13 |   5.753273   1.137404   1.233460   6.490391   1.107091   1.256426   1.351363   6.867965   1.224587   0.057956   0.770631
|     0.0000     1.0000     1.0000     0.0000     1.0000     1.0000     1.0000     0.0000     1.0000     1.0000     1.0000
|
feb13 |   6.490391   1.107091   1.256426   1.351363   6.867965   1.224587   0.057956   0.770631   0.882201   6.435592   0.738524
|     0.0000     1.0000     1.0000     1.0000     0.0000     1.0000     1.0000     1.0000     1.0000     0.0000     1.0000
|
feb14 |   6.867965   1.224587   0.057956   0.770631   0.882201   6.435592   0.738524  -0.406975  -0.488439  -8.945967  -8.377165
|     0.0000     1.0000     1.0000     1.0000     1.0000     0.0000     1.0000     1.0000     1.0000     0.0000     0.0000
|
jan14 |   6.435592   0.738524  -0.406975  -0.488439  -8.945967  -8.377165  -2.085009  -8.983885  -9.496393  -10.21129  -9.748741
|     0.0000     1.0000     1.0000     1.0000     0.0000     0.0000     1.0000     0.0000     0.0000     0.0000     0.0000
|
jul13 |  -2.085009  -8.983885  -9.496393  -10.21129  -9.748741  -6.948265  -6.588580  -1.257306  -6.979824  -7.639835  -8.066820
|     1.0000     0.0000     0.0000     0.0000     0.0000     0.0000     0.0000     1.0000     0.0000     0.0000     0.0000
|
jun13 |  -1.257306  -6.979824  -7.639835  -8.066820  -7.647328   0.577645   1.345278   1.441622   7.566550   1.309824   0.013835
|     1.0000     0.0000     0.0000     0.0000     0.0000     1.0000     1.0000     1.0000     0.0000     1.0000     1.0000
|
mar13 |   7.566550   1.309824   0.013835  -0.052773   0.489597   11.82495   8.879660  -3.802618  -3.551380   1.735224  -3.833581
|     0.0000     1.0000     1.0000     1.0000     1.0000     0.0000     0.0000     0.0065     0.0174     1.0000     0.0057
|
may13 |   1.735224  -3.833581  -4.674006  -4.949562  -4.512609   4.040237   2.945542  -5.406943  -3.099127  -2.855706   2.672702
|     1.0000     0.0057     0.0001     0.0000     0.0003     0.0024     0.1467     0.0000     0.0883     0.1954     0.3424
|
nov13 |   2.672702  -3.131493  -4.040003  -4.305158  -3.845064   5.315158   3.926306  -4.740202   0.837716   0.677506   0.791471
|     0.3424     0.0791     0.0024     0.0008     0.0055     0.0000     0.0039     0.0001     1.0000     1.0000     1.0000
|
oct13 |   6.298163   0.645667  -0.485328  -0.569802  -0.086014   9.537097   7.501867  -0.579365   4.394957   3.726238  -0.235718
|     0.0000     1.0000     1.0000     1.0000     1.0000     0.0000     0.0000     1.0000     0.0005     0.0088     1.0000
|
sep13 |   5.351330  -0.267277  -1.333887  -1.458183  -0.985667   8.370717   6.553333  -1.562332   3.489703   2.786240  -0.893230
|     0.0000     1.0000     1.0000     1.0000     1.0000     0.0000     0.0000     1.0000     0.0220     0.2426     1.0000
``````

As you see in the tables that result from your Dunn test, you make a Bonferroni correction to the results. When you compare, as in your case, 13 averages between them, between the 13 x 13 = 169 comparisons. You can imagine that the chance that something resembles random is greater when you compare 13 groups than, for example, comparing only 2 averages (2 x 2 = 4 combinations instead of 169).

In technical terms you are losing degrees of freedom by increasing the number of comparisons. And in practice the most common solution is a Bonferroni correction as you do above.

For the same reason, it should not surprise you that a significant result with Kruskal Wallis does not result in significant results with Dunn when you have 13 groups. To see differences at the group level the result suggests that you need more data.

The next question is obviously how to continue with this data? My answer would be: take a good look at what your sampling design was and why. It seems that the design in this case was to see if there is an effect of the month, and not to determine the differences between months.

You have support to conclude that there is a significant effect of the month with the Kruskal Wallis result. A monthly trend may be seen on a graph. Although you cannot assign it a statistical significance, you can describe the trend in the data with a visual interpretation.

It usually doesn't make much sense to search and search for a statistical method until you find one that gives you the results you want to see. It is best to take the results as a basis for a better sampling design next time, or as a basis for recommending a better design when you publish these results.

Scroll to Top