knitr::opts_chunk$set(echo = FALSE, results = 'asis')

Problem 1: Vectors

Given are the following two vectors $v$ and $w$. Compute

\begin{center} $v = \left[\begin{array}{c} 3 \ -5 \ 1 \ 9 \ \end{array}\right]$, \hspace{2ex} $w = \left[\begin{array}{c} 1 \ 9 \ -12 \ 27 \ \end{array}\right]$ \end{center}

Solution

The sum $v+w = \left[\begin{array}{c} 3 + 1 \ -5 + 9 \ 1 + (-12) \ 9 + 27 \ \end{array}\right] = \left[\begin{array}{c} 4 \ 4 \ -11 \ 36 \ \end{array}\right]$,

\vspace{2ex}

the difference $v-w = \left[\begin{array}{c} 3 - 1 \ -5 - 9 \ 1 - (-12)\ 9 - 27 \ \end{array}\right] = \left[\begin{array}{c} 2 \ -14 \ 13 \ -18 \ \end{array}\right]$

\vspace{2ex}

The dot product $v\cdot w = 3*1 + (-5) * 9 + 1 * (-12) + 9 * (-27) = 189$

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

Problem 2: Vectors in R

Verify your computations from Problem 1 in R. Start by assigning the vectors $v$ and $w$ with the components given in Problem 1. If you are not sure how to assign vectors in R, please have a look at https://bookdown.org/rdpeng/rprogdatascience/r-nuts-and-bolts.html#creating-vectors and its the corresponding video at https://youtu.be/w8_XdYI3reU

Solution

v <- c(3, -5, 1, 9)
w <- c(1, 9, -12, 27)

Now we do the computations.

The sum $v+w$ is

v+w

The difference $v-w$ is

v-w

and the dot-product is

crossprod(v,w)

or

v %*% w

Please note: Although the R-function is called crossprod() what is computed is the dot product between the two vectors. The function name crossprod() is used because in Statistics the product ($X^TX$) of a transposed matrix ($X^T$) and itself ($X$) is called a matrix crossproduct. This has nothing to do with the crossproduct $v \times w$ between two vectors $v$ and $w$.

Problem 3: Angle between Vectors

Given are two vectors

\begin{center} $a = \left[\begin{array}{c} 8 \ 0 \ 4 \ \end{array}\right]$ and
$b = \left[\begin{array}{c} 2 \ 21 \ x \ \end{array}\right]$ \end{center}

How do we have to choose $x$, such that the vectors are perpendicular? Verify your solution with R

Solution

Two vectors are perpendicular, if their dot product is $0$. The dot product between $a$ and $b$ is computed as

$$a\cdot b = 8 * 2 + 0 * 21 + 4 * x = 0$$

The above formula is an equation for the unknown $x$. Solving for $x$ gives

$$x = - \frac{8*2}{4} = -4$$

In R:

a <- c(8, 0, 4)
x <- -4
b <- c(2, 21, x )
crossprod(a, b)

Problem 4: Phenotypes and Genotypes

# milk yield of Delilah
vec_lact_perf_Delilah <- c(5852, 6833, 7984, 7869, 7322, 8216, 8622, 7851)
# milk yield of Rosy
vec_lact_perf_Rosy <- c(6249, 7312)
# breeding values of Delilah
nLactDelilah <- length(vec_lact_perf_Delilah)
l_ebv_Delilah <- list(Milk = -1037, ND = 112)

# breeding values of Rosy
nLactRosy <- length(vec_lact_perf_Rosy)
l_ebv_Rosy <- list(Milk = 471, ND = 122)

Farmer Frank Miller has two cows named Delilah and Rosy. Delilah has completed r nLactDelilah lactations with the following results

knitr::kable(data.frame(Lactation = 1:nLactDelilah, `Milk Yield` = vec_lact_perf_Delilah))

Rosy is a young cow and has completed just r nLactRosy lactation which is shown below.

knitr::kable(data.frame(Lactation = 1:nLactRosy, `Milk Yield` = vec_lact_perf_Rosy))

Your Tasks

a. Compute for both cows the sum and the mean of all lactation results using R. Hint: Have a look at the functions mean() and sum() in R. b. Our farmer wants to know which of the two cows would be a better mother for his breeding herd when looking at the traits milk yield and longevity. The trait longevity is defined as the number of years a cow is able to produce milk. From the breeding association the farmer receives the following predicted breeding values for the two cows. Please explain which of the two cows is the better choice as a mother.

knitr::kable(data.frame(Cows = c("Delilah", "Rosy"), `Milk Yield` = c(l_ebv_Delilah$Milk, l_ebv_Rosy$Milk), Longevity = c(l_ebv_Delilah$ND, l_ebv_Rosy$ND)))

Solution

a. Assuming the milk performances are assigned the following vector


Then the total milk yield for Delilah is computed as

sum(vec_lact_perf_Delilah)

and the mean milk yield is computed as

mean(vec_lact_perf_Delilah)

The same computations can be done for Rosy


sum(vec_lact_perf_Rosy)
mean(vec_lact_perf_Rosy)

b. Parents do not pass their phenotypes to their offspring, but just a random sample of their alleles. Because the predicted breeding values are an estimated of the genetic potential that is passed from a parent to an offspring it is better to rank the candidates based on their predicted breeding values. Because Rosy has higher breeding values in both traits, our farmer should select her as a mother to produce the next generation. Delilah is a good producing cow and therefore she should be kept in the herd. But it might be better to inseminate her with a beef sire to produce a fattening calf.



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