# knitr::opts_chunk$set(echo = FALSE, results = 'asis')
We assume that the absorption of cholesterol is determined by a certain enzyme. The level of enzyme production is determined by a single bi-allelic locus $E$. The genotype frequencies and the genotypic values for the two dairy cattle populations Original Braunvieh
and Brown Swiss
are given in the following table.
l_maf <- list(ob = 0.25, bs = 0.1) l_a <- list(ob = 15, bs = 29) l_d <- list(ob = 3, bs = 0) tbl_geno_freq_value <- tibble::tibble(Variable = c( "$f(E_1E_1)$", "$f(E_1E_2)$", "$f(E_2E_2)$", "$a$", "$d$"), `Original Braunvieh` = c( l_maf$ob^2, 2*l_maf$ob*(1-l_maf$ob), (1-l_maf$ob)^2, l_a$ob, l_d$ob ), `Brown Swiss` = c( l_maf$bs^2, 2*l_maf$bs * (1-l_maf$bs), (1-l_maf$bs), l_a$bs, l_d$bs )) knitr::kable(tbl_geno_freq_value, booktabs = TRUE, escape = FALSE)
Compute the breeding values for all three genotypes in both populations.
\pagebreak
In R, matrices are constructed using the function matrix()
. This function accepts different options. We want to see, how these options work.
Your Task: Construct matrices using the different options to better understand the meaning of the different options.
data
data
: Specify the different matrix elements(matA <- matrix(data = c(1:9), nrow = 3, ncol = 3))
data
: without specifying the matrix elements(matB <- matrix(nrow = 3, ncol = 3))
data
: specifying not all matrix elements(matC <- matrix(data = c(1,2,3), nrow = 3, ncol = 3))
(matC2 <- matrix(data = c(1,2,3,4), nrow = 3, ncol = 3))
nrow
and ncol
(matD <- matrix(data = c(1:9), nrow = 3))
(matE <- matrix(data = c(1:9), ncol = 3))
byrow
(matF <- matrix(data = c(1:9), nrow = 3, ncol = 3, byrow = TRUE))
(matG <- matrix(data = c(1:9), nrow = 3, ncol = 3, byrow = FALSE))
In R, matrices can be multiplied using the operator %*%
or with the functions crossprod()
or tcrossprod()
. With crossprod()
and tcrossprod()
vectors and matrices can be multiplied directly. The conversion of vectors to matrices is done automatically inside of these functions. The result will always be a matrix. When doing matrix-vector multiplications with %*%
the vector has to be converted first into a matrix using the function as.matrix()
.
In a first part of this problem, compare the results of the functions crossprod()
, tcrossprod()
and %*%
.
a) Given are the following matrices
matA <- matrix(data = c(1:9), ncol = 3) matB <- matrix(data = c(2:10), ncol = 3)
Find out which matrix multiplication with %*%
corresponds to the following statement?
crossprod(matA,matB)
b) Given is the vector vecB
vecB <- c(-3,16,1)
Multiply the matrix matA
with the vector vecB
once using %*%
and then with the function crossprod()
.
Hint: a vector can be converted to a matrix using the function as.matrix()
.
In a population the following numbers of genotypes were counted for a given genetic locus called $A$.
dfGenotypeFreq <- data.frame(Genotypes = c("$A_1A_1$", "$A_1A_2$", "$A_2A_2$"), Numbers = c(24, 53, 23), stringsAsFactors = FALSE) knitr::kable(dfGenotypeFreq)
a) Compute the genotype frequencies b) Compute the allele frequencies c) Compute the population mean $\mu$ under the following assumptions
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.