[R] Trouble setting up correlation structure in lme

Gang Chen gangchen6 at gmail.com
Fri Jan 25 17:31:02 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). Basically I want to model the
correlation with AR(1) or even ARMA along those 6 time points. First, how is
the order determined among the 6 levels of Time? Alphabetically? If so, I
would have to be very careful about their labels? Or can I specify their
order somehow? Secondly, 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?

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. However

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

gives me the following error:

Error in Initialize.corAR1(X[[2L]], ...) :
  Covariate must have unique values within groups for corAR1 objects

Does it mean that the values on the time variable should be unique within
each subject? How can I define a group variable using more than just subject
since I have multiple combinations of subject and some other variables?

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

More information about the R-help mailing list