Skip to content
Prev 1295 / 20628 Next

understanding log-likelihood/model fit

On Thu, Aug 21, 2008 at 7:35 AM, Daniel Ezra Johnson
<danielezrajohnson at gmail.com> wrote:
Yes, in the sense that the residual sum of squares is what you would
obtain from a fixed-effects fit where the model matrix is the [X,Z]
where X is the model matrix for the fixed-effects parameters and Z is
the model matrix for the random effects.  The parameter estimates for
this model may not be well defined because the model could be
overparameterized.  However, the residual sum of squares for this
model is well-defined, as are the predictions and the residuals.

You could produce a similar plot for an lmer model fit.  Consider the
Dyestuff data in current versions of the lme4 package. The REML
criterion is similar to the maximum likelihood but it involves another
term so let's just consider the deviance and not the REML deviance.
0:     327.33176: 0.730297
  1:     327.33082: 0.772944
  2:     327.32706: 0.753271
  3:     327.32706: 0.752556
  4:     327.32706: 0.752581
Linear mixed model fit by maximum likelihood
Formula: Yield ~ 1 + (1 | Batch)
   Data: Dyestuff
   AIC   BIC logLik deviance REMLdev
 333.3 337.5 -163.7    327.3   319.7
Random effects:
 Groups   Name        Variance Std.Dev.
 Batch    (Intercept) 1388.1   37.258
 Residual             2451.3   49.511
Number of obs: 30, groups: Batch, 6

Fixed effects:
            Estimate Std. Error t value
(Intercept)  1527.50      17.69   86.33

The verbose output gives the profiled deviance at each iteration as a
function of a single parameter, which is the ratio of the standard
deviation of the random effects to the residual standard deviation.
[1] 0.7525196

This parameter is stored in the ST slot.  The slot is a list with
elements corresponding to the random effects terms in the model.  In
this model there is only one random effects term, (1|Batch).  In
general the elements of the list are square matrices where the number
of rows and columns corresponds to the number of random effects from
that term for each level of the grouping factor.  In this case there
is only one random effect per level of the factor.
[[1]]
            (Intercept)
(Intercept)   0.7525135

The deviance slot contains the deviance itself and several of its components.
ML         REML         ldL2        ldRX2      sigmaML    sigmaREML
  327.327060   319.725920     8.059354     2.057972    49.510754    50.357153
       pwrss         disc         usqr         wrss
73539.442307 62669.199627 10870.242680 62669.199627

For a linear mixed model, the discrepancy (disc) at the current
parameter values is equal to the weighted residual sum of squares
(wrss).  The random effects, b, are linearly transformed to u, for
which the unconditional distribution is a "spherical"
Gaussian distribution.  (i.e. the variance-covariance matrix is
\sigma^2 times the q by q identity matrix, where \sigma^2 is the same
scalar variance as in the definition of the conditional distribution
of Y|B).  The penalty on the size of the random effects is therefore
the squared length of u (usqr).  The penalized, weighted residual sum
of squares is the sum of wrss and usqr.  The conditional estimate of
\sigma^2 is pwrss/n and sigmaML is its square root.
[1] TRUE
n
30
[1] TRUE


The log-determinant of the conditional variance-covariance of the
random effects, given the data (i.e. B|Y) is, up to the scale factor
of \sigma, ldL2.  The profiled deviance is calculated as shown in
slide 132 of http://www.stat.wisc.edu/~bates/PotsdamGLMM/LMMD.pdf

The actual code in the C function lmm_update_fixef_u in lme4/src/lmer.c is

	d[ML_POS] = d[ldL2_POS] +
	    dn * (1 + log(d[pwrss_POS]) + log(2 * PI / dn));

or, in R,
[1] 327.3271
[1] TRUE

Next I was going to show how to change the value of the ST parameter
and update the deviance slot but in the process I discovered that one
of the C functions (the aforementioned lmm_update_fixef_u) cannot be
called from R.  After changing that and making a new release I can
show how to create a similar figure in the new formulation.