Skip to content
Prev 8194 / 20628 Next

Specifying correlation structure

Your variables are looked up in *Dat*, it would be a mistake to try rely
upon variable being found in various environments as you are doing here.
That would also force you to consider what you are doing and how you are
setting up your data in R. Put everything into `Dat`, including the
`regx` variables.

I didn't realise this at the time but you are doing this:

Dat <- data.frame(time=rep(trials, 3), cond=rep(condition, each=tp),
                  res=rnorm(3*tp))

notice you are now calling the condition variable `cond`! So it is no
wonder that `condition` doesn't have the required length.

If you use the `Dat` as defined, then

(fm <- gls(res ~ 1+reg1+reg2+reg3,
           correlation=corARMA(c(0.02, 0.03), form=~time|cond, p=1,q=1),
           data=Dat))

works fine
form=~time|cond, p=1,q=1), data=Dat))
Generalized least squares fit by REML
  Model: res ~ 1 + reg1 + reg2 + reg3 
  Data: Dat 
  Log-restricted-likelihood: -425.2665

Coefficients:
(Intercept)        reg1        reg2        reg3 
 0.01305633 -0.03300839 -0.08407831  0.03701266 

Correlation Structure: ARMA(1,1)
 Formula: ~time | cond 
 Parameter estimate(s):
      Phi1     Theta1 
-0.1197791  0.1345616 
Degrees of freedom: 300 total; 296 residual
Residual standard error: 0.9848909

Although I would probably clean up my working environment and call `Dat
$cond` `Dat$condition` but it is up to you. Just make sure you are
referring to things **in** `Dat` with the correct names.

HTH

G
On Tue, 2012-05-15 at 09:07 -0400, Gang Chen wrote: