#is_travis <- identical(Sys.getenv("TRAVIS"), "true")
#knitr::opts_chunk$set(eval = TRUE)

How to work with the kwb.qmra package in R(Studio) is described in the following chapters

Once the R package is installed it can be loaded with the following command in R(Studio):

library(kwb.qmra)

1.1 Download 'Old Ford' configuration

The folder with the csv configuration files for the Old Ford use case are
located here and can be downloaded with the following command from ZENODO:

temp <- tempdir()
url <- "https://zenodo.org/record/159527/files/QMRA_OldFord.zip"
t_path <- file.path(temp, basename(url))
download.file(url, dest= t_path, mode="wb") 
unzip(t_path, exdir = temp)

scenarios_dir <- file.path(temp, "scenarios")

cat(sprintf("### Available scenarios:\n%s",
            paste(dir(scenarios_dir), collapse = "\n")))

In total there are three different scenarios available. To the select the first one (r dir(scenarios_dir)[1]), you need to run the following command:

#### DEFINE DIRECTORY ################
confDir <- dir(scenarios_dir,full.names = TRUE)[1]
confDir

1.2 Import configuration into R

All csv files with the input data for the hypothetical u dummy (as shown above) are imported into R with the following function:

#### LOAD ############################
config <- config_read(confDir) 

2 Check input data

The QMRA will be performed - in case the user does not modify them in R - based on the imported input data, which are defined in the configuration folder.

In case of the dummy configuration, a Monte carlo simulation (n = 10) for 365 exposure events per year for three pathogens and the following input parameters will be performed:

simulated <- config$inflow[config$inflow$simulate == 1, 1:3]
knitr::kable(simulated,caption = "Simulated pathogens for QMRA (defined in: 'inflow.csv' with 
             simulated = 1):")

knitr::kable(config$inflow[config$inflow$PathogenName %in% simulated$PathogenName,
 c("PathogenID","PathogenName", "PathogenGroup", "type", "min", "max", 
   "ReferenceName","ReferenceLink")], 
 caption = "Inflow concentrations (defined in: 'inflow.csv') for pathogens used for QMRA:")

knitr::kable(config$treatment$schemes,
 caption = "Treatment schemes (defined in: 'treatment_schemes.csv') used for QMRA:")

knitr::kable(config$treatment$processes[config$treatment$processes$TreatmentID %in% config$treatment$schemes$TreatmentID,
c("TreatmentID","TreatmentName", "TreatmentGroup", "PathogenGroup", "type", "min", "max",
  "ReferenceName","ReferenceLink")], 
 caption = "Treatment processes (defined in: 'treatment_proecesses.csv') and assumed log-reductions used for QMRA (from [DEMOWARE, 2015](http://http://demoware.eu/en/results/deliverables/deliverable-d3-1-appropiate-and-user-friendly-methodologies-for-ra_lca_wfp.pdf#page=18)):")


exposure <- list(number_of_repeatings = as.numeric(config$exposure[config$exposure$name == "number_of_repeatings","value"]),
                 number_of_exposures =  as.numeric(config$exposure[config$exposure$name == "number_of_exposures","value"]),
                 volume_perEvent = config$exposure[config$exposure$name == "volume_perEvent",]
                 )


knitr::kable(exposure$volume_perEvent[,c("name", "type", "value")],
 caption = "Ingested volume per event (defined in: row 3 'volume_perEvent' in 'exposure.csv') (source: own assumption)):")


volume_per_event <- kwb.qmra::create_random_distribution(type = exposure$volume_perEvent$type, 
                                     number_of_repeatings = exposure$number_of_repeatings,
                                     number_of_events = exposure$number_of_exposures, 
                                     value = exposure$volume_perEvent$value, 
                                     min = exposure$volume_perEvent$min, 
                                     max = exposure$volume_perEvent$max, 
                                     mode = exposure$volume_perEvent$mode, 
                                     mean = exposure$volume_perEvent$mean,debug = FALSE)


knitr::kable(config$doseresponse[config$doseresponse$PathogenName %in% simulated$PathogenName,], 
              caption = "Dose-response models (defined in: 'doseresponse.csv') used for QMRA (from [QMRAwiki](http://qmrawiki.canr.msu.edu/index.php/Quantitative_Microbial_Risk_Assessment_(QMRA)_Wiki)):")

knitr::kable(config$health[config$health$PathogenName %in% simulated$PathogenName,], 
              caption = "Health parameters (defined in: 'health.csv') for simulated pathogens (from [WHO, 2011](http://apps.who.int/iris/bitstream/10665/44584/1/9789241548151_eng.pdf#page=132)):")

4 Run risk calculation

Subsequently the risk calculation can be performed in R(Studio) by executing the following code, which uses the config that was imported and inspected above:

risk <- kwb.qmra::simulate_risk(config)

All (input & output) data will be saved in the resulting R object risk which an be easily inspected by the user, e.g.:

Input data

str(risk$input, 1)

Output data

str(risk$output, 1)

Thus the user has access to all results.

5 Visualise results

Finally the results of the QMRA can be visualised for each system component as shown below:

5.1 Inflow

kwb.qmra::plot_inflow(risk)

5.2 Treatment

kwb.qmra::plot_reduction(risk)

5.3 Effluent

kwb.qmra::plot_effluent(risk)

5.4 Exposure

kwb.qmra::plot_event_dose(risk)
kwb.qmra::plot_event_volume(risk)

5.5 Health results

5.5.1 Per event

kwb.qmra::plot_event_infectionProb(risk)
kwb.qmra::plot_event_illnessProb(risk)
kwb.qmra::plot_event_dalys(risk)

5.5.2 Total

kwb.qmra::plot_total_infectionProb(risk)
kwb.qmra::plot_total_illnessProb(risk)
kwb.qmra::plot_total_dalys(risk)

In addition tables with summary statistics, e.g. for the total risk can be generated easily as shown below:

knitr::kable(risk$output$total[risk$output$total$repeatID==1, ], 
             caption = "Total risk (for first repeat of random generation)")

6 Export results

E.g. Write reports for all configurations in a folder e.g. /scenarios (here: r scenarios_dir):

kwb.qmra::report_workflow(confDirs = scenarios_dir)


KWB-R/kwb.qmra documentation built on June 15, 2021, 11:14 p.m.