Many thanks for the suggestion. It seems that gls does not like that either:

>/  (fm<- gls(res ~ 1+reg1+reg2+reg3, correlation=corARMA(c(0.02, 0.03), form=~time|condition, p=1,q=1), data=Dat))
/
Error in model.frame.default(formula = ~time + condition + res + reg1 +  :
   variable lengths differ (found for 'condition')


On Tue, May 15, 2012 at 8:11 AM, Gavin Simpson<gavin.simpson at ucl.ac.uk  <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>>  wrote:
>/  On Tue, 2012-05-15 at 06:27 -0400, Gang Chen wrote:
/>>/  I have some time series data (with 100 time points) collected from one
/>>/  subject. At each time point three measures were taken under three
/>>/  conditions, and there is an explanatory variable for each condition.
/>/
/>/  The temporal correlation is, in this sense, *nested* within the three
/>/  different conditions. You were close with time:condition, but what I
/>/  think you need is
/>/
/>/  corARMA(c(0.02, 0.03), form = ~ time | condition)
/>/
/>/  HTH
/>/
/>/  G
/>/
/>>/  Below is just some fake data to demonstrate the data structure:
/>>/
/>>/  # 100 time points per condition
/>>/  tp<- 100                             # time points
/>>/  trials<- seq(1, tp, 1)          # time counter
/>>/  condition<- c('a', 'b', 'c')   # three conditions
/>>/
/>>/  # fake data
/>>/  set.seed(5)
/>>/  Dat<- data.frame(time=rep(trials, 3), cond=rep(condition, each=tp),
/>>/  res=rnorm(3*tp))



That is because 'condition' is not in your Dat object. I guess it should be cond.
Why corARMA and not corAR1?

I'm actually not sure whether your modelling approach is correct. The unit is the subject....but the time | cond is imposing the correlation
inside the observations from the same condition. Is that what you want? It would ignore any correlation between 2 observations from different
conditions....but still from the same subject. But perhaps I did not fully understand your original post.


Alain


/

-- 

Dr. Alain F. Zuur
First author of:

1. Analysing Ecological Data (2007).
Zuur, AF, Ieno, EN and Smith, GM. Springer. 680 p.
URL: www.springer.com/0-387-45967-7


2. Mixed effects models and extensions in ecology with R. (2009).
Zuur, AF, Ieno, EN, Walker, N, Saveliev, AA, and Smith, GM. Springer.
http://www.springer.com/life+sci/ecology/book/978-0-387-87457-9


3. A Beginner's Guide to R (2009).
Zuur, AF, Ieno, EN, Meesters, EHWG. Springer
http://www.springer.com/statistics/computational/book/978-0-387-93836-3


4. Zero Inflated Models and Generalized Linear Mixed Models with R. (2012) Zuur, Saveliev, Ieno.
http://www.highstat.com/book4.htm

Other books: http://www.highstat.com/books.htm


Statistical consultancy, courses, data analysis and software
Highland Statistics Ltd.
6 Laverock road
UK - AB41 6FN Newburgh
Tel: 0044 1358 788177
Email: highstat@highstat.com
URL: www.highstat.com
URL: www.brodgar.com


	[[alternative HTML version deleted]]

