# Why does this error occur with my linear mixed models?

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.

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 [
lmerModLmerTest]
Formula:
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)             ***
Direction.12hrsIncrease
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
(Intr)
Drctn.12hrI -0.555

• 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 Aug 26, 2020 at 18:22
• @RobertLong I have edited the post with the required information Aug 26, 2020 at 18:57

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.
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.
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.