Data Set

tbl_si_dat <- tibble::tibble(Animal = c(1:5),
                             Sire   = c(NA, NA, NA, 1, 4),
                             Dam    = c(NA, NA, NA, 2, 3),
                             Sex    = c("M", "F", "F", "M", "F"),
                             WWG    = c(4.5, 2.9, 3.9, 3.5, 5.0),
                             PWG    = c(7, 4.2, 5.9, 6.1, 6.9))

tbl_si_dat

Observations

Vector \(y\)

(vec_y <- c(tbl_si_dat$WWG, tbl_si_dat$PWG))
 [1] 4.5 2.9 3.9 3.5 5.0 7.0 4.2 5.9 6.1 6.9

Variance-Covariance Matrix Between Traits

The genetic variance-covariance matrix \(G_0\) contains variances and covariances between the different traits.

(mat_G0 <- matrix(c(20, 18,
                    18, 40), nrow = 2, byrow = TRUE))
     [,1] [,2]
[1,]   20   18
[2,]   18   40

This means that the genetic variance of trait 1 (‘WWG’) is 20 and the genetic variance of trait 2 (‘PWG’) is 40 and the genetic covariance between the two traits is 18.

Similarly for the errors, we the matrix \(R_0\)

(mat_R0 <- matrix(c(40, 11,
                    11, 30), nrow = 2, byrow = TRUE))
     [,1] [,2]
[1,]   40   11
[2,]   11   30

Error Terms

The variance covariance matrix of all the error terms (for all animals with observations and all traits),

\[R = R_0 \otimes I_n\]

(mat_R <- mat_R0 %x% mat_In)
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]   40    0    0    0    0   11    0    0    0     0
 [2,]    0   40    0    0    0    0   11    0    0     0
 [3,]    0    0   40    0    0    0    0   11    0     0
 [4,]    0    0    0   40    0    0    0    0   11     0
 [5,]    0    0    0    0   40    0    0    0    0    11
 [6,]   11    0    0    0    0   30    0    0    0     0
 [7,]    0   11    0    0    0    0   30    0    0     0
 [8,]    0    0   11    0    0    0    0   30    0     0
 [9,]    0    0    0   11    0    0    0    0   30     0
[10,]    0    0    0    0   11    0    0    0    0    30

Genetic Additive

The variance-covariance matrix of all the breeding values

\[G = G_0 \otimes A\]

where \(A\) is the numerator relationship matrix

The numerator relationship matrix \(A\)

(mat_A <- as.matrix(pedigreemm::getA(ped = ped)))

The matrix \(G\) is

(mat_G <- mat_G0 %x% mat_A)
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,] 20.0  0.0    0   10  5.0 18.0  0.0    0    9   4.5
 [2,]  0.0 20.0    0   10  5.0  0.0 18.0    0    9   4.5
 [3,]  0.0  0.0   20    0 10.0  0.0  0.0   18    0   9.0
 [4,] 10.0 10.0    0   20 10.0  9.0  9.0    0   18   9.0
 [5,]  5.0  5.0   10   10 20.0  4.5  4.5    9    9  18.0
 [6,] 18.0  0.0    0    9  4.5 40.0  0.0    0   20  10.0
 [7,]  0.0 18.0    0    9  4.5  0.0 40.0    0   20  10.0
 [8,]  0.0  0.0   18    0  9.0  0.0  0.0   40    0  20.0
 [9,]  9.0  9.0    0   18  9.0 20.0 20.0    0   40  20.0
[10,]  4.5  4.5    9    9 18.0 10.0 10.0   20   20  40.0

Inverse Matrices

The matrix \(G^{-1} = G_0^{-1} \otimes A^{-1}\)

mat_G0inv <- solve(mat_G0)
mat_Ainv <- as.matrix(pedigreemm::getAInv(ped = ped))
(mat_Ginv <- mat_G0inv %x% mat_Ainv)
             [,1]        [,2]        [,3]        [,4]        [,5]        [,6]        [,7]        [,8]        [,9]       [,10]
 [1,]  0.12605042  0.04201681  0.00000000 -0.08403361  0.00000000 -0.05672269 -0.01890756  0.00000000  0.03781513  0.00000000
 [2,]  0.04201681  0.12605042  0.00000000 -0.08403361  0.00000000 -0.01890756 -0.05672269  0.00000000  0.03781513  0.00000000
 [3,]  0.00000000  0.00000000  0.12605042  0.04201681 -0.08403361  0.00000000  0.00000000 -0.05672269 -0.01890756  0.03781513
 [4,] -0.08403361 -0.08403361  0.04201681  0.21008403 -0.08403361  0.03781513  0.03781513 -0.01890756 -0.09453782  0.03781513
 [5,]  0.00000000  0.00000000 -0.08403361 -0.08403361  0.16806723  0.00000000  0.00000000  0.03781513  0.03781513 -0.07563025
 [6,] -0.05672269 -0.01890756  0.00000000  0.03781513  0.00000000  0.06302521  0.02100840  0.00000000 -0.04201681  0.00000000
 [7,] -0.01890756 -0.05672269  0.00000000  0.03781513  0.00000000  0.02100840  0.06302521  0.00000000 -0.04201681  0.00000000
 [8,]  0.00000000  0.00000000 -0.05672269 -0.01890756  0.03781513  0.00000000  0.00000000  0.06302521  0.02100840 -0.04201681
 [9,]  0.03781513  0.03781513 -0.01890756 -0.09453782  0.03781513 -0.04201681 -0.04201681  0.02100840  0.10504202 -0.04201681
[10,]  0.00000000  0.00000000  0.03781513  0.03781513 -0.07563025  0.00000000  0.00000000 -0.04201681 -0.04201681  0.08403361

The matrix \(G^{-1}\) is to be used in mixed model equations of Exercise 9.

Check

round(mat_G %*% mat_Ginv, digits = 6)
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1    0    0    0    0    0    0    0    0     0
 [2,]    0    1    0    0    0    0    0    0    0     0
 [3,]    0    0    1    0    0    0    0    0    0     0
 [4,]    0    0    0    1    0    0    0    0    0     0
 [5,]    0    0    0    0    1    0    0    0    0     0
 [6,]    0    0    0    0    0    1    0    0    0     0
 [7,]    0    0    0    0    0    0    1    0    0     0
 [8,]    0    0    0    0    0    0    0    1    0     0
 [9,]    0    0    0    0    0    0    0    0    1     0
[10,]    0    0    0    0    0    0    0    0    0     1
LS0tCnRpdGxlOiAiS3JvbmVja2VyIFByb2R1Y3RzIGZvciBNdWx0aXZhcmlhdGUgQW5hbHlzZXMiCm91dHB1dDogaHRtbF9ub3RlYm9vawotLS0KCgojIERhdGEgU2V0CgpgYGB7cn0KdGJsX3NpX2RhdCA8LSB0aWJibGU6OnRpYmJsZShBbmltYWwgPSBjKDE6NSksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgU2lyZSAgID0gYyhOQSwgTkEsIE5BLCAxLCA0KSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICBEYW0gICAgPSBjKE5BLCBOQSwgTkEsIDIsIDMpLAogICAgICAgICAgICAg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