工作数据如下所示:
set.seed(1234)
df <- data.frame(y = rnorm(1:30),
fac1 = as.factor(sample(c("A","B","C","D","E"),30, replace = T)),
fac2 = as.factor(sample(c("NY","NC","CA"),30,replace = T)),
x = rnorm(1:30))
lme
模型拟合为:
library(lme4)
mixed <- lmer(y ~ x + (1|fac1) + (1|fac2), data = df)
我曾经bootMer
运行参数引导,我可以成功地获得固定和随机效果的系数(截距)和 SE:
mixed_boot_sum <- function(data){s <- sigma(data)
c(beta = getME(data, "fixef"), theta = getME(data, "theta"), sigma = s)}
mixed_boot <- bootMer(mixed, FUN = mixed_boot_sum, nsim = 100, type = "parametric", use.u = FALSE)
我的第一个问题是如何从引导结果中获得两个随机效应的每个单独水平的系数(斜率)mixed_boot
?
通过使用包中的函数从mixed
模型中提取系数(斜率)没有问题,见下文:augment
broom
library(broom)
mixed.coef <- augment(mixed, df)
但是,似乎broom
无法处理boot
类对象。我不能直接在mixed_boot
.
我也尝试mixed_boot_sum
通过添加来修改mmList
(我认为这将是我正在寻找的),但 R 抱怨为:</p>
Error in bootMer(mixed, FUN = mixed_boot_sum, nsim = 100, type = "parametric", :
bootMer currently only handles functions that return numeric vectors
此外,是否可以通过指定同时获得固定和随机效果的 CI FUN
?
FUN
现在,为了满足我的需求,我对正确的规范感到非常困惑。任何有关我的问题的帮助将不胜感激!