TL;DR: lme4
optimization appears to be linear in the number of model parameters by default, and is way slower than an equivalent glm
model with dummy variables for groups. Is there anything I can do to speed it up?
I'm trying to fit a fairly large hierarchical logit model (~50k rows, 100 columns, 50 groups). Fitting a normal logit model to the data (with dummy variables for group) works fine, but the hierarchical model appears to be getting stuck: the first optimization phase completes fine, but the second goes through a lot of iterations without anything changing and without stopping.
EDIT: I suspect the problem is mainly that I have so many parameters, because when I try to set maxfn
to a lower value it gives a warning:
Warning message:
In commonArgs(par, fn, control, environment()) :
maxfun < 10 * length(par)^2 is not recommended.
However, the parameter estimates aren't changing at all over the course of the optimization, so I'm still confused about what to do. When I tried to set maxfn
in the optimizer controls (despite the warning), it seemed to hang after finishing the optimization.
Here's some code that reproduces the problem for random data:
library(lme4)
set.seed(1)
SIZE <- 50000
NGRP <- 50
NCOL <- 100
test.case <- data.frame(i=1:SIZE)
test.case[["grouping"]] <- sample(NGRP, size=SIZE, replace=TRUE, prob=1/(1:NGRP))
test.case[["y"]] <- sample(c(0, 1), size=SIZE, replace=TRUE, prob=c(0.05, 0.95))
test.formula = y ~ (1 | grouping)
for (i in 1:NCOL) {
colname <- paste("col", i, sep="")
test.case[[colname]] <- runif(SIZE)
test.formula <- update.formula(test.formula, as.formula(paste(". ~ . +", colname)))
}
print(test.formula)
test.model <- glmer(test.formula, data=test.case, family='binomial', verbose=TRUE)
This outputs:
start par. = 1 fn = 19900.78
At return
eval: 15 fn: 19769.402 par: 0.00000
(NM) 20: f = 19769.4 at 0 <other numbers>
(NM) 40: f = 19769.4 at 0 <other numbers>
I tried setting ncol
to other values, and it appears that the number of iterations done is (approximately) 40 per column. Obviously, this becomes a huge pain as I add more columns. Are there tweaks I can make to the optimization algorithm that will reduce the dependence on the number of columns?
glmer
is quite slow, especially for models that have a complex random effects structure (e.g., many random slopes, crossed random effects, etc.). My first suggestion would be to try again with a simplified random effects structure. However, if you're experiencing this problem with a random intercepts model only, your problem may simply be the number of cases, in which case you'll need to try some tools specialized for big data. $\endgroup$