allFit: Refit 'lmer' model using multiple optimizers

Description Usage Arguments Details Value Author(s) See Also Examples

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

1
2
3
4
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.

Details

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

Value

a list of fitted merMod objects

Author(s)

Ben Bolker

See Also

slice, slice2D in the bbmle package

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
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?

## End(Not run)

Example output

Loading required package: lme4
Loading required package: Matrix
************
Welcome to afex. For support visit: http://afex.singmann.science/
- Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()
- Methods for calculating p-values with mixed(): 'KR', 'S', 'LRT', and 'PB'
- 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests
- NEWS: library('emmeans') now needs to be called explicitly!
- Get and set global package options with: afex_options()
- Set orthogonal sum-to-zero contrasts globally: set_sum_contrasts()
- For example analyses see: browseVignettes("afex")
************

Attaching package: 'afex'

The following object is masked from 'package:lme4':

    lmer

Loading required package: optimx
Loading required namespace: dfoptim
bobyqa : [OK]
Nelder_Mead : [OK]
nlminbwrap : [OK]
nmkbw : [OK]
optimx.L-BFGS-B : [OK]
nloptwrap.NLOPT_LN_NELDERMEAD : [OK]
nloptwrap.NLOPT_LN_BOBYQA : [OK]
sh: 1: cannot create /dev/null: Permission denied
                              (Intercept)    period2   period3   period4
bobyqa                          -1.398332 -0.9919238 -1.128214 -1.579750
Nelder_Mead                     -1.398338 -0.9919243 -1.128198 -1.579734
nlminbwrap                      -1.398331 -0.9919262 -1.128215 -1.579755
nmkbw                           -1.398206 -0.9918131 -1.128368 -1.579903
optimx.L-BFGS-B                 -1.398335 -0.9919176 -1.128212 -1.579757
nloptwrap.NLOPT_LN_NELDERMEAD   -1.398446 -0.9918004 -1.128047 -1.579614
nloptwrap.NLOPT_LN_BOBYQA       -1.398446 -0.9918004 -1.128047 -1.579614
                       bobyqa                   Nelder_Mead 
                    -92.02657                     -92.02657 
                   nlminbwrap                         nmkbw 
                    -92.02657                     -92.02657 
              optimx.L-BFGS-B nloptwrap.NLOPT_LN_NELDERMEAD 
                    -92.02657                     -92.02657 
    nloptwrap.NLOPT_LN_BOBYQA 
                    -92.02657 
                       bobyqa.herd.(Intercept) 
                                     0.6420643 
                  Nelder_Mead.herd.(Intercept) 
                                     0.6420639 
                   nlminbwrap.herd.(Intercept) 
                                     0.6420616 
                        nmkbw.herd.(Intercept) 
                                     0.6420666 
              optimx.L-BFGS-B.herd.(Intercept) 
                                     0.6420665 
nloptwrap.NLOPT_LN_NELDERMEAD.herd.(Intercept) 
                                     0.6420344 
    nloptwrap.NLOPT_LN_BOBYQA.herd.(Intercept) 
                                     0.6420344 
                       bobyqa                   Nelder_Mead 
                         TRUE                          TRUE 
                   nlminbwrap                         nmkbw 
                         TRUE                          TRUE 
              optimx.L-BFGS-B nloptwrap.NLOPT_LN_NELDERMEAD 
                         TRUE                          TRUE 
    nloptwrap.NLOPT_LN_BOBYQA 
                         TRUE 

afex documentation built on May 2, 2019, 6:08 p.m.