knitr::opts_chunk$set(echo = FALSE, results = "asis")
knitr::knit_hooks$set(hook_convert_odg = rmdhelp::hook_convert_odg)

BLUP Animal Model

$$y = X\beta + Zu + e$$ \begin{tabular}{lll} where & & \ & $y$ & vector of length $n$ of phenotypic information \ & $\beta$ & vector of length $p$ of unknown fixed effects \ & $X$ & $n \times p$ incidence matrix \ & $u$ & vector of length $q$ of unknown random breeding values \ & $Z$ & $n \times q$ incidence matrix \ & $e$ & vector of length $n$ of unknown random residuals \end{tabular}

Example

n_nr_ani_ped <- 6
n_nr_parent <- 2
tbl_ped <- tibble::tibble(Calf = c((n_nr_parent+1):n_nr_ani_ped),
                             Sire = c(1, 1, 4, 5),
                             Dam  = c(2, NA, 3, 2),
                             Herd = c(1, 2, 2, 1),
                             WWG  = c(4.5, 2.9, 3.9, 3.5))
knitr::kable(tbl_ped, booktabs = TRUE)

Animal Model Setup

vec_y = as.vector(tbl_ped$WWG)
fact_herd <- as.factor(tbl_ped$Herd)
n_nr_obs <- length(vec_y)
n_nr_herds <- nlevels(fact_herd)
### # fixed effects
mat_X <- matrix(c(1, 0,
                  0, 1,
                  0, 1,
                  1, 0), ncol = n_nr_herds, byrow = TRUE)
vec_beta <- rmdhelp::vecGetVecElem(psBaseElement = "\\beta", pnVecLen = n_nr_herds, psResult = "latex")
### # random effects
n_nr_ani <- 6
mat_Z <- cbind(matrix(0, nrow = n_nr_obs, ncol = (n_nr_ani-n_nr_obs)), diag(1, nrow = n_nr_obs))
vec_a <- rmdhelp::vecGetVecElem(psBaseElement = "u", pnVecLen = n_nr_ani, psResult = "latex")
### # residuals
vec_e <- rmdhelp::vecGetVecElem(psBaseElement = "e", pnVecLen = n_nr_obs, psResult = "latex")
cat("$$\n")
cat(paste(rmdhelp::bcolumn_vector(pvec = vec_y, ps_name = 'y'), "\n"))
# cat(" = \n")
# cat("\\left[\n")
# cat(paste(rmdhelp::sConvertMatrixToLaTexArray(pmatAMatrix = mat_X, pnDigits = 0), "\n"), "\n")
# cat("\\right]\n")
# cat("\\left[\n")
# cat(paste(rmdhelp::sConvertVectorToLaTexArray(pvec_avector = vec_beta), "\n"), "\n")
# cat("\\right]\n")
# cat(" + \n")
# cat("\\left[\n")
# cat(paste(rmdhelp::sConvertMatrixToLaTexArray(pmatAMatrix = mat_Z, pnDigits = 0), "\n"), "\n")
# cat("\\right]\n")
# cat("\\left[\n")
# cat(paste(rmdhelp::sConvertVectorToLaTexArray(pvec_avector = vec_a), "\n"), "\n")
# cat("\\right]\n")
# cat(" + \n")
# cat("\\left[\n")
# cat(paste(rmdhelp::sConvertVectorToLaTexArray(pvec_avector = vec_e), "\n"), "\n")
# cat("\\right]\n")
cat("$$\n")
cat("$$\n")
cat(paste(rmdhelp::bmatrix(pmat = mat_X, ps_name = 'X'), "\n"))
cat("\\text{, }")

cat(paste(rmdhelp::bcolumn_vector(pvec = vec_beta, ps_name = '\\beta'), "\n"))
cat("$$\n")

Breeding Values As Random Effects and Residuals

cat("$$\n")
cat(paste(rmdhelp::bmatrix(pmat = mat_Z, ps_name = 'Z'), "\n"))
cat("\\text{, }")
cat(paste(rmdhelp::bcolumn_vector(pvec = vec_a, ps_name = 'u'), "\n"))
cat("\\text{, }")
cat(paste(rmdhelp::bcolumn_vector(pvec = vec_e, ps_name = 'e'), "\n"))
cat("$$\n")

