7
$\begingroup$

I am performing model selection in R with the anova() function, and my categorical variable was maintained in my final model, but when I did a post hoc analysis with the emmeans() function, it told me the levels did not differ. What does it mean?

I use R software, and I am studying how the body condition of a species of fish varies in 3 kinds of rivers: preserved, slightly urban and very urban. Each category has one replicate, so that means I have 2 preserved rivers, 2 slightly urbanized rivers and 2 very urbanized rivers, which means that "river" is a random factor, and "category of urbanization" is my fixed factor and predictor variable with 3 levels. While performing model selection in R with the anova() function, the categorical variable "category" is maintained:

`#it is a linear mixed model because condition is normally distributed
> lmm.1 <- lmer(condition ~ category.of.urbanization + (1|river), data = fish) 
> lmm.null <- lmer(condition ~ 1 + (1|river), data = fish) 
> anova(lmm.null, lmm.1)
refitting model(s) with ML (instead of REML)
Data: fish
Models:
lmm.null: condition ~ 1 + (1 | river)
lmm.1: condition ~ category.of.urbanization + (1 | river)
            npar     AIC     BIC logLik deviance  Chisq Df Pr(>Chisq)   
lmm.null       3 -214.42 -205.37 110.21  -220.42                        
lmm.1          5 -219.80 -204.71 114.90  -229.80 9.3806  2   0.009184 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1`

` I had forgotten to include my model's summary in my my question, so here it is:

> summary(lmm.1)
Linear mixed model fit by REML ['lmerMod']
Formula: condition ~ category.of.urbanization + (1 | river)
Data: fish

REML criterion at convergence: -214.3

Scaled residuals: 
Min       1Q   Median       3Q      Max 
-2.65967 -0.54776 -0.07734  0.56748  2.79995 

Random effects:
Groups   Name        Variance Std.Dev.
river    (Intercept) 0.001965 0.04432 
Residual             0.012381 0.11127 
Number of obs: 151, groups:  river, 6

Fixed effects:
                                 Estimate Std. Error t value
(Intercept)                      -0.12808    0.04154  -3.084
category.of.urbanizationslightly  0.15972    0.05376   2.971
category.of.urbanizationvery      0.17063    0.05432   3.141

Correlation of Fixed Effects:
              (Intr) ctgr.d.rbnzcp
ctgr.d.rbnzcp -0.773              
ctgr.d.rbnzcm -0.765  0.591    

My p-value is 0.009184, meaning category of urbanization is an important predictor, and I expected that at least one level of the categorical variable would be different from the others. However, when trying to do a post hoc analysis, I called the emmeans() function, and R says that none of the levels differ, because the p-values are all above 0.05:

`> emmeans(lmm.1, pairwise ~ category.of.urbanization)
Registered S3 methods overwritten by 'broom':
method            from  
tidy.glht         jtools
tidy.summary.glht jtools
$emmeans
category.of.urbanization  emmean     SE   df lower.CL upper.CL
preserved                -0.1281 0.0441 3.42  -0.2592  0.00304
slightly urban            0.0316 0.0341 2.20  -0.1030  0.16632
very urban                0.0425 0.0350 2.43  -0.0852  0.17032

Degrees-of-freedom method: kenward-roger 
Confidence level used: 0.95 

$contrasts
contrast                    estimate     SE   df t.ratio p.value
preserved - slightly urban   -0.1597 0.0558 2.83  -2.863  0.1324
preserved - very urban       -0.1706 0.0563 2.95  -3.028  0.1123
slightly urban - very urban  -0.0109 0.0489 2.32  -0.223  0.9733

