[R] NLME Covariates
Douglas Bates
bates at stat.wisc.edu
Mon Jun 30 17:43:25 CEST 2003
"Harold Doran" <hdoran at nasdc.org> writes:
> In HLM, one can specify a covariate at one of the "levels". For
> example, if the data structure are repeated observations nested
> within students nested within schools, school size might be a
> covariate that is used at level 3, but not at the other levels. In
> HLM this is rather easy to do.
>
> However, how can one specify a covariate in R for only one of the
> levels? I have a sample data set with the structure as described
> above. I fit the unconditional model in R as
>
> model1<-lme(math~year, random=~year|schoolid/childid, data=datafile)
>
> Now, if I want to enter "female" as a covariate at level 2 only, how
> might I modify the code to accomplish this?
There is no distinction between level 1 and level 2 variables in the
fixed-effects part of an lme model. Once the data are organized in a
composite table (i.e. one table that includes the value of each
covariate for each observation) one simply writes a linear model
expression for the fixed effects.
You need to incorporate the female indicator into your 'datafile' data
frame. The merge function is a good way to do this (I had forgotten
about the merge function when we spoke about this a few weeks ago).
After that you could fit a model using, say,
model2 <- lme(math ~ year * female, random=~year|schoolid/childid,
data = datafile)
--
Douglas Bates bates at stat.wisc.edu
Statistics Department 608/262-2598
University of Wisconsin - Madison http://www.stat.wisc.edu/~bates/
More information about the R-help
mailing list