Putting Everything Together

cat("$$\n")
cat(paste(rmdhelp::bcolumn_vector(pvec = vec_y), "\n"))
cat(" = \n")
cat(paste(rmdhelp::bmatrix(pmat = mat_X), "\n"))
cat(paste(rmdhelp::bcolumn_vector(pvec = vec_beta), "\n"))
cat(" + \n")
cat(paste(rmdhelp::bmatrix(pmat = mat_Z), "\n"))
cat(paste(rmdhelp::bcolumn_vector(pvec = vec_a), "\n"))
cat(" + \n")
cat(paste(rmdhelp::bcolumn_vector(pvec = vec_e), "\n"))
cat("$$\n")

Solution with Mixed Model Equations

\begin{equation} \left[ \begin{array}{lr} X^T R^{-1} X & X^T R^{-1} Z \ Z^T R^{-1} X & Z^T R^{-1} Z + G^{-1} \end{array} \right] \left[ \begin{array}{c} \hat{\beta} \ \hat{u} \end{array} \right] = \left[ \begin{array}{c} X^T R^{-1} y \ Z^T R^{-1} y \end{array} \right] \notag \end{equation}

\begin{equation} \left[ \begin{array}{lr} X^T X & X^T Z \ Z^T X & Z^T Z + \lambda * A^{-1} \end{array} \right] \left[ \begin{array}{c} \hat{\beta} \ \hat{u} \end{array} \right] = \left[ \begin{array}{c} X^T y \ Z^T y \end{array} \right] \notag \end{equation}

with $\lambda = \sigma_e^2 / \sigma_u^2$

Components of Mixed Model Equations

### # preliminary computations
mat_xtx <- crossprod(mat_X)
mat_xtz <- crossprod(mat_X, mat_Z)
mat_ztx <- t(mat_xtz)
mat_ztz <- crossprod(mat_Z)
mat_xty <- crossprod(mat_X, vec_y)
mat_zty <- crossprod(mat_Z, vec_y)

### # show components
cat("$$\n")
cat(paste(rmdhelp::bmatrix(pmat = mat_xtx, ps_name = 'X^TX'), "\n"))
cat("\\text{, } ")
cat(paste(rmdhelp::bmatrix(pmat = mat_xtz, ps_name = 'X^TZ'), "\n"))
cat("$$\n")

cat("$$\n")
cat(paste(rmdhelp::bmatrix(pmat = mat_ztz, ps_name = 'Z^TZ'), "\n"))
cat("\\text{, } ")
cat(paste(rmdhelp::bmatrix(pmat = mat_xty, ps_name = 'X^Ty'), "\n"))
cat("\\text{, } ")
cat(paste(rmdhelp::bmatrix(pmat = mat_zty, ps_name = 'Z^Ty'), "\n"))
cat("$$\n")

Numerator Relationship Matrix

$$var(u) = G = A * \sigma_u^2$$

Meaning of $var()$ for scalar variable $x$

$$var(x) = \sum\left( x - E[x]\right)^2 f(x)$$ for a discrete random variable $x$, e.g. genotypic values $V$ in single locus model.

$$var(x) = \int \left( x - E[x]\right)^2 f(x) dx$$ for a continuous random variable $x$.

Meaning of $var()$ for a vector $u$

vec_u <- rmdhelp::vecGetVecElem(psBaseElement = 'u', pnVecLen = 2, psResult = 'latex')
vec_u <- c(vec_u, '...', 'u_{q}')
cat(paste(rmdhelp::bcolumn_vector(pvec = vec_u, ps_name = 'u', ps_env = '$$'), collapse = '\n'), '\n')

Meaning of $A$

#rmdhelp::use_odg_graphic(ps_path = "odg/animalcov.odg")
knitr::include_graphics(path = "odg/animalcov.png")

Elements of $A$

Example

Elements of $G$ are computed as



charlotte-ngs/lbgfs2020 documentation built on Dec. 20, 2020, 5:39 p.m.