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

J.R. Lockwood lockwood at rand.org
Wed Jul 2 20:07:09 CEST 2003


A couple weeks ago I posted a message about using lme() to fit a model
based on the following: Students are tested in two years, and are
linked to teachers in the second year only.  Thus students are not
nested within teachers in the traditional sense.  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.  Thus 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.  For reference I include at the end of this
message a function "generate.data()" that simulates (balanced) data
according to this model.

I think I figured out a way to fit this model in lme() but I have some
questions about it.  My strategy was essentially to brute-force create
the Z matrix with columns containing indicators of the second year
teacher interleaved with zeros for the first year scores, and then
force the covariance matrix of the random effects to be a constant
times the identity.  Here is the code I am using:


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

lme.u2b<-lme(fixed=Y~time,data=d,random=list(dummy.group=pdIdent(form=fmla)),weights=varIdent(form=~1|time),correlation=corSymm(form = ~1|dummy.group/studid))

I have one set of questions and one observation:

1) The two model fits provide (essentially) the same estimates, and
these estimates seem reasonable.  However, they provide different DF
in the table of fixed effects, reflecting the fact that the nesting
structures specified in the two models are different.  In the first
case, I specify that students are nested within teachers which is not
exactly true.  In the second, I use a dummy grouping variable
"dummy.group" which is identically equal to 1 for all records. 

My major questions are why/how these specifications fit the same
model, whether it is possible for me to fit the model without
specifying names to the list components in the random statement, and
more generally, whether lme() *requires* a nesting structure at all.
I guess what it comes down to is that I am having trouble
understanding how exactly specifying the random statement as a list of
formulas works.

2) intervals() on either of these objects fails with the following
   error message:

Error in structure(exp(as.vector(object)), names = c(paste("sd(", deparse(formula(object)[[2]]),  : 
	names attribute must be the same length as the vector

Any insights would be greatly appreciated.

best regards,

J.R. Lockwood
412-683-2300 x4941
lockwood at rand.org

## Function for generating data
  ## k=number of teachers
  ## n=number of students per teacher

More information about the R-help mailing list