The pedigree used during the lecture corresponds to
suppressPackageStartupMessages( library(pedigreemm) )
n_nr_ani_ped <- 5
n_nr_parent <- 3
tbl_ped_simple <- dplyr::data_frame(Calf = c(1:n_nr_ani_ped),
Sire = c(NA, NA, NA, 1, 3),
Dam = c(NA, NA, NA, 2, 2))
### # pedigreemm
(ped_simple <- pedigree(sire = tbl_ped_simple$Sire, dam = tbl_ped_simple$Dam, label = as.character(1:n_nr_ani_ped)))
(matA_simple <- as.matrix(getA(ped = ped_simple)))
1 2 3 4 5
1 1.0 0.0 0.0 0.50 0.00
2 0.0 1.0 0.0 0.50 0.50
3 0.0 0.0 1.0 0.00 0.50
4 0.5 0.5 0.0 1.00 0.25
5 0.0 0.5 0.5 0.25 1.00
(matD <- diag(Dmat(ped = ped_simple), n_nr_ani_ped))
[,1] [,2] [,3] [,4] [,5]
[1,] 1 0 0 0.0 0.0
[2,] 0 1 0 0.0 0.0
[3,] 0 0 1 0.0 0.0
[4,] 0 0 0 0.5 0.0
[5,] 0 0 0 0.0 0.5
### # get diagonal matrix S with diagonal elements being sqrt of elements of matD
matS <- sqrt(matD)
### # LDL decomposition based on cholesky
matR <- t(chol(matA_simple));matR
1 2 3 4 5
1 1.0 0.0 0.0 0.0000000 0.0000000
2 0.0 1.0 0.0 0.0000000 0.0000000
3 0.0 0.0 1.0 0.0000000 0.0000000
4 0.5 0.5 0.0 0.7071068 0.0000000
5 0.0 0.5 0.5 0.0000000 0.7071068
(matL <- matR %*% solve(matS))
[,1] [,2] [,3] [,4] [,5]
1 1.0 0.0 0.0 0 0
2 0.0 1.0 0.0 0 0
3 0.0 0.0 1.0 0 0
4 0.5 0.5 0.0 1 0
5 0.0 0.5 0.5 0 1
(matA_verify <- matL %*% matD %*% t(matL))
1 2 3 4 5
1 1.0 0.0 0.0 0.50 0.00
2 0.0 1.0 0.0 0.50 0.50
3 0.0 0.0 1.0 0.00 0.50
4 0.5 0.5 0.0 1.00 0.25
5 0.0 0.5 0.5 0.25 1.00
matA_simple - matA_verify
1 2 3 4 5
1 0 0 0 0 0
2 0 0 0 0 0
3 0 0 0 0 0
4 0 0 0 0 0
5 0 0 0 0 0