Rspacer
Rspacer

Reputation: 2429

How to test if linear mixed effects model (lmer) is greater than 1 in R?

In the following dummy data, I want to test if the oviposition index of A and B are significantly different from 1. If I understand correctly, the summary(mod) says if each species is significantly different from 0. How do I change the default to test if its different from 1? Here, I expect species B to be significantly different from 1 as the confidence intervals don't include 1

set.seed(111)
oviposition.index <- rnorm(20, 2, 1.3)
species <- rep(c("A","B"), each = 10)
month <- rep(c("Jan", "Feb"), times = 10)
plot <- rep(c("1", "2"), times = 10)
df <- data.frame(oviposition.index, species, month, plot)

mod <- lmer(oviposition.index ~ species + (1|month/plot), df)
summary(mod)

ggplot(df, aes(x = species, y = oviposition.index, color = species)) + geom_point() + geom_hline(yintercept = 1) + stat_summary(fun.data=mean_cl_boot, geom="errorbar", width=0.2, colour="black") + stat_summary(fun = mean, color = "black", geom ="point", size = 3,show.legend = FALSE) 

enter image description here

Upvotes: 1

Views: 329

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226547

Nate's comment

lmer(oviposition.index ~ 0 + species + (1|month/plot), df)

gets you partway there by specifying that you want separate estimates for each species rather than an estimate of species A + an estimate of the difference, but if you want to test against a null hypothesis of index = 1 you can just subtract 1 from the response:

lmer(oviposition.index - 1 ~ 0 + species + (1|month/plot), df)

You could alternatively add an offset (i.e. add +offset(rep(1, nrow(df))) to your model), but it's overkill for a linear model (it's useful for GLMs where adjusting the zero point is not as easy).

I would add a note of caution that it's easy to go down a bad road here: you may have good reasons for testing the significance of each species separately, but proceeding (as might be natural) to conclude that "species B has an OI that differs significantly from 1 while species A doesn't, therefore they differ" is a mistake. As Andrew Gelman says, "the difference between significant and non-significant is not statistically significant".

Upvotes: 2

Related Questions