作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以,我在 R 中拟合了一个带有两个随机截距的线性混合模型:
Y = X beta + Z b + e_i,
b ~ MVN (0, Sigma)
;
X
和
Z
分别是固定和随机效应模型矩阵,
beta
和
b
是固定效果参数和随机效果 BLUP/条件模式。
b
的底层协方差矩阵,这在
lme4
中似乎不是一件小事包裹。您只能通过
VarCorr
获得方差,不是实际的相关矩阵。
e_i * lambda * t(lambda)
.以及您可以从
lme4
的输出中提取的所有组件.
最佳答案
来自 ?ranef
:
If ‘condVar’ is ‘TRUE’ each of the data frames has an attribute called ‘"postVar"’ which is a three-dimensional array with symmetric faces; each face contains the variance-covariance matrix for a particular level of the grouping factor. (The name of this attribute is a historical artifact, and may be changed to ‘condVar’ at some point in the future.)
library(lme4)
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
rr <- ranef(fm1,condVar=TRUE)
b
之间的方差-协方差矩阵截距值
pv <- attr(rr[[1]],"postVar")
str(pv)
##num [1:2, 1:2, 1:18] 145.71 -21.44 -21.44 5.31 145.71 ...
getMethod("image",sig="dgTMatrix")
...)
library(Matrix)
vc <- bdiag( ## make a block-diagonal matrix
lapply(
## split 3d array into a list of sub-matrices
split(pv,slice.index(pv,3)),
## ... put them back into 2x2 matrices
matrix,2))
image(vc,sub="",xlab="",ylab="",useRaster=TRUE)
关于r - 如何从 lme4 获得随机效应(BLUPs/条件模式)的协方差矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37789299/
我是一名优秀的程序员,十分优秀!