Hi R-users,

I'm attempting to fit a number of mixed models, all with the same structure, across a spatial grid with data points collected at various time points within each grid cell. I'm trying to use a 'for' loop to try the model fit on each grid cell. In some cells lme does not converge, giving me the error:

Error message: In lme.formula(logarea ~ year + summ_d, data = grid2, random = ~year + :
  nlminb problem, convergence error code = 1
  message = iteration limit reached without convergence (9)

When I get the error, the program aborts, and my loop stops.

I'm not too worried about the error, as a generic mixed model structure may not be the best fit for every cell. I expect the optimization to fail in some places. I want to be able to detect when the algorithm has failed to converge automatically, so that I can continue my loop and record the places where the model does fit. I've used the lmeControl method with returnObject=TRUE options to allow me to continue looping, however I want to be able to flag the places where the convergence failed so that I can reject these gridcells and not mistakenly claim that the model fits at these points. Is there a way to do this?

My example code shows the relevant lines of code-- what I'm hoping for is a way to determine that the convergence failed and record this as a boolean value, or something similar.

Thanks,

Sam Nicol


#(set working directory)

#read data
grid2 <- read.csv("grid2.csv", header= TRUE, sep = ",", na.strings="-1")

library(nlme)

#attempt to fit model after setting control options
lmeCtlList <- lmeControl(maxIter=50, msMaxIter=50, tolerance=1e-4, msTol=1e-5, 
nlmStepMax=5, returnObject=TRUE ) #msVerbose=TRUE
global_model3 <-  lme(logarea ~ year+summ_d, data= grid2, random= ~ year + 
summ_d | subject, control=lmeCtlList)
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to