[R] Modelling Heteroscedastic Multilevel Models

Douglas Bates bates at stat.wisc.edu
Tue Apr 17 15:59:17 CEST 2007


May I suggest the Exam data from the mlmRev package as an example.

If you wish to have a random effect for Sex by school you could write
the model as

lmer(test.result ~ homework + Sex + (Sex|school))

which gives correlated random effects for the overall achievement in
schools and the differential effect of Sex by school.  Alternatively
you could write

lmer(test.result ~ homework + Sex + (1|school) + (1|Sex:school))

which gives uncorrelated effects for the intercept by school and for
the effect of sex by school.


On 4/17/07, Doran, Harold <HDoran at air.org> wrote:
> I think there are many who can help, but this question is quite vague.
> This assumes we have access to the book you note and can make sense of
> your question w/o sample data.
>
> If you cannot find a sample data set please create a sample data file.
> However, there are so many sample data sets in the mlmRev package and in
> other places I doubt you will need to do this. For example, see the
> egsingle or star data files that are education specific. But, if you for
> some reason cannot do either at least give a good substantive
> description of your data and the problem you are trying to solve.
>
> In the code you have below, you have a random intercept for each school,
> but you remove the intercept in the fixed portion of the call. Also,
> does it make sense to model Sex as random? This is a repeatable factor
> (I hope), how can it be treated as a random draw from a population?
>
> > -----Original Message-----
> > From: r-help-bounces at stat.math.ethz.ch
> > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Rense
> > Nieuwenhuis
> > Sent: Monday, April 16, 2007 4:37 PM
> > To: r-help at stat.math.ethz.ch
> > Subject: [R] Modelling Heteroscedastic Multilevel Models
> >
> > Dear ListeRs,
> >
> > I am trying to fit a heteroscedastic multilevel model using
> > lmer{lme4- package). Take, for instance, the (fictive) model below.
> >
> > lmer(test.result ~ homework + Sex -1 + (1 | School))
> >
> > Suppose that I suspect the error terms in the predicted
> > values to differ between men and women (so, on the first
> > level). In order to model this, I want the 'Sex'-variable to
> > be random on the first level, as described in Snijders &
> > Bosker, page 110.
> >
> > Does anybody know if this is possible and how this can be
> > done using R?
> >
> > Many thanks in advance.
> >
> > Rense Nieuwenhuis
> >
> >
> > PS. Please excuse me for not providing a self-contained
> > example. I couldn't find a data-set in the lme4-package that
> > fitted my question.
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list