混合效应模型中的置信区间

Confidence Interval in mixed effect models

library(lme4)

fm1 <- lmer(Reaction ~ Days + (Days|Subject), data = sleepstudy)

要生成 95% CI,我可以使用 merTools.

包中的 predictInterval() 函数
library(merTools)
head(predictInterval(fm1, level = 0.95, seed = 123, n.sims = 100))
# fit      upr      lwr
# 1 255.4179 313.8781 184.1400
# 2 273.2944 333.2005 231.3584
# 3 291.8451 342.8701 240.8226
# 4 311.3562 359.2908 250.4980
# 5 330.3671 384.2520 270.7094
# 6 353.4378 409.9307 289.4760

在文档中,它提到了 predictInterval() 函数

This function provides a way to capture model uncertainty in predictions from multi-level models fit with lme4. By drawing a sampling distribution for the random and the fixed effects and then estimating the fitted value across that distribution, it is possible to generate a prediction interval for fitted values that includes all variation in the model except for variation in the covariance parameters, theta. This is a much faster alternative than bootstrapping for models fit to medium to large datasets.

我的目标是获取所有拟合值而不是上限值和下限值 CI 即对于每一行,我需要 计算出这 95% CI 的原始 n 次模拟。我检查了文档中的参数并且 跟着这个:

head(predictInterval(fm1, n.sims = 100, returnSims = TRUE, seed = 123, level = 0.95))
# fit      upr      lwr
# 1 255.4179 313.8781 184.1400
# 2 273.2944 333.2005 231.3584
# 3 291.8451 342.8701 240.8226
# 4 311.3562 359.2908 250.4980
# 5 330.3671 384.2520 270.7094
# 6 353.4378 409.9307 289.4760

它没有得到 100 次模拟,它仍然给我相同的输出。我这里做错了什么?

第二个问题,但我认为这更像是一个 StatsExchange 问题。

"By drawing a sampling distribution for the random and the fixed effects and then."`

如果有人能解释一下,它是如何绘制抽样分布的?

如果在predictInterval()函数中指定newdata,就可以获得模拟值。

predInt <- predictInterval(fm1, newdata = sleepstudy, n.sims = 100,
           returnSims = TRUE, seed = 123, level = 0.95)

simValues <- attr(predInt, "sim.results")

有关如何创建参数抽样分布的详细信息,请参阅帮助的详细信息部分page.You 可以获得拟合的估计值、下边界和上边界:

fit <- apply(simValues, 1, function(x){quantile(x, probs=0.500) } )
lwr <- apply(simValues, 1, function(x){quantile(x, probs=0.025) } )
upr <- apply(simValues, 1, function(x){quantile(x, probs=0.975) } )