LBG - FS2024 – Exercise 6

Author

Peter von Rohr

Problem 1: Numerator Relationship Matrix

The following pedigree is given

s_ped_data <- "https://charlotte-ngs.github.io/lbgfs2024/data/ped_num_rel_mat.csv"
tbl_pedigree <- readr::read_delim(file = s_ped_data, 
                                  col_types = readr::cols(Calf = readr::col_integer(),
                                                          Sire = readr::col_integer(),
                                                          Dam = readr::col_integer()))
knitr::kable(tbl_pedigree, booktabs = TRUE, longtable = TRUE)

The pedigree can be read from the file:

Compute the numerator relationship matrix A for the given pedigree. Recall from the course notes that elements of matrix A are computed differently for elements on the diagonal and for off-diagonal elements. In summary, we compute

  • diagonal element (A)ii as (A)ii=1+Fi where Fi=0.5(A)sd where s and d are parents of i.
  • off-diagonal element (A)ki as (A)ki=0.5[(A)ks+(A)kd] where s and d are parents of i

Task

Use two nested loops over the rows and the columns of matrix A to compute all the elements of matrix A using the formulas given above. You can use the following steps to get to the solution

  • Read the pedigree from the given file
  • Add parents that do not appear as animals to the column of animals
  • Create an empty square matrix A with as many rows and columns as we have animals in the pedigree.
  • Use the above formula to compute the diagonal element of the first row
  • Create a first loop to compute all the off-diagonal elements of the first row
  • Create a loop to repeat the computations over all rows.

Solution

Pedigree is read from the given file

# read pedigree
_webr_editor_3 = Object {code: null, options: Object, indicator: Ke}

Find animals that appear only as parents, start with sires

# find founder sires
_webr_editor_4 = Object {code: null, options: Object, indicator: Ke}

The same for the dams

# find founder dams
_webr_editor_5 = Object {code: null, options: Object, indicator: Ke}

Combining them into one vector and sorting them

# combine founders of both sexes
_webr_editor_6 = Object {code: null, options: Object, indicator: Ke}

Add pedigree records for founder animals at the top of the pedigree

# extend pedigree with founder records
_webr_editor_7 = Object {code: null, options: Object, indicator: Ke}

An empty matrix A is initialized

# start with empty matrix A
_webr_editor_8 = Object {code: null, options: Object, indicator: Ke}

Start with the diagonal elemenent for animal 1

# diagonal for animal 1
_webr_editor_9 = Object {code: null, options: Object, indicator: Ke}

Offdiagonal elements belonging to animal 1

# offdiagonals in first row and first column
_webr_editor_10 = Object {code: null, options: Object, indicator: Ke}

The above two steps can be extended to all rows

# extension to all animals
_webr_editor_11 = Object {code: null, options: Object, indicator: Ke}

Problem 2: Verification

Use the function pedigreemm::getA() from package pedigreemm to verify your result from problem 1.

Solution

The pedigree is defined by

# define pedigree in pedigreemm based on extended version of pedigree
_webr_editor_12 = Object {code: null, options: Object, indicator: Ke}

The numerator relationship matrix is computed by

# compute numerator relationship matrix
_webr_editor_13 = Object {code: null, options: Object, indicator: Ke}

Check whether matrices are identical

# check whether matrices are the same
_webr_editor_14 = Object {code: null, options: Object, indicator: Ke}
Downloading webR