# Relationship Matrices

## Additive Relationship Matrix (Tabular Method)

• R script: createA.txt
• Literature: Henderson, C. R. 1976. Simple Method for Computing the Inverse of a Numerator Relationship Matrix Used in Prediction of Breeding Values. Biometrics 32:69-83.
1. Given the vectors of sire and dam, return additive relationship matrix 'A'.
```> s <- c(0,0,1,1,3,1,5)
> d <- c(0,0,0,2,4,4,6)
> createA(s,d)
[,1] [,2]  [,3]   [,4]    [,5]    [,6]    [,7]
[1,] 1.000 0.00 0.500 0.5000 0.50000 0.75000 0.62500
[2,] 0.000 1.00 0.000 0.5000 0.25000 0.25000 0.25000
[3,] 0.500 0.00 1.000 0.2500 0.62500 0.37500 0.50000
[4,] 0.500 0.50 0.250 1.0000 0.62500 0.75000 0.68750
[5,] 0.500 0.25 0.625 0.6250 1.12500 0.56250 0.84375
[6,] 0.750 0.25 0.375 0.7500 0.56250 1.25000 0.90625
[7,] 0.625 0.25 0.500 0.6875 0.84375 0.90625 1.28125
```

## Additive Relationship Matrix (Recursive Method for Computing L)

• R script: createL.txt
• Literature: Henderson, C. R. 1976. Simple Method for Computing the Inverse of a Numerator Relationship Matrix Used in Prediction of Breeding Values. Biometrics 32:69-83.
1. Given the vectors of sire and dam, return a lower triangular matrix 'L' such that LL' = 'A'.
```> s <- c(0,0,1,1,3,1,5)
> d <- c(0,0,0,2,4,4,6)
> L <- createL(s,d)
> L
[,1] [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
[1,] 1.000 0.00 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
[2,] 0.000 1.00 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
[3,] 0.500 0.00 0.8660254 0.0000000 0.0000000 0.0000000 0.0000000
[4,] 0.500 0.50 0.0000000 0.7071068 0.0000000 0.0000000 0.0000000
[5,] 0.500 0.25 0.4330127 0.3535534 0.7071068 0.0000000 0.0000000
[6,] 0.750 0.25 0.0000000 0.3535534 0.0000000 0.7071068 0.0000000
[7,] 0.625 0.25 0.2165064 0.3535534 0.3535534 0.3535534 0.6373774
> L%*%t(L)
[,1] [,2]  [,3]   [,4]    [,5]    [,6]    [,7]
[1,] 1.000 0.00 0.500 0.5000 0.50000 0.75000 0.62500
[2,] 0.000 1.00 0.000 0.5000 0.25000 0.25000 0.25000
[3,] 0.500 0.00 1.000 0.2500 0.62500 0.37500 0.50000
[4,] 0.500 0.50 0.250 1.0000 0.62500 0.75000 0.68750
[5,] 0.500 0.25 0.625 0.6250 1.12500 0.56250 0.84375
[6,] 0.750 0.25 0.375 0.7500 0.56250 1.25000 0.90625
[7,] 0.625 0.25 0.500 0.6875 0.84375 0.90625 1.28125
```

## Additive Relationship Matrix (Based on 'G' Matrix)

• R script: createAfromG.txt
• Literature: Schaeffer, L. R. 2009. Animal Models Course Note.
1. Given a gametic realationship matrix, return an additive relationship matrix 'A'.
```> s <- c(0,0,1,1,4)
> d <- c(0,0,2,3,2)
> G <- createG(s,d)
> createAfromG(G)
[,1]  [,2]  [,3] [,4]  [,5]
[1,] 1.000 0.000 0.500 0.75 0.375
[2,] 0.000 1.000 0.500 0.25 0.625
[3,] 0.500 0.500 1.000 0.75 0.625
[4,] 0.750 0.250 0.750 1.25 0.750
[5,] 0.375 0.625 0.625 0.75 1.125
```

## Inverse of Additive Relationship Matrix (Noninbred Population)

• R script: createAinv.txt
• Literature: Henderson, C. R. 1976. Simple Method for Computing the Inverse of a Numerator Relationship Matrix Used in Prediction of Breeding Values. Biometrics 32:69-83.
1. Given the vectors of sire and dam, directly return inverse of additive relationship matrix 'A' without creating the 'A' and the lower triagular matrix 'L' themselves. This can only be applied to noninbred populations.
```> s <- c(0,0,1,1,1,1,1,2,7)
> d <- c(0,0,2,2,2,0,0,0,8)
> createAinv(s,d)
[,1]       [,2] [,3] [,4] [,5]       [,6]       [,7]       [,8] [,9]
[1,]  3.1666667  1.5000000   -1   -1   -1 -0.6666667 -0.6666667  0.0000000    0
[2,]  1.5000000  2.8333333   -1   -1   -1  0.0000000  0.0000000 -0.6666667    0
[3,] -1.0000000 -1.0000000    2    0    0  0.0000000  0.0000000  0.0000000    0
[4,] -1.0000000 -1.0000000    0    2    0  0.0000000  0.0000000  0.0000000    0
[5,] -1.0000000 -1.0000000    0    0    2  0.0000000  0.0000000  0.0000000    0
[6,] -0.6666667  0.0000000    0    0    0  1.3333333  0.0000000  0.0000000    0
[7,] -0.6666667  0.0000000    0    0    0  0.0000000  1.8333333  0.5000000   -1
[8,]  0.0000000 -0.6666667    0    0    0  0.0000000  0.5000000  1.8333333   -1
[9,]  0.0000000  0.0000000    0    0    0  0.0000000 -1.0000000 -1.0000000    2
```

