Convergence Error for Development Version of Lme4

Convergence error for development version of lme4

tl;dr this looks like a false positive -- I don't see any particularly important differences among the fits with a variety of different optimizers, although it does look as though the outliers are the built-in Nelder-Mead optimizer and nlminb; built-in bobyqa, and bobyqa and Nelder-Mead from the nloptr package, give extremely close answers, and no warnings.

My general advice in these cases would be to try re-fitting with control=glmerControl(optimizer="bobyqa"); we are considering switching to using bobyqa as the default (this question increases the weight of evidence in its favour).

I put the dput output in a separate file:

source("convdat.R")

Run the whole gamut of possible optimizers: built-in N-M and bobyqa; nlminb and L-BFGS-B from base R, via the optimx package; and the nloptr versions of N-M and bobyqa.

library(lme4)
g0.bobyqa <- glmer(resp ~ months.c * similarity * percSem +
(similarity | subj),
family = binomial, data = myData,
control=glmerControl(optimizer="bobyqa"))
g0.NM <- update(g0.bobyqa,control=glmerControl(optimizer="Nelder_Mead"))
library(optimx)
g0.nlminb <- update(g0.bobyqa,control=glmerControl(optimizer="optimx",
optCtrl=list(method="nlminb")))
g0.LBFGSB <- update(g0.bobyqa,control=glmerControl(optimizer="optimx",
optCtrl=list(method="L-BFGS-B")))

library(nloptr)
## from https://github.com/lme4/lme4/issues/98:
defaultControl <- list(algorithm="NLOPT_LN_BOBYQA",xtol_rel=1e-6,maxeval=1e5)
nloptwrap2 <- function(fn,par,lower,upper,control=list(),...) {
for (n in names(defaultControl))
if (is.null(control[[n]])) control[[n]] <- defaultControl[[n]]
res <- nloptr(x0=par,eval_f=fn,lb=lower,ub=upper,opts=control,...)
with(res,list(par=solution,
fval=objective,
feval=iterations,
conv=if (status>0) 0 else status,
message=message))
}
g0.bobyqa2 <- update(g0.bobyqa,control=glmerControl(optimizer=nloptwrap2))
g0.NM2 <- update(g0.bobyqa,control=glmerControl(optimizer=nloptwrap2,
optCtrl=list(algorithm="NLOPT_LN_NELDERMEAD")))

Summarize results. We get warnings from nlminb, L-BFGS-B, and Nelder-Mead (but the size of the max abs gradient is largest from Nelder-Mead)

getpar <- function(x) c(getME(x,c("theta")),fixef(x))
modList <- list(bobyqa=g0.bobyqa,NM=g0.NM,nlminb=g0.nlminb,
bobyqa2=g0.bobyqa2,NM2=g0.NM2,LBFGSB=g0.LBFGSB)
ctab <- sapply(modList,getpar)
library(reshape2)
mtab <- melt(ctab)
library(ggplot2)
theme_set(theme_bw())
ggplot(mtab,aes(x=Var2,y=value,colour=Var2))+
geom_point()+facet_wrap(~Var1,scale="free")

Just the 'good' fits:

ggplot(subset(mtab,Var2 %in% c("NM2","bobyqa","bobyqa2")),
aes(x=Var2,y=value,colour=Var2))+
geom_point()+facet_wrap(~Var1,scale="free")

Coefficient of variation of estimates among optimizers:

summary(cvvec <- apply(ctab,1,function(x) sd(x)/mean(x)))

The highest CV is for months.c, which is still only about 4% ...

The log-likelihoods don't differ very much: NM2 gives the max log-likelihood, and all the 'good' ones are very close (even the 'bad' ones are at most 1% different)

likList <- sapply(modList,logLik)
round(log10(max(likList)-likList),1)
## bobyqa NM nlminb bobyqa2 NM2 LBFGSB
## -8.5 -2.9 -2.0 -11.4 -Inf -5.0

model failed to converge or not in r (lme4)

Because of this warning message, I thought this model failed to converge. However, my advisor said this is unclear because that eigenvalue is really close to 0.

No, the model has converged. I do not get the Model failed to converge with 1 negative eigenvalue message with your data.

It has converged to a singular fit, and this is because the model is overfitted. You have only 3 sites and 3 seasons and you are also fitting random slopes for duration over both grouping variables. Try this instead:

 lmer(effect ~ duration + (1|sites) +(1|season), data = dat1)

However, 3 is really too few levels to get a good estimate of the random effects.

Convergence error on lme4

You can never be sure (this is numerical optimization of a case about which we can't prove a whole lot in the general case), but as a general matter I would say that if you have succeeded in reaching approximately the same putatively "optimal" parameter estimates with more than one different optimizer (e.g. using allFit()) you can stop worrying about convergence failure. How close "approximately" is depends on personal taste and scientific goals. For my typical use cases, estimating parameters within (say) 1%, or conservatively 0.1%, of each other with different optimizers would count as "approximately equal".

lme4 1.1-27.1 error: pwrssUpdate did not converge in (maxit) iterations

Your response variable has a lot of zeros:

Sample Image

I would suggest fitting a model that takes account of this, such as a zero-inflated model. The GLMMadaptive package can fit zero-inflated negative binomial mixed effects models:

## library(GLMMadaptive)
## mixed_model(countvariable ~ waves + var1 + dummycodedvar2 + dummycodedvar3, ## random = ~ 1 | record_id, data = data,
## family = zi.negative.binomial(),
## zi_fixed = ~ var1,
## zi_random = ~ 1 | record_id) %>% summary()

Random effects covariance matrix:
StdDev Corr
(Intercept) 0.8029
zi_(Intercept) 1.0607 -0.7287

Fixed effects:
Estimate Std.Err z-value p-value
(Intercept) 1.4923 0.1892 7.8870 < 1e-04
waves -0.0091 0.0366 -0.2492 0.803222
var1 0.2102 0.0950 2.2130 0.026898
dummycodedvar2 -0.6956 0.1702 -4.0870 < 1e-04
dummycodedvar3 -0.1746 0.1523 -1.1468 0.251451

Zero-part coefficients:
Estimate Std.Err z-value p-value
(Intercept) 1.8726 0.1284 14.5856 < 1e-04
var1 -0.3451 0.1041 -3.3139 0.00091993

log(dispersion) parameter:
Estimate Std.Err
0.4942 0.2859

Integration:
method: adaptive Gauss-Hermite quadrature rule
quadrature points: 11

Optimization:
method: hybrid EM and quasi-Newton
converged: TRUE


Related Topics



Leave a reply



Submit