knitr::opts_chunk$set(echo = TRUE, results = "markup")
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
$$y = X\mu + Zu + e$$
X = matrix(1, nrow = nr_animal, ncol = 1) X
Z = diag(1, nrow = nr_animal) Z
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
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
sol <- solve(coef_mat, rhs) sol
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.