Skip to content

convergence in GLMM (lme4 package)

3 messages · Martí Casals, Ben Bolker

#
On 12-10-31 02:27 PM, Mart? Casals wrote:
Here's my attempt.
  A reproducible example would have been slightly more convenient --
I'm guessing a bit here.

options(warn=2)
nsim <- 1000  ## BMB: setting this to a parameter
warn<-rep(NA,nsim)
estglmer<-vector('list',nsim)
## BMB: it is marginally more efficient to pre-allocate
## lists (although prob doesn't
##  matter in this much case, glmer() is the slow part)

## don't know why estglmer needs names?

## The model to be fitted (Y, Category, fallswinner & ncombat are
##  variables in data frame dd)
modfun <- function(dat) glmer(Y~Category+fallswinner+(1|id),
       offset=(log(ncombat)),nAGQ=50,family="poisson",data=dat)

for(i in 1:nsim){
     # The data to be used
   ## nAGQ=50 is a little surprising.  Do you really need that much?
     estglmer[[i]]<-withCallingHandlers(
              tryCatch(modfun(alldata[[i]]),
                 error = function(e) {
                      warn[i] <<- paste("ERROR:",e$message)
                       NA
                   }),
                   warning = function(w) {
                        warn[i] <<- w$message
                        invokeRestart("muffleWarning")
                   })
}
4 days later
#
Mart? Casals <mcasals at ...> writes:
ok <- function(x,type= "try-error") class(x)!=type*
options(warn=2)*
fitmodel <- try(lmer(modelformula,data))*
ok(fitmodel)*
I'm glad you got something to work.  I would be willing to work
on the full problem more, but I can't do much without a reproducible
example ...

   Ben Bolker
[snip]