View source: R/HelperFunctions.R
| reml_grad_from_dV | R Documentation |
Computes the derivative of the negative REML objective with respect to a
scalar correlation parameter, given the matrix derivative
\partial \mathbf{V}/\partial \rho.
reml_grad_from_dV(dV, model_fit, glm_weight_function, ...)
dV |
|
model_fit |
A fitted |
glm_weight_function |
The GLM weight function used during model
fitting; see the |
... |
Additional arguments forwarded to |
\mathbf{D} = \mathrm{diag}(d_1,\ldots,d_N) is the diagonal matrix of
observation weights (observation_weights), and
\mathbf{W} = \mathrm{diag}(w_1,\ldots,w_N) is the diagonal matrix of
GLM working weights evaluated at the current fitted values via
glm_weight_function, with the observation-weight contribution
carried separately by \mathbf{D}. For canonical GLM families,
w_i is the usual IRWLS/Fisher-scoring weight on the mean–variance
scale; for example, logistic regression gives
w_i = \mu_i(1-\mu_i). The combined weighting entering the
information matrix is \mathbf{W}\mathbf{D}. In Gaussian identity
models both reduce to scalar multiples of the identity.
\mathbf{V} is the N \times N correlation matrix implied by
VhalfInv, with
\mathbf{V}^{-1} = (\mathbf{V}^{-1/2})^\top \mathbf{V}^{-1/2}.
The penalized observed information at the current iterate is
\mathbf{M} = (\mathbf{X}^*)^\top
\mathbf{V}^{-1}\mathbf{W}\mathbf{D}\,\mathbf{X}^*
+ \mathbf{U}^\top\boldsymbol{\Lambda}\mathbf{U},
where \mathbf{X}^* = \mathbf{X}\mathbf{U} is the constrained design
(N \times P) and the first term is the quadratic approximation to the
penalized log-likelihood Hessian at the current \boldsymbol{\mu}.
For non-Gaussian families this is a local approximation (the IRWLS/Fisher
scoring Hessian), not an exact GLS information matrix.
The constraint projection is
\mathbf{U} = \mathbf{I} -
\mathbf{G}\mathbf{A}(\mathbf{A}^\top\mathbf{G}\mathbf{A})^{-1}
\mathbf{A}^\top
with \mathbf{G} = \mathbf{M}^{-1}.
\mathbf{U} is idempotent (\mathbf{U}^2 = \mathbf{U}) but
not symmetric, so
\mathbf{U}^\top\boldsymbol{\Lambda}\mathbf{U} \neq
\mathbf{U}\boldsymbol{\Lambda}\mathbf{U}^\top.
The U stored in model_fit$U is on the expansion- and
response-standardised scale. The rescaled version used here is
\tilde{\mathbf{U}} =
\mathbf{U} \cdot \mathrm{diag}(1, s_1, \ldots, s_{p-1},
1, s_1, \ldots) / \hat{\sigma}_y,
where s_j are the expansion scales and \hat{\sigma}_y
standardises the response. All quantities below use
\tilde{\mathbf{U}} in place of \mathbf{U}.
The REML objective is constructed by integrating out the fixed effects from the penalized log-likelihood, using a Laplace approximation to the marginal likelihood for non-Gaussian families. This approximation is exact for Gaussian identity models and is the standard extension used in restricted maximum likelihood estimation for GLMMs.
The REML correction term is
-\tfrac{1}{2}\log|\mathbf{M}|, where \mathbf{M} is the
penalized observed information defined above. Differentiating with respect
to \rho (noting only \mathbf{V} depends on \rho)
gives the REML correction gradient
-\frac{1}{2}\mathrm{tr}\!\Bigl(
\mathbf{M}^{-1}
(\mathbf{X}^*)^\top\mathbf{V}^{-1}
\frac{\partial\mathbf{V}}{\partial\rho}
\mathbf{V}^{-1}\mathbf{W}\mathbf{D}\,\mathbf{X}^*
\Bigr).
\frac{\partial(-\ell_R)}{\partial\rho}
= \frac{1}{N}\Biggl[
\underbrace{
\frac{1}{2}\mathrm{tr}\!\Bigl(
\mathbf{V}^{-1}\frac{\partial\mathbf{V}}{\partial\rho}
\Bigr)
}_{\text{(i) log-det of }\mathbf{V}}
\underbrace{
-\frac{1}{2\tilde{\sigma}^2}
\mathbf{r}^\top\frac{\partial\mathbf{V}}{\partial\rho}\mathbf{r}
}_{\text{(ii) residual quadratic form}}
\underbrace{
-\frac{1}{2}\mathrm{tr}\!\Bigl(
\mathbf{M}^{-1}(\mathbf{X}^*)^\top\mathbf{V}^{-1}
\frac{\partial\mathbf{V}}{\partial\rho}
\mathbf{V}^{-1}\mathbf{W}\mathbf{D}\,\mathbf{X}^*
\Bigr)
}_{\text{(iii) REML correction}}
\Biggr],
where the whitened residual is
\mathbf{r} =
\mathrm{diag}\!\left(\sqrt{d_i}/\sqrt{w_i}\right)
\mathbf{V}^{-1/2}(\mathbf{y} - \boldsymbol{\mu}),
and r_i =
[\mathbf{V}^{-1/2}(\mathbf{y}-\boldsymbol{\mu})]_i
\sqrt{d_i}/\sqrt{w_i}.
Term (i) does not involve \mathbf{D} or \mathbf{W}; the
log-determinant of \mathbf{V} depends only on the correlation
structure. For non-Gaussian families terms (ii) and (iii) are evaluated
at the current IRWLS iterate and constitute a local approximation.
A scalar: the gradient of the negative REML objective with respect
to \rho, divided by N.
lgspline, lgspline.fit
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.