简体   繁体   English

如何测试线性混合效应模型(lmer)在 R 中是否大于 1?

[英]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?在下面的虚拟数据中,我想测试A和B的oviposition index是否与1显着不同。如果我理解正确,summary(mod)说每个物种是否与0显着不同。如何更改默认值测试它是否与1不同? Here, I expect species B to be significantly different from 1 as the confidence intervals don't include 1在这里,我希望物种B与 1 显着不同,因为置信区间不包括 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) 

在此处输入图片说明

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:通过指定您想要对每个物种进行单独估计而不是对物种 A 的估计 + 对差异的估计,让您走到了一半,但是如果您想针对 index = 1 的零假设进行测试,您只需从响应中减去 1 :

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

You could alternatively add an offset (ie 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).您也可以添加一个偏移量(即,将+offset(rep(1, nrow(df)))到您的模型中),但它对于线性模型来说太过分了(这对于调整零点并不那么容易的 GLM 很有用)。

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.我要添加一个警告,在这里很容易走上一条糟糕的道路:你可能有充分的理由分别测试每个物种的重要性,但继续(可能是自然的)得出结论“物种 B 有一个 OI与 1 显着不同,而物种 A 没有,因此它们不同”是一个错误。 As Andrew Gelman says, "the difference between significant and non-significant is not statistically significant".正如 Andrew Gelman 所说,“显着性和非显着性之间的差异在统计上并不显着”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM