I am attempting to run linear mixed effects models using the function lmer() in order to analyse the effect of the direction of change (single categorical fixed effect) in weather parameters over a fixed period of time (e.g. temperature) on the duration of different insect behaviours. My current model contains a single random effect - treatment (pertaining to conditions the insects were kept in during rearing in the lab). When I attempt to use the anova() function in order to determine the significance of the fixed effect (by comparing a model with and without it) I get the following error:

Warning message:
In optwrap(optimizer, devfun, x@theta, lower = x@lower, calc.derivs = TRUE,  :
  convergence code 3 from bobyqa: bobyqa -- a trust region step failed to reduce q

Would anyone be able to explain to me why this error occurs, how I would be able to fix it, and whether or not the p-value generated is only relevant once the error is fixed.

Added information:

The two models I am comparing take the following forms:

model.7<-lmer(winsorized.Tot.time.fence.secs~Direction.12hrs + (1|Sex.ratio.line.male), data = charlotte.agg.2)
model.8<-lmer(winsorized.Tot.time.fence.secs~(1|Sex.ratio.line.male), data = charlotte.agg.2)

Here is also the summary output of the first model:

Linear mixed model fit by REML. t-tests use Satterthwaite's method [
winsorized.Tot.time.fence.secs ~ Direction.12hrs + (1 | Sex.ratio.line.male)
   Data: charlotte.agg.2

REML criterion at convergence: 3425.4

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-2.00084 -0.74868 -0.09043  0.68238  2.27442 

Random effects:
 Groups              Name        Variance Std.Dev.
 Sex.ratio.line.male (Intercept)   820     28.64  
 Residual                        25017    158.17  
Number of obs: 265, groups:  Sex.ratio.line.male, 11

Fixed effects:
                        Estimate Std. Error     df t value Pr(>|t|)
(Intercept)               297.79      15.63  20.44   19.06 1.72e-14
Direction.12hrsIncrease    10.60      19.64 257.28    0.54     0.59
(Intercept)             ***
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
Drctn.12hrI -0.555
  • $\begingroup$ I think we will need more information. Can you share the output of str(mydata) along with the model formula you are using, and the output of summary(mymodel) please $\endgroup$ Aug 26, 2020 at 18:22
  • $\begingroup$ @RobertLong I have edited the post with the required information $\endgroup$ Aug 26, 2020 at 18:57

1 Answer 1


The error happens when running anova() because you fitted the models using restricted maximum likelihood and you can only do a likelihood ratio test of two models when they are fitted with maximum likelihood. The models are therefore refitted with ML prior to testing and that is where the convergence warning happens.

Sometimes a model doesn't converge because random effects do not behave nicely. I am being deliberately vague because it's not possible to be specific.

The approach I would recommend here, since you only have 11 levels of the grouping factor is to fit a model with this factor as a fixed effect using lm and compare the output for your main exposure in both models.

However I do wonder why you are using a likelihood ratio test here. The t tests reported in the Fixed Effects section of the summary output are tests of the null hypothesis that the fixed effects coefficients are zero. You say that you want to "determine the significance of the fixed effect", well, that's what the t test does. I don't see a need to do a likelihood ratio test.

Try not to be too concerned with p values. I would interpret the model output by saying that you have an outcome which is almost constant with respect to the Direction.12hrsIncrease (assuming you have checked for a nonlinear assocation), and while you have repeated measures within Sex.ratio.line.male there is almost no variation attributable to it, that is there is very litte correlation within levels of it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.