Skip to content
Prev 7002 / 20628 Next

account for temporal correlation

matteo dossena <matteo.dossena at ...> writes:
set.seed(5)
mydata <- data.frame(var = rnorm(100,20,1),
                      temp = sin(sort(rep(c(1:10),10))),
                      subj = as.factor(rep(c(1:10),5)),
                      time = sort(rep(c(1:10),10)),
                      trt = rep(c("A","B"), 50))
library(nlme)
model <- lme(var~temp*trt,random=~1|subj,mydata)
model1 <- lme(var~temp*trt,random=~1|subj,
                correlation=corAR1(form=~1|subj),mydata)

model1$modelStruct$corStruct

Correlation structure of class corAR1 representing
        Phi 
-0.05565362 

  You shouldn't be nesting time within subject.  'subject' is all the grouping
you need here.

intervals(model1)

 gives (approximate!!) CI for the correlation structure parameter
(-0.27,0.77) in this case

  Of course, in this case we don't expect to find anything interesting
because these are simulated data without any correlation built in.

  These plots are useful.

plot(ACF(model),alpha=0.05)
plot(ACF(model1),alpha=0.05)  ## should be ALMOST identical to the one above
 ## taking correlation into account:
plot(ACF(model1,resType="normalized"),alpha=0.05)