[R-sig-ME] Convergence issues with nlme:lme

Ben Bolker bbo|ker @end|ng |rom gm@||@com
Mon Oct 21 17:50:57 CEST 2024


    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:
> 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:
> 
>> set.seed(3)
>> data <- data.frame(y = rnorm(100), x = rnorm(100), group = rep(1:10, each
> = 10))
>>
>> model <- lme(y ~ x, random = ~ 1 + x | group, data = data)
> 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 !
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-mixed-models using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models

-- 
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
* E-mail is sent at my convenience; I don't expect replies outside of 
working hours.



More information about the R-sig-mixed-models mailing list