Day 14 Software Implementation of LMMs

14.1 Announcements

  • Assignment 4 grades will be posted tonight
  • Projects

14.2 Model review

In general, we can write LLMs as

\[\mathbf{y} \vert \boldsymbol{b} \sim N(\mathbf{X}\boldsymbol{\beta} + \mathbf{Z}\boldsymbol{b}, \sigma^2 \mathbf{W}^{-1})\]

\(\boldsymbol{b} \sim N(\boldsymbol{0}, \boldsymbol{\Sigma})\), where\(\boldsymbol{\Sigma}\) must be positive semidefinite and can be expressed also as \(\boldsymbol{\Sigma}_{\theta} = \sigma^2\boldsymbol{\Lambda}_\theta \boldsymbol{\Lambda}_\theta^T\), where \(\sigma\) is the scale factor (same as above) and \(\boldsymbol{\Lambda}_\theta\) is a relative covariance factor that depends on the variance component \(\theta\).

14.3 Computational tricks

14.3.1 Improving computational stability

  • For computational stability and efficiency, reformulate the model such that \(\theta\) appears only in the conditional distribution for the response.
  • For ML, minimize -2 log-likelihood, \(-2 \mathcal{L}(\boldsymbol{\theta}, \boldsymbol{\beta}, \sigma^2\vert\mathbf{y})=\log \frac{\vert\boldsymbol{L}_\theta\vert^2}{\vert\boldsymbol{W}\vert} + n \log(2\pi\sigma^2)+ \frac{r^2(\boldsymbol{\theta})}{\sigma^2} + \frac{\vert\vert \mathbf{R}_X(\boldsymbol{\beta}-\hat{\boldsymbol{\beta}}_\theta) \vert\vert}{\sigma^2}\)

14.3.2 Nonlinear optimizing algorithms

  • Bound Optimization by Quadratic Approximation (bobyqa)
    • Used in lme4 (default)
  • Nelder Mead
  • Template Model Builder (TMB)
    • nlminb() or optim() under the hood
    • GLMMs

Download R script for implementing LMMs