converge_it: Converge an lme4 model

View source: R/converge_it.R

converge_itR Documentation

Converge an lme4 model

Description

Convergence is a common problem with mixed models of enough complexity, especially GLMM, and especially those fit by the lme4 package. Assuming it's not a data or specification problem causing the issue, this function will run the model successively until convergence.

Usage

converge_it(model)

## S3 method for class 'merMod'
converge_it(model)

Arguments

model

An lme4 model.

Details

This simple function currently just works for lme4 objects. Its main purpose is to just save the trouble of guessing how long you might need to run something to get to the default convergence. It just continues running update with additional iterations until convergence or an additional stopping point (10 additional runs of update). At that point you can just feed the updated model and continue further if desired, try a different optimizer, a different model, etc. While this function may get you to convergence, you still may have 'singular' or other issues. In addition, you will still see warnings as it iterates toward a converged model.

Value

A hopefully successfully converged lme4 model, or one closer to convergence.

Note

While it is true that GLMMs generally are hard to fit, most convergence warnings with lme4 seem really more about the underlying data, or a problematic model, rather than an issue with estimation. Furthermore, it is often the case that the model with warnings will typically have no meaningful difference in results with those from a different optimizer, but this would need to be checked with some thing like allFit. Also, if you are having a problem with a model fit with lmer, i.e. an LMM as opposed to a GLMM, this is usually a model that is too complex for the underlying data.

See Also

convergence, allFit, isSingular

Examples

## Not run: 
data(Salamanders, package = 'glmmTMB')

library(lme4)
library(mixedup)

# a possibly silly model
glmer_mod = glmer(count ~ spp + mined + DOP + Wtemp + DOY +
  (1 | sample) +
  (1 + DOY + DOP | site),
  data = Salamanders,
  family = poisson
)


converge_it(glmer_mod)

## End(Not run)

m-clark/mixedup documentation built on Oct. 15, 2022, 8:55 a.m.