简体   繁体   English

如何为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. 该实验重复三次。

I have created a lmm as follows: 我创建了一个lmm如下:

Survival.model <- lmer(Survival ~ Location + Substrate + Location:Substrate + (1|Replicate), data=Transplant.Survival,, REML = TRUE)

I would like to use the predict command to extract predictions, for example: 我想使用predict命令来提取预测,例如:

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: 然后提取标准误差,以便我可以使用预测绘制它们,以生成如下图:

在此输入图像描述

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. 我知道如何使用标准glm(这是我创建示例图的方式),但我不确定我是否能够或应该用lmm做到这一点。

Can I do this or am I as a new user of linear mixed models missing something fundamental? 我可以这样做,还是我作为线性混合模型的新用户缺​​少一些基本的东西?

I did find this post on Stack Overflow which was not helpful. 我确实在Stack Overflow上找到了这篇文章 ,但没有用。

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? 根据RHertel的评论,也许我应该提出这样的问题:如何绘制我的模型结果的模型估计和置信区间,以便我可以得到与上面创建的模型类似的情节?

Sample Data: 样本数据:

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))

Edit: fixed bug in function / figure. 编辑:修复了函数/图中的bug。

If you like to plot estimates with CI, you may want to look at the sjp.lmer function in the sjPlot package. 如果您想使用CI绘制估计值,您可能需要查看sjPlot包中的sjp.lmer函数。 See some example of the various plot types here . 在这里查看各种绘图类型的一些示例。

Furthermore, the arm package provides function for computing standard Errors ( arm::se.fixef and arm::se.ranef ) 此外, arm包提供了计算标准错误的功能( arm::se.fixefarm::se.ranef

sjp.setTheme("forestgrey") # plot theme
sjp.lmer(Survival.model, type = "fe")

would give following plot 会给出下面的情节

在此输入图像描述

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

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