Skip to content

Convergence issues with nlme:lme

2 messages · Robert Long, Ben Bolker

#
Dear list

Having tried to fit a mixed effects model with nlme:lme, and found
convergence problems, how do we inspect the fitted model object to find out
what is the problem?

Reproducible example:
= 10))
Error in lme.formula(y ~ x, random = ~1 + x | group, data = data) :
  nlminb problem, convergence error code = 1
  message = iteration limit reached without convergence (10)

Now that we have the model object, how do we interrogate it to find out
what went wrong? I need to do this in code, so I won't have access to the
Error message raised when the model was first fitted (unless there is a
magical way to get at the error (which I haven't yet found)

Thanks !
#
You don't have the model object, since R threw an error.


   If you run

model <- lme(y ~ x, random = ~ 1 + x | group, data = data, control = 
lmeControl(returnObject = TRUE))

   you will get an object returned. However, I don't see anything in the 
returned object that stores warning information.

   In these cases you need to set up some machinery to capture and store 
errors and warnings, et.c. from
https://github.com/lme4/lme4/blob/master/R/error_factory.R

mylme <- lme4:::factory(lme)
model2 <- mylme(y ~ x, random = ~ 1 + x | group, data = data, control = 
lmeControl(returnObject = TRUE))


attr(model2, "factory-warning")
## [1] "nlminb problem, convergence error code = 1\n  message = 
iteration limit reached without convergence (10)"

And now without setting returnObject = TRUE ...

model3 <- mylme(y ~ x, random = ~ 1 + x | group, data = data)

model3
[1] "An error occurred in the factory function"
attr(,"factory-error")
[1] "nlminb problem, convergence error code = 1\n  message = iteration 
limit reached without convergence (10)"
On 10/21/24 11:40, Robert Long wrote: