knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Indices are computed using weighting factors or economic values. Both are read from csv-formatted files. The second type of input corresponds to a space-separated text file containing predicted breeding values for all animals.
### # specify a given file s_factor_input_path <- system.file("extdata", "economic_values", "economic_value_relative.csv", package = "MeatValueIndex") ### # reading economic values tbl_ev_factors <- readr::read_csv(file = s_factor_input_path) tbl_ev_factors
The second input are the breeding values
### # specify path to breeding value file s_bv_input_path <- system.file("extdata", "breeding_values", "test_rawSolutionsQualitas_Mitrassenbasis.txtpubUpdated", package = "MeatValueIndex") ### # reading s_bv_input_path tbl_bv <- readr::read_delim(file = s_bv_input_path, delim = " ") tbl_bv
We start with joining the factors to the breeding values
library(dplyr) tbl_bv_ev <- tbl_bv %>% inner_join(tbl_ev_factors, by = c("trait" = "Trait", "breed" = "Breed")) %>% select(-c(pubCode,base)) tbl_bv_ev <- tbl_bv_ev %>% mutate(index=estimate*Ev) tbl_index <- tbl_bv_ev %>% group_by(idaTvd) %>% summarise(IndexSum = sum(index)) tbl_index
readr::write_csv(tbl_index, path = "index_slaughter_traits.csv")
Correlations between index values and breeding values of single traits are computed as follows
s_trait_name <- "ccc" tbl_bv_ccc_sf <- tbl_bv %>% filter(trait == s_trait_name & breed == "SF") %>% select(idaTvd, estimate) %>% inner_join(tbl_index, by = c("idaTvd" = "idaTvd")) tbl_bv_ccc_sf
cor(tbl_bv_ccc_sf$IndexSum, tbl_bv_ccc_sf$estimate)
tbl_cor_result <- tibble::data_frame(Trait = c("cca", "ccc", "cfa", "cfc", "cwa", "cwc"), OB = c(rep(NA, 6)), BV = c(rep(NA, 6)), SI = c(rep(NA, 6)), SF = c(rep(NA, 6)), MO = c(rep(NA, 6))) tbl_cor_result tbl_cor_result[2,3] <- 0.24 tbl_cor_result vec_breed <- colnames(tbl_cor_result) vec_trait <- tbl_cor_result[,1][[1]] for (bidx in 2:ncol(tbl_cor_result)){ b <- vec_breed[bidx] cat("Computation for breed: ", b, "\n") for (tidx in seq_along(vec_trait)){ t <- vec_trait[tidx] cat("Use trait: ", t, "\n") tbl_cor_result[tidx, bidx] <- MeatValueIndex::compute_correlation(ptbl_bv = tbl_bv, ptbl_index = tbl_index, ps_breed = b, ps_trait = t) } } tbl_cor_result knitr::kable(tbl_cor_result, booktabs = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.