[R-sig-ME] log Likelihood depends on contrasts?

Douglas Bates bates at stat.wisc.edu
Thu May 10 21:24:06 CEST 2007


On 5/10/07, Martin Henry H. Stevens <HStevens at muohio.edu> wrote:
> Hi folks,
> I didn't realize log likelihood of a model depended on the particular
> specification of contrasts.
>
> Example
>
>  > str(cake)
> 'data.frame':   270 obs. of  5 variables:
> $ replicate  : Factor w/ 15 levels "1","2","3","4",..: 1 1 1 1 1 1 1
> 1 1 1 ...
> $ batch      : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 2 2 2 2 ...
> $ recipe     : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 2 2 2 2 ...
> $ temperature: Ord.factor w/ 6 levels "175"<"185"<"195"<..: 1 2 3 4 5
> 6 1 2 3 4 ...
> $ angle      : int  42 46 47 39 53 42 39 46 51 49 ...
>  > options(contrasts=c("contr.treatment", "contr.poly"))
>  > mod.t <- lmer(angle ~ recipe + (1|batch), data=cake)
>  > options(contrasts=c("contr.sum", "contr.poly"))
>  > mod.s <- lmer(angle ~ recipe + (1|batch), data=cake)
>  > logLik(mod.t)
> 'log Lik.' -947.82 (df=4)
>  > logLik(mod.s)
> 'log Lik.' -948.92 (df=4)


What you are seeing is the log-restricted-likelihood which does depend
upon that parameterization used for the fixed effects, hence on the
contrasts used for a factor.  If you were to fit both models with
method = "ML" then you would get the same value of the log-likelihood
as shown in the enclosed.

The REML criterion does not always behave like a likelihood.  In
particular there is a term in the REML criterion that depends on the
form of the model matrix for the fixed effects.

(By the way, the model fit in your example doesn't make sense.  It
appears that batch and recipe are the same factor and should not be
included as a fixed effect and as a random effect.)
-------------- next part --------------
> getOption("contrasts")
[1] "contr.treatment"  "contr.poly"
> logLik(fm1 <- lmer(angle ~ recipe + temp + (1|recipe:replicate), cake, method = "ML"))
'log Lik.' -848.0789 (df=5)
> options(contrasts = c("contr.sum", "contr.poly"))
> logLik(fm2 <- lmer(angle ~ recipe + temp + (1|recipe:replicate), cake, method = "ML"))
'log Lik.' -848.0789 (df=5)


More information about the R-sig-mixed-models mailing list