我正在使用lmer
from lme4
package 来计算方差分量的置信区间。
当我拟合模型时,会出现警告消息:
fit <- lmer(Y~X+Z+X:Z+(X|group),data=sim_data)
Warning messages:
1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
unable to evaluate scaled gradient
2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge: degenerate Hessian with 1 negative eigenvalues
我搜索了很多以了解为什么会发生错误并最终做出决定there is difference between error and warning in the R world
。
我想计算模型参数的置信区间并运行显示错误的代码:
confint.merMod(fit,oldNames=FALSE)
Computing profile confidence intervals ...
Error in if (all(x[iu <- upper.tri(x)] == 0)) t(x[!iu]) else t(x)[!iu] :
missing value where TRUE/FALSE needed
是否有另一种方法可以使用 lmer 获得随机效应的 CI?
编辑 :
simfun <- function(J,n_j,g00,g10,g01,g11,sig2_0,sig01,sig2_1){
N <- sum(rep(n_j,J))
x <- rnorm(N)
z <- rnorm(J)
mu <- c(0,0)
sig <- matrix(c(sig2_0,sig01,sig01,sig2_1),ncol=2)
u <- rmvnorm(J,mean=mu,sigma=sig)
b_0j <- g00 + g01*z + u[,1]
b_1j <- g10 + g11*z + u[,2]
y <- rep(b_0j,each=n_j)+rep(b_1j,each=n_j)*x + rnorm(N,0,0.5)
data <- data.frame(Y=y,X=x,Z=rep(z,each=n_j),group=rep(1:J,each=n_j))
}
noncoverage <- function(J,n_j,g00,g10,g01,g11,sig2_0,sig01,sig2_1){
dat <- simfun(J,n_j,g00,g10,g01,g11,sig2_0,sig01,sig2_1)
fit <- lmer(Y~X+Z+X:Z+(X|group),data=dat)
}
comb1 = replicate(1000,noncoverage(10,5,1,.3,.3,.3,(1/18),0,(1/18)))
comb26 = replicate(1000,noncoverage(100,50,1,.3,.3,.3,(1/8),0,(1/8)))