glmer
deviance functionslibrary("lme4")
parsedForm <- glFormula(cbind(incidence, size - incidence) ~ period + (1 | herd), family = binomial, data = cbpp)
glmer
models are usually fitted in two steps. The first step
involves no integration (nAGQ = 0
), and the second involves
integration by either Laplace (nAGQ = 1
) or adaptive Gaussian
quadrature (nAGQ > 1
).
(devfun0 <- do.call(mkGlmerDevfun, parsedForm))
(devfun1 <- updateGlmerDevfun(devfun0, parsedForm$reTrms))
as.list(body(devfun1)[c(3, 4, 8, 9)])
Note that there are several objects being used that do not appear to
be created anywhere (e.g. lp0
). Don't worry, they are actually in the
environment of devfun0
, which we can list using the following
command.
ls(rho <- environment(devfun0))
Therefore, all of these objects are available to devfun0
.
We will now step through each line, explaining what it does. The first line,
body(devfun0)[[2]]
updates the conditional mean of the response variable at the value of
the linear predictor, lp0
. Mathematically, the linear predictor is,
$$ \mathbf\eta = \mathbf o + \mathbf X\mathbf\beta + \mathbf Z
\mathbf\Lambda_\theta \mathbf u $$
The conditional mean is then,
$$ \mathbf\mu = \text{link}(\mathbf\eta) $$
Note that the condition mean depends on the covariance parameters
$\mathbf\theta$. Therefore, this update of the conditional mean is
based on the old value of $\mathbf\theta$. The new value of
$\mathbf\theta$ is updated on the next line:
body(devfun0)[[3]]
Next the penalized weighted residual sum of squares is calculated with this new value of $\mathbf\theta$:
body(devfun0)[[4]]
Finally the weights are updated (for safety?)
body(devfun0)[[5]]
ls(rho <- environment(devfun1))
rho$baseOffset
body(devfun1)[[2]]
body(devfun1)[[3]]
body(devfun1)[[4]]
body(devfun1)[[5]]
body(devfun1)[[6]]
body(devfun1)[[7]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.