Pedigree
nr_animal <- 6
tbl_pedigree <- tibble::tibble(Calf = c(1:nr_animal),
Sire = c(NA, NA, NA, 1 ,3, 4),
Dam = c(NA, NA, NA, 2, 2, 5))
tbl_pedigree
Numerator Relationship Matrix
We call the numerator relationship matrix \(A\). The computation of the elements of \(A\) are done separately for
- the diagnoal elements \((A)_{ii}\) and
- the off-diagonal elements \((A)_{ij}\) for \(i \ne j\)
First all elements of the matrix \(A\) are initialized to \(0\)
A = matrix(0, nrow = nr_animal, ncol = nr_animal)
A
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0 0 0 0 0 0
[2,] 0 0 0 0 0 0
[3,] 0 0 0 0 0 0
[4,] 0 0 0 0 0 0
[5,] 0 0 0 0 0 0
[6,] 0 0 0 0 0 0
Diagonal Elements
Computation: \((A)_{ii} = (1 + F_i)\) and \(F_i = 1/2 (A)_{sd}\)
i <- 1
s <- tbl_pedigree$Sire[i]
d <- tbl_pedigree$Dam[i]
Fi <- ifelse((is.na(s) | is.na(d)), 0, 0.5 * A[s,d])
A[i,i] <- 1+Fi
A
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 0 0 0 0 0
[2,] 0 0 0 0 0 0
[3,] 0 0 0 0 0 0
[4,] 0 0 0 0 0 0
[5,] 0 0 0 0 0 0
[6,] 0 0 0 0 0 0
Off-diagonal Elements
Off-diagonal \((A)_{ij} = 1/2 (A)_{io} + 1/2 (A)_{iq}\) where \(o\) and \(q\) are parents of \(j\)
for (j in (i+1):6){
o <- tbl_pedigree$Sire[j]
q <- tbl_pedigree$Dam[j]
Aio <- ifelse(is.na(o), 0, A[i,o])
Aiq <- ifelse(is.na(q), 0, A[i,q])
A[i,j] <- 0.5 * Aio + 0.5 * Aiq
}
A[(i+1):6,i] <- A[i,(i+1):6]
A
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1.00 0 0 0.5 0 0.25
[2,] 0.00 0 0 0.0 0 0.00
[3,] 0.00 0 0 0.0 0 0.00
[4,] 0.50 0 0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