Troubleshooting

Convergence problems and simplifying the random effects structure

It’s common, when variances and covariances are close to zero, that lmer has trouble fitting your model. The solution is to simplify complex models, removing of constraining some random effects.

For example, in an experiment where you have multiple stimuli and different experimental conditions, with many repeated trials, you might end up with data like this:

df %>%
  head()
# A tibble: 6 x 5
  trial condition block subject    RT
  <int>     <int> <int>   <int> <dbl>
1     1         1     1       1  299.
2     2         1     1       1  300.
3     3         1     1       1  300.
4     4         1     1       1  300.
5     5         1     1       1  301.
6     6         1     1       1  301.

Which you could model with lmer like this:

m1 <- lmer(RT ~ block * trial * condition + (block+condition|subject), data=df)
boundary (singular) fit: see ?isSingular

You can list the random effects from the model using the VarCorr function:

VarCorr(m1)
 Groups   Name        Std.Dev.   Corr         
 subject  (Intercept) 1.12152879              
          block       0.00052841  1.000       
          condition   0.00673767 -1.000 -1.000
 Residual             1.00551111              

As VarCorr shows, this model estimates:

  • random intercepts for subject,
  • random slopes for trial and condition, and
  • three covariances between these random effects.

If these covariances are very close to zero though, as is often the case, this can cause convergence issues, especially if insufficient data are available.

If this occurs, you might want to simplify the model. For example, to remove all the covariances between random effects you might rewrite the model this way:

m2 <- lmer(RT ~ block * trial * condition +
  (1|subject) +
  (0+block|subject) +
  (0+condition|subject), data=df)
VarCorr(m2)

To remove only covariances with the intercept:

m3 <- lmer(RT ~ block * trial * condition +
  (1|subject) +
  (0+block+condition|subject), data=df)

VarCorr(m3)

In general, the recommendation is to try and fit a full random effects structure, and simplify it by removing the least theoretically plausible parameters. See:

See this page for lots more examples of more complex mixed models