## Inverse of Additive Relationship Matrix (A Simple Method Using L)

• R script: createAinvL.txt
• Literature: Henderson, C. R. 1976. Simple Method for Computing the Inverse of a Numerator Relationship Matrix Used in Prediction of Breeding Values. Biometrics 32:69-83.
1. Given the vectors of sire and dam, directly return inverse of additive relationship matrix 'A' based on a lower traingular matrix 'L' without taking the inverse of the 'A' itself.
```> s <- c(0,0,1,1,3,1,5)
> d <- c(0,0,0,2,4,4,6)
> createAinvL(s,d)
[,1] [,2]       [,3] [,4]       [,5]       [,6]      [,7]
[1,]  2.3333333  0.5 -0.6666667 -0.5  0.0000000 -1.0000000  0.000000
[2,]  0.5000000  1.5  0.0000000 -1.0  0.0000000  0.0000000  0.000000
[3,] -0.6666667  0.0  1.8333333  0.5 -1.0000000  0.0000000  0.000000
[4,] -0.5000000 -1.0  0.5000000  3.0 -1.0000000 -1.0000000  0.000000
[5,]  0.0000000  0.0 -1.0000000 -1.0  2.6153846  0.6153846 -1.230769
[6,] -1.0000000  0.0  0.0000000 -1.0  0.6153846  2.6153846 -1.230769
[7,]  0.0000000  0.0  0.0000000  0.0 -1.2307692 -1.2307692  2.461538
```

## Inverse of Additive Relationship Matrix (Rapid Computation of the Diagonal of L)

• R script: quaas.txt
• Literature: Quaas, R. L. 1976. Computing the Diagonal Elements and Inverse of a Large Numerator Relationship Matrix. Biometrics 32:949-953.
1. Given the vectors of sire and dam, directly return inverse of additive relationship matrix 'A' without creating the 'A' itself. This is a modification of Henderson's method and unlike createAinv.r, this can be used in inbred populations.
```> s <- c(0,0,1,1,3,1,5)
> d <- c(0,0,0,2,4,4,6)
> quass(s,d)
[,1] [,2]       [,3] [,4]       [,5]       [,6]      [,7]
[1,]  2.3333333  0.5 -0.6666667 -0.5  0.0000000 -1.0000000  0.000000
[2,]  0.5000000  1.5  0.0000000 -1.0  0.0000000  0.0000000  0.000000
[3,] -0.6666667  0.0  1.8333333  0.5 -1.0000000  0.0000000  0.000000
[4,] -0.5000000 -1.0  0.5000000  3.0 -1.0000000 -1.0000000  0.000000
[5,]  0.0000000  0.0 -1.0000000 -1.0  2.6153846  0.6153846 -1.230769
[6,] -1.0000000  0.0  0.0000000 -1.0  0.6153846  2.6153846 -1.230769
[7,]  0.0000000  0.0  0.0000000  0.0 -1.2307692 -1.2307692  2.461538
```

## Dominance Relationship Matrix

• R script: createD.txt
• Literature: Mrode, R.A. 2005. Linear Models for the Prediction of Animal Breeding Values. CAB International, Oxon, UK.
1. Given the vectors of sire and dam, return a dominance relationship matrix 'D'.
```> s <- c(0,0,0,0,1,3,6,0,3,3,6,6)
> d <- c(0,0,0,0,2,4,5,5,8,8,8,8)
> createD(s,d)
[,1] [,2] [,3] [,4] [,5] [,6]   [,7] [,8]   [,9]  [,10] [,11] [,12]
[1,]    1    0    0    0    0    0 0.0000    0 0.0000 0.0000 0.000 0.000
[2,]    0    1    0    0    0    0 0.0000    0 0.0000 0.0000 0.000 0.000
[3,]    0    0    1    0    0    0 0.0000    0 0.0000 0.0000 0.000 0.000
[4,]    0    0    0    1    0    0 0.0000    0 0.0000 0.0000 0.000 0.000
[5,]    0    0    0    0    1    0 0.0000    0 0.0000 0.0000 0.000 0.000
[6,]    0    0    0    0    0    1 0.0000    0 0.0000 0.0000 0.000 0.000
[7,]    0    0    0    0    0    0 1.0000    0 0.0625 0.0625 0.125 0.125
[8,]    0    0    0    0    0    0 0.0000    1 0.0000 0.0000 0.000 0.000
[9,]    0    0    0    0    0    0 0.0625    0 1.0000 0.2500 0.125 0.125
[10,]    0    0    0    0    0    0 0.0625    0 0.2500 1.0000 0.125 0.125
[11,]    0    0    0    0    0    0 0.1250    0 0.1250 0.1250 1.000 0.250
[12,]    0    0    0    0    0    0 0.1250    0 0.1250 0.1250 0.250 1.000
```

