[R-sig-ME] implicit nesting
Douglas Bates
bates at stat.wisc.edu
Wed Jul 7 17:03:38 CEST 2010
On Tue, Jul 6, 2010 at 7:33 PM, array chip <arrayprofile at yahoo.com> wrote:
> Dear Dr. Bates,
> I am learning lmer() from lme4 package. I came across your article "Fitting linear mixed models in R" in R News (vol5, May 2005). I have 2 questions:
> 1. one is about the implicit nesting in the section "Specifying levels" where you gave an example dataset "Pixel" from MEMSS package. You said "If we wish to fit a model with random effects for "side within dog" we must first create a dog/side factor as
> > Pixel$DS <- wirth(Pixel, Dog:Side)[drop=TRUE]
> ".
> I still don't quite understand why we have to create a new factor variable like the above. What is wrong if we simply specify a model like this (it runs and produces results):
> > fm <- lmer(pixel~day + (day|Side) + (day|Dog), Pixel)
Because Side has only two levels, "L" and "R", and you want to define
random effects separately for each side of each dog.
> 2. the 2nd question is about the example you gave in the section "Nested and non-nested grouping factors" where you considered the dataset "star" from mlmRev package. In this example, the model specification is:
> > fm4 <- lmer(math ~ gr + sx + eth + cltype + (yrs | id) + (yrs | sch), star)
When modeling the results of annual test scores like these, "year" and
"grade" are usually confounded or close to being confounded within
each student. For defining per-student random effects we prefer to
use yr because the year should always change from one result to the
next but when a student has been retained the grade doesn't change.
> In this model, you didn't include "yrs" as a fixed effect. The how should we explain the random slope? When "yrs" is included as a fixed effect in the model, we can explain random slope as a random slope around a fixed common slope. But if "yrs" is not included as a fixed effect, does that mean the random slope is around a common fixed slope of 0?
> Actually, I tried to add "yrs" as a fixed effect:
> > fm4 <- lmer(math ~ gr + sx + eth + cltype + yrs + (yrs | id) + (yrs | sch), star)
> But I got an error message "Error in mer_finalize(ans) : Downdated X'X is not positive definite, 13.", why is that?
When means that you have linearly dependent columns in the
fixed-effects model matrix.
> Thank you very much!
>
> John
More information about the R-sig-mixed-models
mailing list