knitr::opts_chunk$set(echo = TRUE, results = "markup")

Data

nr_animal <- 5
tbl_decomp <- tibble::tibble(Animal = c(1:nr_animal),
                             Sire = c(NA, NA, NA, 1, 4),
                             Dam = c(NA, NA, NA, 2, 3),
                             Trait = c(4.5, 2.9, 3.9, 3.5, 5.0))
tbl_decomp

Model

$$y = X\mu + Zu + e$$

Components

X = matrix(1, nrow = nr_animal, ncol = 1)
X
Z = diag(1, nrow = nr_animal)
Z

Pedigree

ped = pedigreemm::pedigree(sire = tbl_decomp$Sire, 
                           dam = tbl_decomp$Dam,
                           label = as.character(1:nr_animal))
Ainv <- as.matrix(pedigreemm::getAInv(ped = ped))
Ainv

MME

xtx <- crossprod(X)
xtx
xtz <- crossprod(X, Z)
xtz
ztx <- crossprod(Z, X)
ztx
ztz <- crossprod(Z)
ztz
sigmae2 <- 40
sigmau2 <- 20
lambda <- sigmae2/sigmau2
lambda
ztzainvlambda <- ztz + Ainv * lambda
ztzainvlambda
coef_mat <- rbind(cbind(xtx, xtz), cbind(ztx, ztzainvlambda))
coef_mat
y <- tbl_decomp$Trait
xty <- crossprod(X,y)
zty <- crossprod(Z,y)
rhs <- rbind(xty, zty)
rhs 

Solitions

sol <- solve(coef_mat, rhs)
sol

Decomposition



charlotte-ngs/lbgfs2021 documentation built on Dec. 19, 2021, 3:01 p.m.