lmer随机效应的置信区间 [英] Confidence interval of random effects with lmer

查看:628
本文介绍了lmer随机效应的置信区间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用lme4包中的lmer来计算方差分量的置信区间.

I am using lmer from lme4 package to calculate confidence interval for variance component .

当我拟合模型时,会显示警告消息:

When I fit the model there is warning messages :

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的决定.

I searched a lot to understand why does the error occur and finally come to a decision that there is difference between error and warning in the R world .

我想计算模型参数的置信区间,并运行显示错误的代码:

I want to compute confidence interval for the model parameters and run the code which shows error :

 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?

Is there another way to obtain CI of random effects with lmer?

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)))

推荐答案

这完全取决于您从置信区间中查找的内容,但是arm包中的函数sim提供了一种获取重复次数的好方法从lmerglmer对象的后部采样以了解固定项和随机项的系数的变化性.

It depends on what you are looking for from the confidence intervals exactly, but the function sim in the arm package provides a great way to obtain repeated samples from the posterior of an lmer or glmer object to get a sense of the variability in the coefficients of both the fixed and random terms.

merTools包中,我们编写了一个包装程序,简化了提取这些值并与之交互的过程:

In the merTools package, we've written a wrapper that simplifies the process of extracting these values and interacting with them:

library(merTools)
randomSims <- REsim(fit, n.sims = 500)
# and to plot it
plotREsim(REsim(fit, n.sims = 500))

merTools中,还有许多其他工具可用于探索这些工具.但是,如果您想要实际得到的模拟,最好使用arm::sim.

There are a number of other tools for exploring these in merTools. If you want the actual resulting simulations though, you're better off using arm::sim.

这篇关于lmer随机效应的置信区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