I am analysing the effect of cover of two invasive species (Solidago spp.) on the diversity of invaded plant communities. I am using a linear mixed model - the function lmer in the R package lme4. The response variable is species richness, the explanatory variables are categorical - invasive species (2 levels), cover of invasive species (3 levels) and their interaction.
While the results of the anova (the function Anova, type 3 and 2; the package car) suggest no significant interaction, visual inspection of the boxplot suggests the opposite, which was confirmed by a post-hoc test (the function avg_comparisons from the package marginaleffects).
Anova results:
Analysis of Deviance Table (Type II Wald chisquare tests)
Response: Hillall_0
Chisq Df Pr(>Chisq)
solidago 14.2077 1 0.0001637 ***
plot 11.7648 2 0.0027881 **
solidago:plot 4.7284 2 0.0940244 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Post-hoc test result:
> avg_comparisons(m1, variables = "solidago", by = "plot")
Term Contrast plot Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
solidago mean(gigantea) - mean(canadensis) C -12.4 4.33 -2.861 0.00423 7.9 -20.9 -3.9
solidago mean(gigantea) - mean(canadensis) D -1.8 4.33 -0.415 0.67796 0.6 -10.3 6.7
solidago mean(gigantea) - mean(canadensis) T -14.1 4.33 -3.253 0.00114 9.8 -22.6 -5.6
Reproductible example below.
Why this discrepancy and what should I do?
(After fitting the model, I got this error message: "boundary (singular) fit: see help('isSingular')". Thus, according to R Documentation, there are concerns that standard inferential procedures such as Wald statistics and likelihood ratio tests may be inappropriate. Could this be the cause of the discrepancy between results of anova and post-hoc test?)
Reproductible example:
#> dput(dat)
structure(list(solidago = c("canadensis", "canadensis", "canadensis",
"canadensis", "canadensis", "canadensis", "canadensis", "canadensis",
"canadensis", "canadensis", "canadensis", "canadensis", "canadensis",
"canadensis", "canadensis", "canadensis", "canadensis", "canadensis",
"canadensis", "canadensis", "canadensis", "canadensis", "canadensis",
"canadensis", "canadensis", "canadensis", "canadensis", "canadensis",
"canadensis", "canadensis", "gigantea", "gigantea", "gigantea",
"gigantea", "gigantea", "gigantea", "gigantea", "gigantea", "gigantea",
"gigantea", "gigantea", "gigantea", "gigantea", "gigantea", "gigantea",
"gigantea", "gigantea", "gigantea", "gigantea", "gigantea", "gigantea",
"gigantea", "gigantea", "gigantea", "gigantea", "gigantea", "gigantea",
"gigantea", "gigantea", "gigantea"), locality = c("HOS", "TOR",
"BAK", "PCH", "SLT", "GEM", "HRN", "BAR", "HAJ", "HOK", "HOS",
"TOR", "BAK", "PCH", "SLT", "GEM", "HRN", "BAR", "HAJ", "HOK",
"HOS", "TOR", "BAK", "PCH", "SLT", "GEM", "HRN", "BAR", "HAJ",
"HOK", "SVJ", "TOM", "KUT", "PER", "IZA", "CHL", "CEN", "MAS",
"KKR", "GAB", "SVJ", "TOM", "KUT", "PER", "IZA", "CHL", "CEN",
"MAS", "KKR", "GAB", "SVJ", "TOM", "KUT", "PER", "IZA", "CHL",
"CEN", "MAS", "KKR", "GAB"), plot = c("C", "C", "C", "C", "C",
"C", "C", "C", "C", "C", "T", "T", "T", "T", "T", "T", "T", "T",
"T", "T", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "C",
"C", "C", "C", "C", "C", "C", "C", "C", "C", "T", "T", "T", "T",
"T", "T", "T", "T", "T", "T", "D", "D", "D", "D", "D", "D", "D",
"D", "D", "D"), Hillall_0 = c(49L, 52L, 40L, 38L, 39L, 30L, 38L,
41L, 29L, 64L, 49L, 51L, 48L, 58L, 51L, 32L, 25L, 34L, 33L, 39L,
35L, 24L, 23L, 29L, 40L, 37L, 39L, 11L, 17L, 17L, 20L, 27L, 23L,
38L, 24L, 25L, 35L, 34L, 29L, 41L, 34L, 26L, 26L, 24L, 26L, 40L,
47L, 27L, 17L, 12L, 8L, 30L, 32L, 28L, 29L, 30L, 11L, 24L, 32L,
30L)), class = "data.frame", row.names = c(NA, -60L))
R script:
attach(dat)
library(lme4)
library(car)
library(marginaleffects)
m1<-lmer(Hillall_0 ~ solidago * plot + (1 | locality), data=dat)
Anova(m1, type="III", icontrasts=c("contr.sum", "contr.poly"))
Anova(m1, type="II")
avg_comparisons(m1, variables = "solidago", by = "plot")


