# [R] beginner gls (nlme) question

Simon Blomberg Simon.Blomberg at anu.edu.au
Wed Jul 9 01:48:25 CEST 2003

```Hi,

Well since I have gotten no responses to my question, I managed to figure it out for myself (I think.). Here is the answer, for the purposes of the archive:

Firstly, I was wrong in that it is not the factors that are correlated, but the observations (D'oh!). Therefore, the correlation matrix will have dimension 2^3 * 5 = 40. However, we can simplify the structure if we assume no correlation among replicates of the same treatment (using a grouping variable), reducing the matrix to dimension 2^3=8. ie the correlations among the observations of the interactions also have to be specified, not just the main effects. The data set looks like:

A B C   response group
1  0 0 0  40.411581     1
2  1 0 0  19.926468     1
3  0 1 0  70.824970     1
4  1 1 0  37.298386     1
5  0 0 1 108.361849     1
6  1 0 1  67.315986     1
7  0 1 1   7.843482     1
8  1 1 1  45.648360     1
9  0 0 0 115.457913     2
10 1 0 0  42.650458     2
11 0 1 0  88.852955     2
12 1 1 0 116.738213     2
13 0 0 1 150.724565     2
14 1 0 1  81.888251     2
15 0 1 1  47.178701     2
16 1 1 1  28.822613     2
...

and the correlation matrix mat is:

> mat
Int    A    B C  A:B A:C B:C A:B:C
Int     1 0.00 0.00 0 0.00   0   0     0
A       0 1.00 0.75 0 0.75   0   0     0
B       0 0.75 1.00 0 0.75   0   0     0
C       0 0.00 0.00 1 0.00   0   0     0
A:B     0 0.75 0.75 0 1.00   0   0     0
A:C     0 0.00 0.00 0 0.00   1   0     0
B:C     0 0.00 0.00 0 0.00   0   1     0
A:B:C   0 0.00 0.00 0 0.00   0   0     1

Then the call to gls will be:

gls(response~A*B*C, data=dat, correlation=corSymm(mat[lower.tri(mat)], form= ~1|group))

Simon.

Simon Blomberg, PhD
Depression & Anxiety Consumer Research Unit
Centre for Mental Health Research
Australian National University
http://www.anu.edu.au/cmhr/
Simon.Blomberg at anu.edu.au  +61 (2) 6125 3379

> -----Original Message-----
> From: Simon Blomberg
> Sent: Thursday, 3 July 2003 10:53 AM
> To: R-help mailing list
> Subject: [R] beginner gls (nlme) question
>
>
> Hi all,
>
> I am trying to get a handle on gls (package nlme). I have a
> toy problem: 3 fixed factors (A, B, C), two levels each, 5
> replicates per treatment. The response variable is
> continuous, normal. I have a correlation matrix of the form:
>
> > mat
>      A    B C
> A 1.00 0.75 0
> B 0.75 1.00 0
> C 0.00 0.00 1
>
> which is common to all observations.
>
> How do I construct the call to gls? I think I need to use
> correlation=corSymm(), but I do not understand the precise
> syntax. I have read the relevant parts of Pinheiro and Bates,
> but they only talk about cases where the corSymm correlation
> structure is modelled, rather than known. I have also
> searched the R archives, but no luck.
>
> I think it should be of the form gls(response~A*B*C,
> data=dat, correlation=corSymm(...?))
> but I don't understand the arguments to corSymm.
>
>
> Simon.
>
> Simon Blomberg, PhD
> Depression & Anxiety Consumer Research Unit
> Centre for Mental Health Research
> Australian National University
> http://www.anu.edu.au/cmhr/
> Simon.Blomberg at anu.edu.au  +61 (2) 6125 3379
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>

```