Gary Dong <pdxgary163 <at> gmail.com> writes:
> I'm estimating a two-level regresion model but having difficuly in
finding
> a good R syntax example.
>
> Let me use an example to explain what I'm doing. The dependent variable
is
> math score (mathscore). Predictors are at two levels. At the student level,
> they are household income (hinc) and IQ (IQ). At the school level, there is
> a dummy variable indicating if the school is a private school (prvsch). I
> also have school IDs (id) that can be used as the subject.
>
> I'm wondering what the syntax would be in R. Any advice is appreciated.
When using lme4 you don't need to explicitly state which fixed-effect
predictors are at which level; the simplest model would use
mathscore ~ hinc + IQ + prvsch + (1|id)
You might want to consider whether the effects of household income
and IQ vary by school or not:
mathscore ~ hinc + IQ + prvsch + (hinc+IQ|id)
(the intercept is implicit in all cases, this would be the same
as using (1+hinc+IQ|id))
The full 3x3 covariance matrix is estimated in this case; if
you want to force independent variation of intercept, hinc, IQ
within schools, use
mathscore ~ hinc + IQ + prvsch + (1|id) + (0+hinc|id) + (0+IQ|id)
Further questions on mixed models in R should probably go to
r-sig-mixed-models at r-project.org