[R] Trouble setting up correlation structure in lme

Gang Chen gangchen6 at gmail.com
Fri Jan 25 22:15:15 CET 2008


Hi, I'm trying to set up AR(1) as a correlation structure in modeling some
data (attached file data.txt in text format) with lme, but have trouble
getting it to work.

Incent, Correctness, and Oppor are 3 categorical variables, Beta is a
response variable, and Time is an equally-spaced variable with 6 time points
(treated as a categorical variable as well). I'm not so sure about the form
in corAR1 here. Since the correlation is supposed to be along the Time
points, is form=~1 | Subject/Time a correct setup?

library(nlme)
Data <- read.table("data.txt", header=TRUE)
fm <- lme(Beta~Incent*Correctness+Oppor+(Time-1),
    random = ~1|Subj, correlation=corAR1(0.5, form=~1|Subj/Time), Data)

The above lines do work, but my intuition seems pointing to a form like form
= ~time | Subj/Incent/Correctness/Oppor. However

fm <- lme(Beta~Incent*Correctness+Oppor+(Time-1),
   random = ~1|Subj, correlation=corAR1(0.5,
form=~Time|/Incent/Correctness/Oppor), Data)

gives me the following error:

Error in attributes(.Data) <- c(attributes(.Data), attrib) :
  'names' attribute [270] must be the same length as the vector [0]

It is probably due to the fact some combinations in the data are missing,
but I could not figure out how to group them so that the values on the time
variable would be unique within each subject. So how can I do this?

Any help is highly appreciated,
Gang
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: data.txt
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20080125/2e7d148b/attachment.txt 


More information about the R-help mailing list