Learn R Programming

afex (version 0.14-2)

allFit: Refit lmer model using multiple optimizers

Description

Attempt to re-fit a [g]lmer model with a range of optimizers. The default is to use all known optimizers for R that satisfy the requirements (do not require explicit gradients, allow box constraints), in three categories; (i) built-in (minqa::bobyqa, lme4::Nelder_Mead), (ii) wrapped via optimx (most of optimx's optimizers that allow box constraints require an explicit gradient function to be specified; the two provided here are really base R functions that can be accessed via optimx, (iii) wrapped via nloptr.

Usage

allFit(m, meth.tab = cbind(optimizer = rep(c("bobyqa", "Nelder_Mead",
  "optimx", "nloptwrap"), c(1, 1, 2, 2)), method = c("", "", "nlminb",
  "L-BFGS-B", "NLOPT_LN_NELDERMEAD", "NLOPT_LN_BOBYQA")), verbose = TRUE,
  maxfun = 1e+05, ...)

Arguments

m
a fitted model with lmer
meth.tab
a matrix (or data.frame) with columns - method the name of a specific optimization method to pass to the optimizer (leave blank for built-in optimizers) - optimizer the optimizer function to use
verbose
print progress messages?
maxfun
number of iterations to allow for the optimization rountine.
...
further arguments passed to update.merMod such as data.

Value

  • a list of fitted merMod objects

Details

Needs packages nloptr and optimx to try out all optimizers. optimx needs to be loaded explicitly using library or require.

See Also

slice, slice2D in the bbmle package

Examples

Run this code
require(optimx)
gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
data = cbpp, family = binomial)
gm_all <- allFit(gm1)
t(sapply(gm_all,fixef)) ## extract fixed effects
sapply(gm_all,logLik) ## log-likelihoods
sapply(gm_all,getME,"theta") ## theta parameters
!sapply(gm_all,inherits,"try-error") ## was fit OK?

Run the code above in your browser using DataLab