Optimization and Numerical Integration

Dimitris Rizopoulos


Estimation Procedure

As described in vignette GLMMadaptive basics (vignette("GLMMadaptive_basics", package = "GLMMadaptive")), the log-likelihood function behind the mixed models fitted by GLMMadaptive contains an intractable integral over the random effects. In addition, the mode of the log-likelihood function cannot be calculated analytically. Therefore, maximum likelihood estimation requires a combination of numerical integration and optimization.

For the numerical optimization two, interlinked by default, algorithms are implemented. An EM algorithm in which the random effects are treated as ‘missing data’, and a quasi-Newton algorithm for direct optimization. The EM algorithm is often a more stable algorithm, especially when the initial values are far from the mode of the log-likelihood; however, because it has a linear convergence rate it can be slow reaching the mode. On the other hand, quasi-Newton algorithms typically have a super-linear convergence rate, but they may have trouble if they are initiated far from the mode. For this reason, optimization procedure in GLMMadaptive starts with the EM algorithm for a fixed number of iterations that are used as a refinement of the initial values before switching to the quasi-Newton algorithm.

The numerical integration over the random effects is done using the adaptive Gauss-Hermite quadrature rule. This also requires an optimization step of finding the modes of the complete-data (= observed response variable and unobserved random effects) log-likelihood with respect to the random effects, for each sample unit. To decrease the computational cost, the optimization procedure in GLMMadaptive does not locate these modes of the random effects in every iteration but every few iterations of the optimization procedure.

The control argument of function mixed_model() has a number of arguments that enable the user to determine how the numerical integration and optimization procedure are performed. The relevant arguments are:

Controlling the Optimization and Integration

We start by simulating some data for a binary longitudinal outcome:

n <- 300 # number of subjects
K <- 4 # number of measurements per subject
t_max <- 15 # maximum follow-up time

# we construct a data frame with the design: 
# everyone has a baseline measurement, and then measurements at K time points
DF <- data.frame(id = rep(seq_len(n), each = K),
                 time = gl(K, 1, n*K, labels = paste0("Time", 1:K)),
                 sex = rep(gl(2, n/2, labels = c("male", "female")), each = K))

# design matrices for the fixed and random effects
X <- model.matrix(~ sex * time, data = DF)
Z <- model.matrix(~ 1, data = DF)

betas <- c(-2.13, 1, rep(c(1.2, -1.2), K-1)) # fixed effects coefficients
D11 <- 1 # variance of random intercepts

# we simulate random effects
b <- cbind(rnorm(n, sd = sqrt(D11)))
# linear predictor
eta_y <- as.vector(X %*% betas + rowSums(Z * b[DF$id, ]))
# we simulate binary longitudinal data
DF$y <- rbinom(n * K, 1, plogis(eta_y))

We fit a mixed effects logistic regression for y assuming random intercepts for the random-effects part, and the main effects of sex and time for the fixed-effects part. In the call to mixed_model(), we are using the default values for the control arguments:

mixed_model(fixed = y ~ sex + time, random = ~ 1 | id, data = DF, family = binomial())

In the following example we do not use any EM iterations, and we specify as optimizer the nlimnb() function. In addition, during each iteration of the outer loop in which the modes of the modes of the conditional distribution of the random effects are relocated, we increase the number of the quasi-Newton iterations by 5:

mixed_model(fixed = y ~ sex + time, random = ~ 1 | id, data = DF, family = binomial(), 
            iter_EM = 0, optimizer = "nlminb", iter_qN_incr = 5)

In the following call, we allow again for EM iterations, but we set the number of the iterations to 1000 giving the option to achieve convergence only during the EM-phase. In addition, we set to update the modes of the conditional distribution of the random effects every 5 iterations, and we also set the number of quadrature points to 21:

mixed_model(fixed = y ~ sex + time, random = ~ 1 | id, data = DF, family = binomial(), 
            iter_EM = 1000, update_GH_every = 5, nAGQ = 21)

To not run the optimization procedure at all, we need to also to set iter_qN_outer to 0, e.g.,

mixed_model(fixed = y ~ sex + time, random = ~ 1 | id, data = DF, family = binomial(), 
            iter_EM = 0, iter_qN_outer = 0)

Advice on optimization and numerical integration control