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)
The folder with the csv configuration files for a hypothetical use case is located here:
#### DEFINE DIRECTORY ################ confDir <- system.file("extdata/configs/dummy", package = "kwb.qmra") confDir
The following screenshot shows the required configuration files located in
confDir
(here: r confDir
):
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)
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")], 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")], caption = "Treatment processes (defined in: 'treatment_proecesses.csv') and assumed log-reductions used for QMRA (from [WHO, 2011](http://apps.who.int/iris/bitstream/10665/44584/1/9789241548151_eng.pdf#page=162)):") 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", "min", "max", "mode")], 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/old/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)):")
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)
Output data
str(risk$output)
Thus the user has access to all
Finally the results of the QMRA can be visualised for each system component as shown below:
kwb.qmra::plot_inflow(risk)
kwb.qmra::plot_reduction(risk)
kwb.qmra::plot_effluent(risk)
kwb.qmra::plot_event_dose(risk)
kwb.qmra::plot_event_volume(risk)
kwb.qmra::plot_event_infectionProb(risk)
kwb.qmra::plot_event_illnessProb(risk)
kwb.qmra::plot_event_dalys(risk)
kwb.qmra::plot_total_infectionProb(risk)
kwb.qmra::plot_total_illnessProb(risk)
kwb.qmra::plot_total_dalys(risk)
In addtion 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)")
E.g. Write reports for all configurations in package subfolder extdata/configs/
(here:
r system.file("extdata/configs/", package = "kwb.qmra")
):
confDirs <- system.file("extdata/configs/", package = "kwb.qmra") kwb.qmra::report_workflow(confDirs)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.