[R] [R-sig-ME] account for temporal correlation
bbolker at gmail.com
Sat Nov 19 00:06:50 CET 2011
[cc'ing back to r-help]
On Fri, Nov 18, 2011 at 4:39 PM, matteo dossena
<matteo.dossena at gmail.com> wrote:
> Thanks a lot,
> just to make sure i got it right,
> if (using the real dataset) from the LogLikelihood ratio test model1 isn't "better" than model,
> means that temporal auto correlation isn't seriously affecting the model?
yes. (or use AIC etc.)
> and, I shouldn't be nesting time within subject because is implicit
> that observation from the same subject are the repeated measures?
> The need of nesting would for example be:
> an experiment also having spatial correlation, to say, if subjects are are also grouped by their geographical position,
> should i in this case be nesting location within subject?
If subjects were in spatial blocks then you would nest subject
within location (~1|location/subject).
Note (from ?corAR1) that you can also use an explicit time covariate,
(~time|location/subject) -- otherwise
the assumption is that observations within subject are ordered by time.
> Il giorno 18 Nov 2011, alle ore 18:26, Ben Bolker ha scritto:
>> matteo dossena <matteo.dossena at ...> writes:
>>> Dear list,
>>> I have a data frame like this:
>> 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))
>>> I need to model the response of var as a function of temp*trt
>>> and to do so I'm using the following model:
>> model <- lme(var~temp*trt,random=~1|subj,mydata)
>>> however, since i have repeated measurement of the same subject,
>>> i.e. I measured var in subj1 at time1,2,3..
>>> I must consider the non independence of the residuals.
>>> moreover, temp is also a function of time, but i'm not sure how
>>> to include this in my model.
>>> I'm following the approach in Zuur et al 2009, so I checked for
>>> temporal auto-correlation using the
>>> function afc()
>>> In fact the residuals follow the temporal patter of temperature with time.
>>> However, here I'm not interested in the temporal dependence of temperature
>>> and consequently the effect of
>>> this on var.
>>> Instead what i need to do is to account for the
>>> correlation between consecutive measures (made on the same
>>> subject) in the error term of the model.
>>> here is my attempt to do so:
>> model1 <- lme(var~temp*trt,random=~1|subj,
>> Correlation structure of class corAR1 representing
>> You shouldn't be nesting time within subject. 'subject' is all the grouping
>> you need here.
>> 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(model1),alpha=0.05) ## should be ALMOST identical to the one above
>> ## taking correlation into account:
>> R-sig-mixed-models at r-project.org mailing list
More information about the R-help