# R structures

## Dimensions

In a traditional analysis, the residuals are IID (Independently and Identically Distributed) in which case the order does not matter. However, ASReml is designed to handle cases where residuals are correlated. Sometimes, these correlations can be defined as a direct product of variance structures, assuming the residuals are in an appropriate order.

#### IID residuals

The variance structure can be written as
``` 0 0 g
```
or
``` 1 1 g
n 0 ID
```
where g is the number of G structures and n is the number of data points. Where there is just 1 section (as in this example), n can be specified as 0 and ASReml will use the number of observations in the data. ID is the VCODE for an Identity matrix.

This analysis will estimate any variance components as ratios relative to the implicit residual variance.

#### Typical field trial - regular rectangular grid

The variance structure can be written as
``` 1 2 g           # 1 section, 2 way layout, g G structures
row row AR1 .1
column column AR1 .1
```
This particular coding assumes there is a factor in the data called row which indexes the rows of the field layout, and another factor column which indexes the columns of the field layout, and that that there are data records for all cells in the complete row x column grid. (It will be necessary to estimate any missing values in the data.)
AR1 is the VCODE for a first order Auroregressive matrix. It requires one parameter (correlation) given an initial value of 0.1.

If the data file does not contain row and column information, but a correlated structure is required, the data records need to be sorted on row and column (even though the coding is not in the file) and the structures (assuming 12 rows and 36 columns) would be written as
``` 1 2 g           # 1 section, 2 way layout, g G structures
12 0 AR1 .1
36 0 AR1 .1
```
So, the first field is the number of rows/columns. The second field controls sorting the plots (no sorting now because the plots are in order).

#### Spatial data - irregular pattern

The variance structure can be written as
``` 1 1 g
n xy MAT1 10
```
Again, n can be written as 0 and ASReml will use the number of observations in the data.
xy is a special numeric code pointing to fields in the data locating the data points. For example if field 3 defines the X-axis (say Easting ) and field 4 defines the Y-axis (say Northing ) then xy would be written as 304.
MAT1 is the VCODE for a MATERN correlation structure with 1 parameter estimated. It requires one parameter (range) given an initial value of 10..

#### Multivariate data

The R structure (assuming 3 traits) can be written as
``` 1 2 g
0              # n 0 ID
Trait 0 US
6*0
```
The data is sorted traits within records so the structure for traits is specified second. Again we let ASReml supply the number of records.
US is the VCODE for an unstructed variance matrix. It requires six initial values: 3 variances and 3 covariances in the order V11 C21 V22 C31 C32 V22 (lower triangle rowwise). However, it is generally difficult to guess suitable values so we have supplied initial values of zeros (6*0 is six zeros) and ASReml will obtain initial values as a proportion of the simple variances and covariances of the residual.