0

I was trying to use the nlme package in r to do a multilevel linear model.

I have yield as response variable and rainfall as predictor variable for 60 years for 6 different locations (State). I am trying to see whether rainfall has same level of effect on yield in all locations or different effects. In principle, I am trying to see if slope of yield vs rainfall significantly varies between locations. Therefore rainfall is my random effect. I built my model like this:

  # baseline model which only includes intercept
  mdl1<-gls(yield ~ 1,data = data, method="ML")

  #intercept as random effect
  mdl2<-lme(yield ~ 1,data=data,random = ~1|state,method="ML")  

  # slope as random effect
  mdl3<-lme(yield ~ rain, data = data, random = ~rain|state,method="ML")

  ##compare the three model
  anova(mdl1,mdl2,mdl3)
  #this shows me when I add slope as random effect, my model shows better fit compared to baseline model (mdl1)

this is all working fine. The problem starts when I do the same analysis using an another predictor variable (a count data).

 # baseline model which only includes intercept: Works fine
 mdl4<-gls(yield ~ 1,data = data, method="ML")

 #intercept as random effect - works fine
mdl5<-lme(yield ~ 1,data=data,random = ~1|state,method="ML")  

 # include different predictor (break) this time instead of rain
 mdl6<-lme(yield ~ break, data = data, random = ~break|state,method="ML")

when i run the mdl 6, this gives me the error

 Error in lme.formula(res_yld ~ brk, data = data, random = ~brk | state,  : 
 nlminb problem, convergence error code = 1
 message = iteration limit reached without convergence (10)

I have absolutely no clue why is this happening. Everything worked fine for my first predictor but this does not work on another predictor. What am I doing wrong here? I tried reading about this online but the posts are not very clear to me. I would really appreciate of anyone could me out on this. Thanks

  • 2
    in addition to the answer below I would suggest (1) plotting your data to get a visual sense of whether there's something odd about this response value (e.g. outlier points or groups, strong nonlinearities, etc.); (2) possibly trying `lme4::lmer(yield ~ break+(break|state), data = data, REML=FALSE)`; (3) posting a reproducible example if you want more help. – Ben Bolker Jun 05 '14 at 14:06

1 Answers1

1

From the error message, you can see that the maximum number of iterations is reached before the algorithm has converged. From the documentation, it seems you can increase it with something like:

lmeControl(msMaxIter = 50)

But beware that slow convergence can also point to an ill-posed problem. So check that you indeed can estimate what you're trying to estimate from your data.

Anders Ellern Bilgrau
  • 9,928
  • 1
  • 30
  • 37