r - lme4 中 lme4 随机效应预测的标准误差
问题描述
我对具有不同生长习性 ( growth_type
)、嵌套在生长类型中的基因型 ( ge
) 以及也嵌套在生长类型中的块 ( block
) 进行了实验。目的是测试植物性能的生长类型和基因型的影响。这是一个示例数据和可重现的示例。
data1 <- read.csv(text = "
growth_type,ge,block,performance
dwarf,A,1,128.32
dwarf,A,2,97.01
dwarf,A,3,91.05
dwarf,B,1,108.51
dwarf,B,2,121.11
dwarf,B,3,84.15
dwarf,C,1,132.55
dwarf,C,2,129.45
dwarf,C,3,122.33
tall,D,1,79.68
tall,D,2,122.5
tall,D,3,143.42
tall,E,1,149.29
tall,E,2,162.13
tall,E,3,135.42
tall,F,1,90.45
tall,F,2,127.4
tall,F,3,78.99")
这些是我使用的库:
library(dplyr)
library(lme4)
library(lsmeans)
第一步是拟合模型:
model.fit <-
lmer(performance ~ growth_type + (1 | block:growth_type) + (1 | ge:growth_type),
data = data1)
从这个模型中,我可以使用以下方法提取增长类型的固定效应lsmeans
:
fixed.effect.estimates <- lsmeans::lsmeans(model.fit, "growth_type")
这是输出:
我需要获得的是随机效应的相同输出。我能够获得预测区间,但无法获得标准误差。这是我尝试过的:
# RANDOM EFFECT ESTIMATES
data1$pred.performance <-
predict(model.fit,
newdata = data1,
re.form= ~(1 | ge:growth_type))
pred.ge <- data1 %>%
distinct(ge, growth_type, pred.performance)
这就是我得到的。到目前为止,一切都很好。
然后我使用该bootMer
函数通过引导建立预测区间。
mySumm <- function(.) {
predict(., newdata=pred.ge, re.form= ~(1 | ge:growth_type))
}
####Collapse bootstrap into median, 95% PI
sumBoot <- function(merBoot) {
return(
data.frame(fit = apply(merBoot$t, 2, function(x) as.numeric(quantile(x, probs=.5, na.rm=TRUE))),
lwr = apply(merBoot$t, 2, function(x) as.numeric(quantile(x, probs=.025, na.rm=TRUE))),
upr = apply(merBoot$t, 2, function(x) as.numeric(quantile(x, probs=.975, na.rm=TRUE)))
)
)
}
##lme4::bootMer() method 1
PI.boot1.time <- system.time(
boot1 <- lme4::bootMer(model.fit, mySumm, nsim=250, use.u=TRUE, type="parametric")
)
PI.boot1 <- sumBoot(boot1)
cbind(pred.ge, PI.boot1)
这是我得到的:
总之,我的问题是:
- 我怎样才能像我对固定效果组件所做的那样获得标准错误?
- 为什么随机效应估计与
lme4::predict
不同lme4::bootMer
?
抱歉,解释太长了。
解决方案
推荐阅读
- javascript - 如果选项对象不存在,则将布尔值设置为默认值
- c# - 使用 WebMethod 从数组中获取值
- angular - 将 Angular http 调用迁移到 v6
- c# - 必须在数据库上搜索查询,例如名称并吐出任何相似的内容
- matlab - 如何在 Matlab 中对矢量数据进行数值积分?
- javascript - 尝试插入新事件时 API 日历出现问题
- amazon-web-services - Kubectl:使用 route53 私有托管区域访问 kubernetes 集群
- python - python - 如何在没有重叠的情况下在python中找到字符串中的一些连续字母?
- python - 在 Python 中查询正则表达式模式
- ios - 随机词(有意义的)生成