## Dominance Relationship Matrix (Based on 'G' Matrix)

• R script: createDfromG.txt
• Literature: Schaeffer, L. R. 2009. Animal Models Course Note.
1. Given a gametic realationship matrix 'G', return a dominance relationship matrix 'D'.
```> s <- c(0,0,1,1,4)
> d <- c(0,0,2,3,2)
> G <- createG(s,d)
> createDfromG(G)
[,1]  [,2] [,3]    [,4]     [,5]
[1,] 1.00 0.000 0.00 0.25000 0.000000
[2,] 0.00 1.000 0.00 0.00000 0.125000
[3,] 0.00 0.000 1.00 0.25000 0.250000
[4,] 0.25 0.000 0.25 1.06250 0.156250
[5,] 0.00 0.125 0.25 0.15625 1.015625
```

## Gametic Relationship Matrix with/without Marker Information (Tabular Method)

• R script: createG.txt
• Literature 1: Fernando, R. L. and Grossman, M. 1989. Marker-Assisted Selection Using Best Linear Unbiased Prediction. Genetic Selection Evolution 21, 467-477.
• Literature 2: Schaeffer, L. R. 2009. Animal Models Course Note.
• Literature 3: Mrode, R.A. 2005. Linear Models for the Prediction of Animal Breeding Values. CAB International, Oxon, UK.
1. Given the vectors of sire and dam with/without marker information, return a gametic relationship matrix 'G'. A marker locus is linked to a marked QTL is assumed. Here is an example from above Schaeffer's course note, which deals with a pedigree of no marker information.
```> s <- c(0,0,1,1,4)
> d <- c(0,0,2,3,2)
> createG(s,d)
[,1]  [,2]  [,3]  [,4] [,5] [,6]  [,7]  [,8]  [,9] [,10]
[1,] 1.000 0.000 0.000 0.000  0.5 0.00 0.500 0.250 0.375 0.000
[2,] 0.000 1.000 0.000 0.000  0.5 0.00 0.500 0.250 0.375 0.000
[3,] 0.000 0.000 1.000 0.000  0.0 0.50 0.000 0.250 0.125 0.500
[4,] 0.000 0.000 0.000 1.000  0.0 0.50 0.000 0.250 0.125 0.500
[5,] 0.500 0.500 0.000 0.000  1.0 0.00 0.500 0.500 0.500 0.000
[6,] 0.000 0.000 0.500 0.500  0.0 1.00 0.000 0.500 0.250 0.500
[7,] 0.500 0.500 0.000 0.000  0.5 0.00 1.000 0.250 0.625 0.000
[8,] 0.250 0.250 0.250 0.250  0.5 0.50 0.250 1.000 0.625 0.250
[9,] 0.375 0.375 0.125 0.125  0.5 0.25 0.625 0.625 1.000 0.125
[10,] 0.000 0.000 0.500 0.500  0.0 0.50 0.000 0.250 0.125 1.000
```
2. Second example is from Mrode (2005), 8.1. This one contains marker information.
```> s <- c(0,0,1,1,4)
> d <- c(0,0,2,3,3)
> sM <- c(0,0,1,2,1)
> dM <- c(0,0,2,1,1)
> r <- 0.1
> createG(s,d,sM,dM,r)
[,1]  [,2]  [,3]  [,4]  [,5] [,6]   [,7]   [,8]   [,9]  [,10]
[1,] 1.000 0.000 0.000 0.000 0.900 0.00 0.1000 0.8100 0.1710 0.8100
[2,] 0.000 1.000 0.000 0.000 0.100 0.00 0.9000 0.0900 0.8190 0.0900
[3,] 0.000 0.000 1.000 0.000 0.000 0.10 0.0000 0.0100 0.0010 0.0100
[4,] 0.000 0.000 0.000 1.000 0.000 0.90 0.0000 0.0900 0.0090 0.0900
[5,] 0.900 0.100 0.000 0.000 1.000 0.00 0.1800 0.9000 0.2520 0.9000
[6,] 0.000 0.000 0.100 0.900 0.000 1.00 0.0000 0.1000 0.0100 0.1000
[7,] 0.100 0.900 0.000 0.000 0.180 0.00 1.0000 0.1620 0.9162 0.1620
[8,] 0.810 0.090 0.010 0.090 0.900 0.10 0.1620 1.0000 0.2458 0.8200
[9,] 0.171 0.819 0.001 0.009 0.252 0.01 0.9162 0.2458 1.0000 0.2278
[10,] 0.810 0.090 0.010 0.090 0.900 0.10 0.1620 0.8200 0.2278 1.0000
```