majom
majom

Reputation: 8021

Alternative optimization algorithms for lmer

The function lmer in the lme4 package uses by default bobyqa from the minqa package as optimization algorithm.

According to the following post https://stat.ethz.ch/pipermail/r-sig-mixed-models/2013q1/020075.html, it is possible to use also the other optimization algorirthms in the minqa package

How can one use uobyqa or newuoa as optimization algorithm for lmer?

library(lme4)
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy, control=lmerControl(optimizer="bobyqa"))

Upvotes: 2

Views: 6042

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226162

You can't use newuoa nor uobyqa because neither allows for constraints on the parameters. From ?lmerControl (emphasis added)

Any minimizing function that allows box constraints can be used provided that it

(1) takes input parameters ‘fn’ (function to be optimized), ‘par’ (starting parameter values), ‘lower’ (lower bounds) and ‘control’ (control parameters, passed through from the ‘control’ argument) and

(2) returns a list with (at least) elements ‘par’ (best-fit parameters), ‘fval’ (best-fit function value), ‘conv’ (convergence code, equal to zero for successful convergence) and (optionally) ‘message’ (informational message, or explanation of convergence failure).

The b at the beginning of "bobyqa" stands for "bound" (as in constrained), I assume the u in the other algorithms similarly stands for "unconstrained". You can check out this file for some machinery to (re)fit the same model with a bunch of different optimizers:

allFit <- system.file("utils", "allFit.R", package="lme4")
file.show(allFit)

The list of all optimizers I currently know about that allow box constraints and don't require an explicit gradient function to be specified (required for most of the bound-constrained optimizers in the optimx package), as shown in the file above, is

  • BOBYQA (minqa and nloptr package implementations)
  • Nelder-Mead (lme4, nloptr, and dfoptim package implementations)
  • nlminb from base R (from the Bell Labs PORT library)
  • L-BFGS-B from base R, via optimx (Broyden-Fletcher-Goldfarb-Shanno, via Nash)

In addition to these, which are built in to allFit.R, you can use the COBYLA or subplex optimizers from nloptr: see ?nloptwrap. There's another implementation of subplex in the subplex package: there may be a few others I've missed.

Upvotes: 6

Related Questions