# Should there be agreement between NB GLM and Kruskal Wallis for categorical variable levels?

Briefly, my question is whether the results of a GLM (negative binomial) for a categorical variable should agree with the results of a non parametric test--in this case a kruskal-wallis test.

This question may be an artifact of my particular data set, but I'll attempt to explain. I am looking at fish counts with respect to a number of environmental variables. I have several independent variables, but for now I am interested in the interpretation of Biogenics (number of anemones like Metridium).

A negative binomial GLM suggests that with respect to the reference level 'Biogenics1', the intercepts of both Biogenics2 and Biogenics4 are significantly different. ( In this case the mean count of fish is smaller).

But! If I perform a Kruskal.Wallis test on the same data looking for differences in counts among the levels of Biogenics, there is an insignificant p.value. Maybe I'm all confused on the interpretation of these results (GLM vs kruskal.wallis), and how they should (or should not) relate to one another. Am I way off to think that a significant difference in negative binomial intercepts should translate to significant differences in the mean counts across the levels of a particular factor?

If the GLM is telling me there is a difference between the levels of Biogenics, but Kruskal Wallis says 'no, there is not', is this a problem?

glm.nb(formula = fish.counts ~ Bottom.Type + Lat + Slope + Depth_m +
Biogenics + offset(log(area)), data = fish, maxit = 500,
init.theta = 0.3167104931, link = log)

Deviance Residuals:
Min       1Q   Median       3Q      Max
-1.5296  -0.7711  -0.4639  -0.2190   4.4543

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept)      100.479364   8.357186  12.023  < 2e-16 ***
Bottom.TypeHard    1.864022   0.273399   6.818 9.24e-12 ***
Bottom.TypeMixed   0.606571   0.319242   1.900 0.057429 .
Lat               -2.831241   0.226682 -12.490  < 2e-16 ***
Slope             -0.037392   0.014754  -2.534 0.011266 *
Depth_m           -0.010358   0.004173  -2.482 0.013048 *
Biogenics2        -1.170058   0.315571  -3.708 0.000209 ***
Biogenics3        -0.400999   0.327457  -1.225 0.220732
Biogenics4        -0.753762   0.229439  -3.285 0.001019 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for Negative Binomial(0.3167) family taken to be 1)

Null deviance: 936.30  on 702  degrees of freedom
Residual deviance: 411.16  on 694  degrees of freedom
AIC: 1503.6


kruskal.test(fish.counts ~ Biogenics, data = fish)
---
Kruskal-Wallis rank sum test

data:  fish.counts by Biogenics
Kruskal-Wallis chi-squared = 3.45, df = 3, p-value = 0.3273


P.S. I know no one likes 'here's my code, explain the results' types of questions, and so I'm not asking for the specifics of the GLM results, rather how to interpret these two statistical tests in light of each other.

P.SS A likelihood ratio test for the NB GLM suggests that the overal variable Biogenics improves the model fit, and should not be dropped

• KW isn't adjusting for all those covariates that are in your model, and (even if that weren't already enough to fully account for the results being different) it also uses the data quite differently in assessing group differences. Why would you expect it to give the same result? Mar 1 '17 at 7:11
• Thank you Glen_b and @Tim , I should have considered the adjustments for the covariates. I think my first problem was thinking that both KW and NBD results reflected differences in the mean of the Biogenics factor, so even if the statistical test was different, there should be some general agreement between the two. Your answers helped clarify my mistake. Mar 2 '17 at 16:54
• KW does not reflect differences in means (in general). Mar 2 '17 at 16:58
• Sorry, I intended to indicate that I had the false notion that KW reflected differences in means- but that I now understand this is not the case thanks to the helpful answers here. Mar 2 '17 at 17:01
• Yes, I see ... my apologies. Mar 2 '17 at 17:36

## 1 Answer

No. As @Glen_b has said, there is no reason to expect them to be the same. Kruskal-Wallis is testing for differences in the medians, whereas NBD is testing for differences in the means, conditional on the distributional assumption (of the NBD), the theta parameter, and the covariates. It is the covariates that are likely making the real difference, and without them you would expect similar conclusions.

My guess is that the way to read this is that the biogenics alone do not explain differences in your dependent variable. However, the other variables in your NBD-regression are meaningful and, once they are included, the biogenics is significant at explaining effects that they do not explain.

• Kruskal Wallis doesn't test for differences in medians (yes, lots of things say so, but it's easy to show they're wrong) -- and if you add the assumptions people usually tend to make to turn it into a test of medians, it would work perfectly well as a test of means (I've upvoted though, since you cover the important part). Mar 2 '17 at 17:09
• Ah, you have caught me out here. As I typed it I knew I was being a bit lazy...
– Tim
Mar 6 '17 at 3:55