如何为lmer模型结果绘制带有标准误差的预测值? [英] How to plot predicted values with standard errors for lmer model results?
问题描述
我有一个针对四个位置和四个底物(从每个位置获取)的移植实验.我已经确定了每个人群在每个位置和底物组合中的存活率.该实验重复了三遍.
I have a transplant experiment for four locations and four substrates (taken from each location). I have determined survival for each population in each location and substrate combination. This experiment was replicated three times.
我创建了一个如下所示的lmm:
I have created a lmm as follows:
Survival.model <- lmer(Survival ~ Location + Substrate + Location:Substrate + (1|Replicate), data=Transplant.Survival,, REML = TRUE)
我想使用predict命令提取预测,例如:
I would like to use the predict command to extract predictions, for example:
Survival.pred <- predict(Survival.model)
然后提取标准错误,以便我可以将其与预测一起绘制以生成类似以下图的内容:
Then extract standard errors so that I can plot them with the predictions to generate something like the following plot:
我知道如何使用标准的glm(这是我创建示例图的方式)来执行此操作,但是不确定是否可以或应该使用lmm来执行此操作.
I know how to do this with a standard glm (which is how I created the example plot), but am not sure if I can or should do this with an lmm.
我可以做这件事吗,或者我是线性混合模型的新用户,但缺少一些基本知识?
Can I do this or am I as a new user of linear mixed models missing something fundamental?
我确实在Stack Overflow上找到了这个 post 没有帮助.
I did find this post on Stack Overflow which was not helpful.
根据RHertel的评论,也许我应该用 问题:如何绘制模型估计值和置信区间 我的lmer模型得到了结果,因此我可以获得与我相似的图 在上面创建了?
Based on a comment from RHertel, maybe I should have phrased the question: How do I plot model estimates and confidence intervals for my lmer model results so that I can get a similar plot to the one I have created above?
样本数据:
Transplant.Survival <- structure(list(Location = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Steninge", "Molle",
"Kampinge", "Kaseberga"), class = "factor"), Substrate = structure(c(1L,
1L, 1L, 2L, 2L, 2L, 3L, 3L, 4L, 4L, 4L, 1L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 4L, 4L, 4L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L,
4L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L), .Label = c("Steninge",
"Molle", "Kampinge", "Kaseberga"), class = "factor"), Replicate = structure(c(1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 2L, 3L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("1",
"2", "3"), class = "factor"), Survival = c(1, 1, 1, 0.633333333333333,
0.966666666666667, 0.5, 0.3, 0.233333333333333, 0.433333333333333,
0.966666666666667, 0.866666666666667, 0.5, 0.6, 0.266666666666667,
0.733333333333333, 0.6, 0.3, 0.5, 0.3, 0.633333333333333, 0.9,
0.266666666666667, 0.633333333333333, 0.7, 0.633333333333333,
0.833333333333333, 0.9, 0.6, 0.166666666666667, 0.333333333333333,
0.433333333333333, 0.6, 0.9, 0.6, 0.133333333333333, 0.566666666666667,
0.633333333333333, 0.633333333333333, 0.766666666666667, 0.766666666666667,
0.0333333333333333, 0.733333333333333, 0.3, 1.03333333333333,
0.6, 1)), .Names = c("Location", "Substrate", "Replicate", "Survival"
), class = "data.frame", row.names = c(NA, -46L))
推荐答案
修复了函数/图形中的错误.
如果要使用CI绘制估计值,则可能需要查看sjPlot
包中的sjp.lmer
函数.
If you like to plot estimates with CI, you may want to look at the sjp.lmer
function in the sjPlot
package. See some example of the various plot types here.
此外,arm
软件包提供了用于计算标准错误(arm::se.fixef
和arm::se.ranef
)
Furthermore, the arm
package provides function for computing standard Errors (arm::se.fixef
and arm::se.ranef
)
sjp.setTheme("forestgrey") # plot theme
sjp.lmer(Survival.model, type = "fe")
将给出以下情节
这篇关于如何为lmer模型结果绘制带有标准误差的预测值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!