knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(qp4ewc)

Aim

In this vignette, you will get more information about the construction of the main-function pre_process_ew_input() . This task is to pre-process the input-parameter-files of ECOWEIGHT for beef cattle (EWBC).

Pre-processing part

Major steps of pre_process_ew_input() are

1) function create_directory_scenario() : the task of this function is to create a directory per scenario with template of input-parameter-file for ECOWEIGHT.

2) Read file with input from literature research and update input-parameter-file coming from literature of ECOWEIGHT. All these inputs (minerals, straw, water, dung, veterinary cost, cost removing dead animal, cost stock-man hours, fixed cost, semen, gestation length, natural mating, culled, sold, proportion, milk, protein, fat, governmental support, dry matter, net energy, protein, amount, price) are coming from literature research. Further depending of the * s_sirebreed some values for average price per breeding bull purchased for natural mating or maturity type of progeny, * s_prodsystew some values for production system or mating type for heifers and cows or tested bulls or purchased replacement heifers.

3) function pre_process_ew_input_calving() : the task of this function is to pre-process the calving data (by calculating abortion rate, stillbirth rate, calving score proportions, proportion of calves died to 24 hours) to update the input-parameter-file of ECOWEIGHT. In the calving file s_input_file_calving are the raw calving data readed. With the s_start_date and s_end_date , the time frame of the calving data to consider is set. Most of the calculation are done for primiparous (first lactation) as well as multiparous (more than first lactation). Only for beef-on-beef further calculation like losses of calves from 48 hours after calving and cows artificially inseminated in first oestrus.

4) function pre_process_ewbc_input_progeny_data_flp() : the task of this function is to pre-process the progeny data flp (by calculating mean birth weight, mean live weight at slaughter, mean weaning weight, slaughter age, daily gain between weaning and fattening, extrapolated weight at 300 days, 302 days, 304 days, cow weight after 1st calving, cow weight after second calving, mature cow weight, mature bull weight) to update the input-parameter-file of ECOWEIGHT for beef-on-beef production system. In s_input_file_flp are the carcass and progeny raw data as well as calf export s_input_file_calf readed. With the s_start_date and s_end_date , the time frame of this data are set. The pedigree s_input_file_ped is needed to get the breed of the sire and the dam, so that we can know if we are looking to purebred beef or crossbred. The pedigree informations will be merged with the flp-data-file. There are different situation depending on the s_marketingchannel.

5) function pre_process_ewbc_input_carcass_data_flp() : the task of this function is to pre-process the carcass conformation, fat, prices based on different input like s_input_file_flp, prices to update the input-parameter-file of ECOWEIGHT. Number of classes for fleshiness and fat covering are set (here is to say that for fleshiness we consider X, XX, XXX as the same class X due to the preprocessing of the genetic evaluation for carcass traits). Frequency per slaughtercategory (cow, bull (OB and MT are considered), heifer. Then a price week of Proviande is defined to set the base price.

Parameters

# Sire breed can be: AN,AU,CH,LM,OB,SI corresponding to Angus,Aubrac, Charolais, Limousin, Original-Braunvieh, Simmental
s_sirebreed <- "LM"
# Dam breed can be for beef-on-beef: AN,AU,CH,LM,OB,SI corresponding to Angus,Aubrac, Charolais, Limousin, Original-Braunvieh, Simmental 
s_dambreed <- "LM"
# Production system according to ECOWEIGHT for beef-on-beef: 1,2,3 corresponding to purebreeding, crossbreeding, terminal crossing
s_prodsystem <- "1"
# Marketing channel can be: Natura-Beef, SwissPrimBeef
s_marketingchannel <- "Natura-Beef"
# Path to define from the working directory
s_path_directory2create <- file.path(here::here(),"inst","extdata","ewbc","test","Preprocess_output")
# Path to input from the literature research. Based on this example an other file can be created with different input-value and input-source.
s_input_file_literature <- system.file("extdata","ewbc","input_literature.txt", package = "qp4ewc")
# Path to input from the parameter specific for the scenario. Based on this example an other file can be created with different input-value.
s_input_file_par <- system.file("extdata","ewbc","input_par_statement.txt", package = "qp4ewc")
# path to file with input for file 35 for the input-parameter-file for ECOWEIGHT
s_input_file_35 <- system.file("extdata","ewbc","input35_statement.txt", package = "qp4ewc")
# path to file with input for file 36 for the input-parameter-file for ECOWEIGHT
s_input_file_36 <- system.file("extdata","ewbc","input36_statement.txt", package = "qp4ewc")
# Path to specific input for ProdSyst1 for tested bulls
s_input_file_testedbulls <- system.file("extdata","ewbc","input_testedbulls.txt", package = "qp4ewc")
# Path to specific input for ProdSyst3 for replacement progeny heifers
s_input_file_purchasedreplacementheifers  <- system.file("extdata","ewbc","input_purchasedreplacementheifers.txt", package = "qp4ewc")
# Path to input from the calving. Based on this example an other file can be created with different input-values.
s_input_file_calving_statement <- system.file("extdata","ewbc","input_calving_statement.txt", package = "qp4ewc")
# Path to calving data file
s_input_file_calving <- system.file("extdata","ewbc","test","test_zws_muku_gal.csv", package = "qp4ewc")
# Date YYYYMMDD used as start date to filter data for calving or carcass
s_start_date <- 20000101
# Date YYYYMMDD used as end date to filter data for calving or carcass
s_end_date <- 20211231
# Path to input from the progeny flp data. Based on this example an other file can be created with different input-values.
s_input_file_progeny_flp_statement <- system.file("extdata","ewbc","input_flp_statement.txt", package = "qp4ewc")
# Path to flp data file
s_input_file_flp <- system.file("extdata","ewbc","test","test_zws_muku_flp.csv", package = "qp4ewc")
# Path to calf price data file
s_input_file_calf <- system.file("extdata","ewdc","test","test_calf_data.csv", package = "qp4ewc")
# Path to input statement for carcass and price
s_input_file_flp_carcass_matrix_statement <- system.file("extdata","ewbc","input_flp_carcass_matrix_statement.txt", package = "qp4ewc")
# Path to input with cow price. Based on this example an other file can be created with different input-values.
s_input_file_price_cow <- system.file("extdata","ewbc","cow_price.txt", package = "qp4ewc")
# Path to input with bull price. Based on this example an other file can be created with different input-values.
s_input_file_price_bull <- system.file("extdata","ewbc","bull_price.txt", package = "qp4ewc")
# Path to input with heifer price. Based on this example an other file can be created with different input-values.ONLY REQUIRED BEEF ON DAIRY (will not be used for beef on beef)
s_input_file_price_heifer <- system.file("extdata","ewbc","heifer_price.txt", package = "qp4ewc")
# Path to input with calf price. Based on this example an other file can be created with different input-values.
s_input_file_price_calf <- system.file("extdata","ewdc","veal_price.txt", package = "qp4ewc")
# Path to pedigree input file
s_input_file_ped <- system.file("extdata","ewbc","test","test_pedigree.txt", package = "qp4ewc")
# Flag to set to TRUE, if a log-file is whished
b_log <- TRUE

At the beginning of the function depending of the setting for pb_log and plogger, a log-file will be created.

Run pre_process_ew_input() in RStudio

pre_process_ew_input(ps_sirebreed = s_sirebreed,
                     ps_dambreed = s_dambreed,
                     ps_prodsystew = s_prodsystem,
                     ps_marketchannel = s_marketingchannel,
                     ps_path_directory2create = s_path_directory2create,
                     ps_input_file_literature = s_input_file_literature,
                     ps_input_file_par = s_input_file_par,
                     ps_input_file_35 = s_input_file_35,
                     ps_input_file_36 = s_input_file_36,
                     ps_input_file_testedbulls = s_input_file_testedbulls,
                     ps_input_file_purchasedreplacementheifers = s_input_file_purchasedreplacementheifers,
                     ps_input_file_calving_statement = s_input_file_calving_statement,
                     ps_input_file_calving = s_input_file_calving,
                     ps_start_date = s_start_date,
                     ps_end_date = s_end_date,
                     ps_input_file_progeny_flp_statement = s_input_file_progeny_flp_statement,
                     ps_input_file_flp = s_input_file_flp,
                     ps_input_file_calf = s_input_file_calf,
                     ps_input_file_flp_carcass_matrix_statement = s_input_file_flp_carcass_matrix_statement,
                     ps_input_file_price_cow = s_input_file_price_cow,
                     ps_input_file_price_bull = s_input_file_price_bull,
                     ps_input_file_price_heifer = s_input_file_price_heifer,
                     ps_input_file_price_calf = s_input_file_price_calf,
                     ps_input_file_ped = s_input_file_ped,
                     pb_log = b_log)

Because we are did test-data-set, it is possible that some values of the INPUTXX.TXT files get NAs.

The input-files are now ready to execute ECOWEIGHT for beef cattle (EWBC). This need to be done separately and is not part of the package qp4ewc. As soon as we have the result file of ECOWEIGHT for beef cattle (in the vignette 2_Manual_Postprocess_EWBC some test-file are already available to allow to proceed to the post-processing part), we can run the post-processing part to extract economic weights and population means.

ps_sirebreed = s_sirebreed
ps_dambreed = s_dambreed
ps_prodsystew = s_prodsystem
ps_marketchannel = s_marketingchannel
ps_path_directory2create = s_path_directory2create
ps_input_file_literature = s_input_file_literature
ps_input_file_par = s_input_file_par
ps_input_file_35 = s_input_file_35
ps_input_file_36 = s_input_file_36
ps_input_file_testedbulls = s_input_file_testedbulls
ps_input_file_purchasedreplacementheifers = s_input_file_purchasedreplacementheifers
ps_input_file_calving_statement = s_input_file_calving_statement
ps_input_file_calving = s_input_file_calving
ps_start_date = s_start_date
ps_end_date = s_end_date
ps_input_file_progeny_flp_statement = s_input_file_progeny_flp_statement
ps_input_file_flp = s_input_file_flp
ps_input_file_calf = s_input_file_calf
ps_input_file_flp_carcass_matrix_statement = s_input_file_flp_carcass_matrix_statement
ps_input_file_price_cow = s_input_file_price_cow
ps_input_file_price_bull = s_input_file_price_bull
ps_input_file_price_heifer = s_input_file_price_heifer
ps_input_file_price_calf = s_input_file_price_calf
ps_input_file_ped = s_input_file_ped
pb_log = b_log


sknqualitasag/qp4ewc documentation built on Sept. 27, 2022, 3:31 p.m.