emmeans adds Days together

51 Views Asked by At

I want to do a posthoc / pairwise comparison with emmeans. My model says, as soon as I add Day as an explanatory variable, it gets significant. But when I do posthoc analyses, it gets weird and I get the following result: For some reasons, R gives me 5.1 as Day, in my minimal reproducible example it is 5.33.

Day emmean    SE   df lower.CL upper.CL .group
5.1   14.2 0.993 4.36     11.5     16.9  A    

For some context: Over two weeks, i incubated different Treeorgans of two tree species and took samples every so often (Day 1, Day 2, Day 3, Day 5, Day 8, etc) and measured various things with these samples. Unfortunately, because of some technical issues, some days are not the same for both species, e.g., Experiment of Species 1 ends after 14 days; for Species 2, it ends after 16 days. Could this maybe be the issue ? How do I fix it? (Day is continuous)

Here is an example of how my dataset looks like

ID  Species         Organ   TreeNR  Day Result
#1  Fagus sylvatica Roots   Tree1   0   30.7
#2  Fagus sylvatica Leaves  Tree1   0   10.3
#3  Fagus sylvatica Roots   Tree2   0   20.0
#4  Fagus sylvatica Leaves  Tree2   0   10.0
#5  Fagus sylvatica Roots   Tree1   1   16.4
#6  Fagus sylvatica Leaves  Tree1   1   -3.7
#7  Fagus sylvatica Roots   Tree2   1   15.0
#8  Fagus sylvatica Leaves  Tree2   1   -6.0
#9  Fagus sylvatica Roots   Tree1   14  17.3
#10 Fagus sylvatica Leaves  Tree1   14  13.0
#11 Fagus sylvatica Roots   Tree2   14  12.0
#12 Fagus sylvatica Leaves  Tree2   14  13.0
#13 Picea abies Roots   Tree1   0   7.9
#14 Picea abies Leaves  Tree1   0   7.2
#15 Picea abies Roots   Tree2   0   10.0
#16 Picea abies Leaves  Tree2   0   12.0
#17 Picea abies Roots   Tree1   1   30.4
#18 Picea abies Leaves  Tree1   1   7.5
#19 Picea abies Roots   Tree2   1   12.0
#20 Picea abies Leaves  Tree2   1   13.0
#21 Picea abies Roots   Tree1   16  17.8
#22 Picea abies Leaves  Tree1   16  18.5
#23 Picea abies Roots   Tree2   16  20.0
#24 Picea abies Leaves  Tree2   16  21.0

Here is the model in question:

model4 <- lmer((D14C_sugar) ~  Species + Organ + Day + (1|TreeNR), REML = FALSE, data = Sol)

if(requireNamespace("multcomp")) {
  model4_ph <-lmer((D14C_sugar) ~  Species + Organ + Day + (1|TreeNR), REML = T, data = Sol)
  model4_ph.emm <- emmeans (model4_ph, ~ Day) 
  multcomp::cld(model4_ph.emm, alpha = 0.05, Letters = LETTERS)
}

summary of model


Linear mixed model fit by maximum likelihood  ['lmerMod']
Formula: (Result) ~ Species + Organ + Day + (1 | TreeNR)
   Data: Sol

     AIC      BIC   logLik deviance df.resid 
  1075.8   1096.7   -530.9   1061.8      138 

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.7659 -0.5320  0.0367  0.5097  3.4541 

Random effects:
 Groups   Name        Variance Std.Dev.
 TreeNR   (Intercept)  0.7387  0.8595  
 Residual             88.0164  9.3817  
Number of obs: 145, groups:  TreeNR, 5
```r
1

There are 1 best solutions below

3
jkd On

This is because Day is a numeric (thus continuous) variable. Therefore emmeans will average its value. To perform comparisons at specific days, you can use the at argument of the emmeans function.

model4_ph.emm <- emmeans(model4_ph, ~ Day, at=list(Day=c(0, 1))
contrast(model4_ph.emm, "tukey")