[R] Fitting particular repeated measures model with lme()

J.R. Lockwood lockwood at rand.org
Thu Jun 19 21:58:38 CEST 2003


Hello,

I have a simulated data structure in which students are nested within
teachers, and with each student are associated two test scores.  There
are 20 classrooms and 25 students per classroom, for a total of 500
students and two scores per student.  Here are the first 10 lines of
my dataframe "d":

   studid tchid          Y time
1       1     1 -1.0833222    0
2       1     1 -0.7656281    1
3       2     1 -1.0198641    0
4       2     1  0.7808148    1
5       3     1 -1.1381721    0
6       3     1 -0.4395021    1
7       4     1 -2.0944685    0
8       4     1 -1.8746840    1
9       5     1 -0.7784412    0
10      5     1  1.9952170    1
...

I am trying to use lme() to fit a relatively basic repeated measures
model where there are random teacher intercepts, and an unstructured
residual covariance matrix within students.  The following call to
lme() seems to fit the model:

lme.t5<-lme(fixed=Y~time,data=d,random=~1|tchid,weights=varIdent(form=~1|time),\
correlation=corSymm(form = ~1|tchid/studid))

Now, I would like to try to alter this model to one in which the
"teacher effect" applies to only one year.  One can think of the first
score on the student as a score from a prior year (for which I have no
teacher links), and the second score is from the current year and is
linked to the teacher.  The model for student j in class i is:

Y_{ij0} = a_0 + e_{ij0}
Y_{ij1} = a_1 + b_i + e_{ij1}

with Var(b_i) the teacher variance component and Cov(e_{ij0},e_{ij1})
unstructured.  That is, if the data are organized by student, the "Z"
matrix in the usual linear mixed model notation has every other row
equal to a row of zeros.

I am wondering whether there is some way to fit this model using
lme().  Thanks in advance for your help and patience.

best regards,

J.R. Lockwood
412-683-2300 x4941
lockwood at rand.org
http://www.rand.org/methodology/stat/members/lockwood/




More information about the R-help mailing list