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