glmer 错误消息中的随机效应 glm

Random effect glm in glmer error message

这是一个子集数据集,我试图在其中 运行 glm 考虑到某些操作员进行多次测量的随机影响:

data<-data.frame(c("AA","AB","AC","AD","AE","AF","AG","AB","AE","AH","AI","AJ","AK","AL","AM","AD","AN","AO","AP","AQ","AR","AS","AT","AU","AJ","AM","AI","AD","AV","AW","AE","AA","AY","AP","AM","AZ","BA","BB","BC","BD","BE","BF","BG","BH","BI","BJ","BK","BF","BL","AI","AD","BM","BN","BO","AU","AM","AE","AI","AC","BP","BQ","BR","BS","AB","BT","BU","BV","LEH","AD","AZ","BW","BL","BX","BY","BZ","BR","AL","BU","AJ","CA","CB","BO","BU","BO","CC","CD","BU","CE","CF","CG","CH","BO","AX","AJ","CI","AN","CJ","BO","AJ","CK","AY","CL","CM","CL","CN","AV","CO","BP","CP","CK","BP","BF","CQ"))
colnames(data)[1]<-"op"
data$resp<-c(1,NA,1,1,1,0,1,1,1,0,NA,0,1,1,0,NA,0,0,0,1,NA,1,0,0,1,0,NA,NA,0,0,1,0,1,0,1,NA,0,NA,NA,NA,1,0,0,1,0,1,0,1,NA,1,1,1,1,0,1,0,NA,1,1,NA,1,NA,1,0,0,0,1,NA,NA,1,1,1,NA,1,NA,NA,NA,NA,0,1,NA,0,1,0,1,NA,1,0,1,0,0,0,0,1,0,NA,1,0,NA,1,0,1,1,0,NA,1,1,1,0,0,0,1,1)
data$var1<-c(NA,NA,0,1,NA,NA,NA,1,NA,NA,NA,NA,NA,1,0,NA,NA,NA,0,NA,NA,NA,NA,0,1,0,NA,NA,NA,NA,NA,0,1,0,0,NA,NA,NA,NA,NA,NA,NA,0,NA,NA,1,0,1,NA,1,1,NA,NA,NA,1,0,NA,1,0,NA,1,NA,1,0,0,0,1,NA,NA,1,NA,1,NA,NA,NA,NA,NA,NA,NA,NA,NA,0,NA,0,1,NA,1,0,NA,NA,0,0,0,1,NA,NA,1,NA,NA,1,NA,1,0,0,NA,1,NA,NA,NA,NA,0,NA,NA)
data$var2<-c(NA,NA,NA,NA,NA,NA,1,NA,1,NA,NA,NA,1,NA,NA,NA,NA,NA,NA,1,NA,1,NA,NA,NA,NA,NA,NA,NA,0,1,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,0,NA,1,NA,NA,NA,NA,NA,NA,NA,1,1,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,1,NA,NA,NA,NA,NA,NA,NA,NA,1,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,1,1,NA,NA,NA,1,NA)
data$var3<-c(NA,NA,1,NA,NA,0,1,NA,1,0,NA,NA,0,1,0,NA,NA,NA,0,0,NA,0,NA,0,0,0,NA,NA,NA,0,0,0,0,0,1,NA,NA,NA,NA,NA,1,0,NA,1,NA,0,0,1,NA,NA,NA,1,1,NA,0,0,NA,1,1,0,NA,NA,1,NA,0,0,0,NA,NA,0,NA,1,NA,0,NA,NA,NA,NA,NA,NA,NA,0,0,0,1,NA,1,NA,NA,0,0,0,0,0,NA,NA,NA,NA,NA,1,NA,0,1,0,NA,NA,0,0,NA,NA,0,NA,NA)

当我运行第一个glm使用glmer(来自lme4)如下:

summary(glmer(resp~var1+(1|op),data=data,family=binomial,na.action=na.omit))

我只得到这个错误信息

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,  :
   Hessian is numerically singular: parameters are not uniquely determined
Error in diag(vcov(object, use.hessian = use.hessian)) : 
  error in evaluating the argument 'x' in selecting a method for function 'diag': Error in solve.default(h) : 
  Lapack routine dgesv: system is exactly singular: U[3,3] = 0

当我运行第二个变量的第二个glm

summary(glmer(resp~var2+(1|op),data=data,family=binomial,na.action=na.omit))

然后我收到另一条消息:

Error in summary(glmer(resp ~ var2 + (1 | op), data = data, family = binomial,  : 
  error in evaluating the argument 'object' in selecting a method for function 'summary': Error in summary(glmer(resp ~ var2 + (1 | op), data = data, family = binomial,  : 
  pwrssUpdate did not converge in (maxit) iterations

如果我运行它为第三个变量

summary(glmer(resp~var3+(1|op),data=data,family=binomial,na.action=na.omit))

然后它似乎工作正常,但那是真的吗?一定有一些数据分布不适合此分析。任何人有任何想法并可以提出解决方法吗?

我可能已经通过 运行ning

找到了绕过它的方法
summary(lme(resp~var1,random=~1|op,data=data,na.action=na.omit))

这似乎 运行 对于所有 3 个变量都没有问题,但是 glmer 和 lme 之间的 data$var3 结果略有不同,此时我不相信我的结果。 我不确定为什么会出现这些错误,而且我可以在 SO 和其他站点中找到的所有解释对我来说都没有多大意义。数据非常简单,但为什么这不起作用?使用 lme 合适吗? 非常感谢

在第二个案例中,很容易看出回归应该失败(因为预测变量和结果变量相同):

> na.omit(data[c('resp','var2','op')])
    resp var2 op
7      1    1 AG
9      1    1 AE
13     1    1 AK
20     1    1 AQ
22     1    1 AS
30     0    0 AW
31     1    1 AE
42     0    0 BF
44     1    1 BH
52     1    1 BM
53     1    1 BN
74     1    1 BY
83     1    1 BU
107    1    1 CO
108    1    1 BP
112    1    1 BF

在第一个情况下,它们几乎相同,尽管有一些情况(我认为有两个)具有不同的值,但具有聚类项强加的额外结构,错误消息对我来说并不奇怪不一样了。

在第三个的情况下,有一个不同的问题:

> with( na.omit(data[c('resp','var3','op')]), table(resp,var3) )
    var3
resp  0  1
   0 22  0
   1 16 18

这被称为 "complete separation"。当 var3 为 1 时,没有 resp 等于 0 的情况。因此 "true" 为 1 的几率是无穷大。我猜你的系数是 10 或 20(或介于两者之间)。这是逻辑回归的病态结果的标志,因为指数系数(即优势比)非常大。寓意:在开始回归建模之前,您应该学会做更多的表格调查。