# [R-sig-ME] GLMER Syntax Question

Douglas Bates bates at stat.wisc.edu
Thu Sep 29 18:40:29 CEST 2011

```On Thu, Sep 29, 2011 at 11:34 AM, Ben Bolker <bbolker at gmail.com> wrote:
> Ubuntu Diego <ubuntu.diego at ...> writes:
>
>>
>> I was wondering is someone can explain me the differences
>> between these (random slopes and intercept) models
>>
>>  model1 <- glmer(output~A+B+C+(A+B+C | F) )
>>
>>  model2 <- glmer(output~A+B+C+(A | F)+(B | F)+(C | F)
>>
>
>  Here's an experimental way to see what the differences are.
>
> Make up some data with the appropriate variables/structure:
>
> d <- expand.grid(A=factor(1:3),B=factor(1:3),C=factor(1:3),
>                 rep=1:10,F=factor(1:5))
> d\$y <- runif(nrow(d))
>
> Fit different model specifications (use lme4a so we
> matrix):
>
> library(lme4a)
> m1 <- lmer(y~A+B+C+(A+B+C|F),data=d)
> m2 <- lmer(y~A+B+C+(A|F)+(B|F)+(C|F),data=d)
> m3 <- lmer(y~A+B+C+(A|F)+(B-1|F)+(C-1|F),data=d)
>
> Using "image(m2 at re@Lambda)" (trick extracted from
> Doug Bates's book draft online):
>
> image(m1 at re@Lambda)

The preferred version is now

getME(m1, "Lambda")

Martin suggested that because I keep changing the internal
representation there should be an accessor function that doesn't
depend on the representation and he created such a function.
> The lower triangle of a 35x35 block-diagonal matrix.  For each group
> we have a lower-triangular 7x7 matrix which represents the
> random-effects values within that group.  That is, for each group we
> have a non-zero covariance among the 7 (intercept, A2, A3, B2, B3, C2,
> C3) main effect terms we are allowing to vary across groups.
>
> image(m2 at re@Lambda)
>
> Now we have a 45x45 matrix with 3 separate 3x3 blocks for each group.
> This is a bit problematic because we are estimating the intercept term
> *separately* for each random factor specification, so the model is
> overfitted.  As you can see from the picture, the last 5 3x3 blocks in
> the matrix are coming out as zero (gray) -- I assume these are
> representing those aliased intercept terms.
>
> image(m3 at re@Lambda)
>
> We might think that using "-1" in the model formula to suppress the
> intercept terms would help, but it doesn't really work in this case
> (it does nicely for making the intercept and slope of a regression
> model independent, as shown in the example for lmer in the
> documentation). It just reparameterizes the 3x3 blocks instead of
> reducing the structure to what we might prefer, which would be a
> singleton (the intercept term) followed by 3 2x2 blocks (for {A2,A3},
> {B2,B3}, {C2,C3}) [although it wouldn't be clear that this is what we
> want either ...]
>
> Hope that helps.
>
> You could also play around with parameterizing the model in terms
> of interaction groups (i.e. (1|A:F) instead of (A|F), which is
> a slightly restricted form [compound symmetry with a non-negative
> correlation] of the same model).
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>

```