Degrees-of-freedom method: kenward-roger 
P value adjustment: tukey method for comparing a family of 3 estimates `

Please, what does this mean? How is the predictor variable significant, but with levels that aren't different? I have 151 fish, so my number of data and observations is not very low. I am sorry if I've made spelling mistakes, English is not my native language.

$\endgroup$
4
  • 1
    $\begingroup$ One really important piece of the answer is that p>0.05 does not mean that the none of the levels differ! That's too strong of a conclusion. It means that you did see differences in your sample, but that you'd expect to see differences of that size (or larger) more than 5% of the time. Not only that, p<0.05 does not mean "important"! You can have term with p<0.05 but the size of the effect is so small you don't care. $\endgroup$ Commented Oct 16 at 20:26
  • $\begingroup$ Sorry for taking so long to reply, I have been very busy lately...So, what you are saying is even if the p-values are above 0.05, my levels could still be different from each other? I'm not sure I understand how...could you please elaborate a little more? Thank you very much for your help! $\endgroup$
    – Alan
    Commented Oct 21 at 21:43
  • $\begingroup$ That's a bigger answer than fits in a comment and is part of the much bigger question of how to interpret p-values correctly. There are many questions about that on the site, and lots of other resources elsewhere too. $\endgroup$ Commented Oct 22 at 22:05
  • 1
    $\begingroup$ @Aaron-mostlyinactive sorry again for taking so long to reply, and thank you for your help, I will keep studying this subject. I am new on Stack Exchange, so I am still learning a lot $\endgroup$
    – Alan
    Commented Oct 29 at 18:03

3 Answers 3

14
$\begingroup$

Some important information that you did not show is the between and within river variability (do a summary on the lmm.1 object). You have 151 fish, but only 6 rivers. If the between river variability is large relative to the within river variability then the 6 is the much more important number for the power of the inference.

Note also the degrees of freedom in the comparisons, they are very low (below 3). Remember that all the p-values are approximations once we go beyond simple models. You are computing approximate p-values based on the chi-squared distribution in one case and from a t distribution with fewer than 3 degrees of freedom in the other case. The square of a t is asymptotically chi-squared as the number of degrees of freedom go to infinity, so for large enough samples they should agree, but 3 d.f. is not large enough to expect agreement. I expect that the p-value based on the chi-squared is overly optimistic and those on the t a little bit pessimistic.

I would look at the estimates of the means as well as the differences and determine if those are potentially meaningful differences (practical significance), because if not, then there really is not reason to proceed. If they are potentially meaningful, then you either need more data (more rivers will be more important than more fish in the current rivers) or another way to bring in more information (possibly use a Bayesian analysis with informative priors).

$\endgroup$
8
  • $\begingroup$ Sorry, I had forgotten the summary. I just edited my question and included it in it. The variability between rivers is slightly smaller than the variability within them. How can this impact the post hoc test? $\endgroup$
    – Alan
    Commented Oct 16 at 11:58
  • 1
    $\begingroup$ @Alan, I don't have a quick fix for you. But from looking at the summary I would still say that the degrees of freedom for the Chi-square distribution are too high (infinity) and the values less than 3 are probably lower than needed. You should look through the vignettes and documentation for emmeans to find alternative ways of computing the degrees of freedom that better capture the information that you have. $\endgroup$
    – Greg Snow
    Commented Oct 16 at 16:27
  • $\begingroup$ The lmerTest package is worth looking into, I believe it uses Kenward-Roger df in its ANOVA table. But do consider Greg's last paragraph about looking at the size of the effects first. $\endgroup$ Commented Oct 17 at 17:50
  • $\begingroup$ You guys, sorry for taking so long to reply, I've been very busy lately...Well, in my project I could only work with 6 rivers, we couldn't find more rivers that met our requirements for the study, unfortunately. So, if I look into emmeans() documentation and don't find alternative ways of computing the degrees of freedom, do you think it would be acceptable to accept the results the way they are? I mean, to write in the paper that the category was important but the levels didn't differ? I've once heard that such cases do occur. Thank you very much for your help! $\endgroup$
    – Alan
    Commented Oct 21 at 21:34
  • $\begingroup$ @Alan based on 6 rivers, and only two per each factor level, it is difficult to generalise to other rivers. What you could do is simply make a table or plot of the results for the six rivers (possibly without random effects), and commentate on those results with a warning about interpreting the results as conclusive because of the low significance (with 6 rivers you cannot generalise and you need to be open for the possibility that your results are plain coincidence). Possibly there is more data elsewhere, and people can combine results, or use your data for priors in new research. $\endgroup$ Commented Oct 21 at 21:56
7
$\begingroup$

Already without the mixed effects, you can get differences between different tests. Because

Below is a simulation in R for a situation without mixed effects that shows how you can get the discrepancies.

You get different p-values

TEST                  p-value
Likelihood ratio test 0.011 
ANOVA test            0.103
TukeyHSD              0.129

Code:

### dummy data
d = 0.25
y = c(0,0,1,1,1,1) +
    c(-d,d,
      -d,d,
      -d,d)
x = as.factor(c(0,0,1,1,2,2))

mm = lm(y~x)

### LR test 0.01058
lmtest::lrtest(mm)

### ANOVA test 0.103
mod = aov(mm)
summary(mod)

### Tukey test 0.128822
TukeyHSD(mod)
$\endgroup$
6
  • $\begingroup$ I wonder whether I used the functions too easily and possibly made a mistake. I would have thought that Anova and LR test are equivalent for the assumption of normal distributed data. $\endgroup$ Commented Oct 15 at 16:26
  • $\begingroup$ Ah, no, they are not the same. There is a relation between the two statistics $$\log \Lambda = -\frac{n}{2} \log \left( \frac{RSS_0}{RSS_1}\right) = \frac{n}{2} \log \left( 1+F \frac{k_1-k_0}{n-k_1}\right)$$ but $\Lambda$ is far from chi-squared distributed if $n$ is small. Replicate t or F test from regression using regression likelihoods $\endgroup$ Commented Oct 15 at 16:29
  • $\begingroup$ We could use the relationship from the previous comment to make adjustments for the likelihood ratio based on curves of p-values for an F-test versus p-values for an LR test. $\endgroup$ Commented Oct 15 at 16:35
  • $\begingroup$ So, anova saying the category is important but the emmeans function saying the levels are not different is a common thing? Thank you for your help! $\endgroup$
    – Alan
    Commented Oct 21 at 21:42
  • 1
    $\begingroup$ Also, small detail in the language use. A test doesn't say whether levels are different. For this you simply fit the result and look at the estimated levels, and compute the difference. What the test does is saying what the 'statistical significance' is of the observed difference. $\endgroup$ Commented Oct 21 at 21:48
2
$\begingroup$

There are two things going on:

  1. You may have a lot of fish, but the experimental units for category.of.urbanization are the rivers, not the fish. For that reason, the degrees of freedom for each comparison is quite low. So although the $t$ ratios for comparing preserved with the other two conditions are similar to the model output, the degrees of freedom are both less than 3, and that makes the P values large.

  2. In addition, as annotated in the emmeans output, the P values for the comparisons are Tukey-adjusted, and that inflates the P values, whereas the ones in the model summary are unadjusted (and also use the wrong d.f.)

$\endgroup$
2
  • $\begingroup$ The std. errors are also different between the summary output and the emmeans contrasts output. Is this due to the Tukey adjustment also? $\endgroup$
    – dipetkov
    Commented Nov 30 at 20:23
  • 1
    $\begingroup$ @dipetkov No. I don't know why those differ. I think they may differ slightly because the summary output uses the unadjusted covariance matrix while emmeans uses the adjusted covariance estimates in the K-R method. You can check this by adding mode = "satt" to the emmeans call; then I think they'll agree. $\endgroup$
    – Russ Lenth
    Commented Dec 8 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.