# [R-sig-ME] understanding log-likelihood/model fit

Ken Beath ken at kjbeath.com.au
Thu Aug 21 10:58:43 CEST 2008

```On 20/08/2008, at 11:01 PM, Daniel Ezra Johnson wrote:

> Everyone agrees about what happens here:
>
> Nsubj <- 10
> Ngrp <- 2
> NsubjRep <- 5
> set.seed(123)
> test1s <- data.frame(subject = rep(seq(Nsubj * Ngrp), each =
> NsubjRep),
>       response=500+c(rep(-100,Nsubj * NsubjRep),rep(100,Nsubj *
> NsubjRep))+rnorm(Nsubj * Ngrp * NsubjRep, 0, 10),
>       fixed=(rep(c("A","B"),each=Nsubj * NsubjRep)))
> null1 <- lmer(response~(1|subject),test1s)
> fixed1 <- lmer(response~fixed+(1|subject),test1s)
>
> I still have two questions which I'll try to restate. I should note
> that I have attempted to understand the mathematical details of ML
> mixed effect model fitting and it's a bit beyond me. But I hope that
> someone can provide an answer I can understand.
>
> Question 1: When you have an "outer" fixed effect and a "subject"
> random effect in the same model, specifically why does the model
> (apparently) converge in such a way that the fixed effect is maximized
> and the random effect minimized? (Not so much why should it, as why
> does it? This is the 'fixed1' case.)
>

Because your generated data has only a fixed effect, so the estimated
random effect is zero. This is the same as if you generated data of
the form y=x, it would be expected to fit with an intercept of close
to zero. Someone else supplied an example of adding a random effect
which, of course, will result in a fitted random effect of greater
than zero.

> Question 2: Take the fixed1 model from Question 1 and compare it to
> the null1 model, which has a random subject effect but no fixed
> effect. The predicted values of the two models -- the ones from
> fitted(), which include the ranefs -- are virtually the same. So why
> does fixed1 have a lower deviance, why is it preferred to null1 in a
> likelihood ratio test? (Again, I'm not asking why it's a better model.
> theory of likelihood applied to such cases.)
>

The residual variance is slightly lower for the second model
explaining the better fit. Knowing about the fixed effects helps but
not much.

The fitted are similar, but there is reasonable variation. It will
always be better (in terms of likelihood and as a rule) to fit the
correct model. What is nice is that the model with only a random
effect gives sensible results, so in many situations I don't need to
know why the clusters vary and departures from normality don't seem to
matter much.

Ken

> D
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>

```