| Title: | QMRA (quantitative microbial risk assessment) |
|---|---|
| Description: | QMRA for water supply systems. |
| Authors: | Michael Rustler [aut, cre] (ORCID: <https://orcid.org/0000-0003-0647-7726>), Hauke Sonnenberg [aut] (ORCID: <https://orcid.org/0000-0001-9134-2871>), Wolfgang Seis [ctb, rev] (ORCID: <https://orcid.org/0000-0002-7436-8575>), Ralf Junghanns [ctb], Kompetenzzentrum Wasser Berlin gGmbH [cph], AquaNES [fnd], DEMOWARE [fnd], Smart-Control [fnd] |
| Maintainer: | Michael Rustler <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.0 |
| Built: | 2026-05-21 08:35:55 UTC |
| Source: | https://github.com/KWB-R/kwb.qmra |
Based on exposure days per year and target infection risk per year the acceptable daily infection risk is backcalculated
backcalc_infectionRisk_perDay( target_infectionRisk_perYear = 1/10000, exposures_daysPerYear = 1:365 )backcalc_infectionRisk_perDay( target_infectionRisk_perYear = 1/10000, exposures_daysPerYear = 1:365 )
target_infectionRisk_perYear |
target infection risk per per year (default: 1/10000) |
exposures_daysPerYear |
exposure days per year (default: 1 to 365) |
acceptable daily infection risk for given exposures per year and target infection risk per year
Risk calculation: health
calc_health_risk( infectionRisk_perYear = 9.5 * 10^-4, infection_to_illness = 0.7, diseaseBurden_dalyPerCase = 1.5 * 10^-3, fraction_population = 1, target_dalyPerYearPerPerson = 1/1e+06 )calc_health_risk( infectionRisk_perYear = 9.5 * 10^-4, infection_to_illness = 0.7, diseaseBurden_dalyPerCase = 1.5 * 10^-3, fraction_population = 1, target_dalyPerYearPerPerson = 1/1e+06 )
infectionRisk_perYear |
as retrieved by calc_infection_risk()$events$infectionRisk_perYear or user defined input (default: 9.5 * 10 ^ - 4 infections/year) |
infection_to_illness |
probability of illness given infection (default: 0.7, i.e. 70 percent illness probability giving infection) |
diseaseBurden_dalyPerCase |
disabled adjusted life years per case. Value depends on multiple parameters such as illness type (default: 1.5*10 ^ -3) |
fraction_population |
fraction of population at risk of getting the illness (default: 1, i.e. 100 percent of population can possibly get the illness, worst-case assumption assuming no prior immunization!) |
target_dalyPerYearPerPerson |
target disabled adjusted life years (DALY) per person per year (default: 1/1000000 DALY per per person per year, WHO standard) |
data frame with input parameters and calculated health risk outputs
calc_infection_risk for infection risk input
Risk calculation: infection
calc_infection_risk( inflow_orgPerLitre = 10, treatment_logRemoval = 5.8, exposure_daysPerYear = 365, doseresponse_modelType = "dr.expo", waterConsumption_LitrePerDay = 1, target_infectionRisk_perYear = 1/10000, ... )calc_infection_risk( inflow_orgPerLitre = 10, treatment_logRemoval = 5.8, exposure_daysPerYear = 365, doseresponse_modelType = "dr.expo", waterConsumption_LitrePerDay = 1, target_infectionRisk_perYear = 1/10000, ... )
inflow_orgPerLitre |
concentration of microbiological parameter in inflow to water treatment plant (default: 10 Org/L) |
treatment_logRemoval |
reduction of microbiological concentration in water treatment plant (default: 5.8 log) |
exposure_daysPerYear |
exposure days per year (default: 365) |
doseresponse_modelType |
dose response model to be used: "dr.expo" for exponential or "dr.betapoisson" for beta-poisson model |
waterConsumption_LitrePerDay |
daily water consumption (default: 1 L/day) |
target_infectionRisk_perYear |
NOT IMPLEMENTED YET!!!! target infection risk per per year. Only used if one of the following input parameters (i.e. "inflow_orgPerLitre", "treatment_logRemoval", "exposure_daysPerYear", "waterConsumption_LitrePerDay") is not defined (default: 1/10000). |
... |
additional parameters used for dose response modelling. Depends on used dose-response model |
list with input parameters and calculated infection risk
dr.expo for exponential or
dr.betapoisson for beta-poisson dose-response model
JSON input configuration generated with R script (data-raw/config_json.R)
data(config_dummy_json)data(config_dummy_json)
A json list with all configuration parameters used by opencpu_simulate_risk, which are passed to simulate_risk
data("config_dummy_json") config_dummy_jsondata("config_dummy_json") config_dummy_json
JSON input configuration generated with R script (data-raw/config_json.R)
data(config_default_json)data(config_default_json)
A json list with all configuration parameters used by opencpu_simulate_risk, which are passed to simulate_risk
data("config_default_json") config_default_jsondata("config_default_json") config_default_json
Config: read configuration
config_read( confDir = system.file("extdata/configs/dummy", package = "kwb.qmra") )config_read( confDir = system.file("extdata/configs/dummy", package = "kwb.qmra") )
confDir |
directory to read configuration files (Default: system.file('extdata/configs/dummy', package = 'kwb.qmra')") |
stores configuration in R list structure
Config: create configuration
config_write(config, confName = "dummy", confDir = tempdir(), zipFiles = TRUE)config_write(config, confName = "dummy", confDir = tempdir(), zipFiles = TRUE)
config |
a configuration as retrieved by config_read() |
confName |
name of configuration |
confDir |
directory to save the configuration files (Default: tempdir()") |
zipFiles |
should also zipfile be created in folder confDir (default: TRUE) |
writes configuration in confDir subfolder defined in confName
Config: create dummy configuration
config_write_dummy( confDir = system.file("extdata/configs/dummy", package = "kwb.qmra") )config_write_dummy( confDir = system.file("extdata/configs/dummy", package = "kwb.qmra") )
confDir |
directory to save the dummy configuration files (Default: system.file('extdata/config', package = 'kwb.qmra')") |
writes dummy configuration in confDir
Create random distribution
create_random_distribution( type = "uniform", number_of_repeatings = 1, number_of_events = 365, value = 10, min = 10, max = 1000, percent_within_minmax = 0.9, min_zero = 0.01, log10_min = default_min(min, max, min_zero, f = log10), log10_max = default_max(max, min_zero * 10, f = log10), log10_mean = (log10_min + log10_max)/2, log10_sdev = abs((log10_max - log10_mean)/get_percentile(percent_within_minmax)), mean = (default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2, sdev = abs((default_max(max, 10 * min_zero) - mean)/get_percentile(percent_within_minmax)), meanlog = mean(log(default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2), sdlog = abs(sd(c(default_min(min, max, min_zero, f = log), default_max(max, 10 * min_zero, f = log)))), mode = (default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2, debug = TRUE )create_random_distribution( type = "uniform", number_of_repeatings = 1, number_of_events = 365, value = 10, min = 10, max = 1000, percent_within_minmax = 0.9, min_zero = 0.01, log10_min = default_min(min, max, min_zero, f = log10), log10_max = default_max(max, min_zero * 10, f = log10), log10_mean = (log10_min + log10_max)/2, log10_sdev = abs((log10_max - log10_mean)/get_percentile(percent_within_minmax)), mean = (default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2, sdev = abs((default_max(max, 10 * min_zero) - mean)/get_percentile(percent_within_minmax)), meanlog = mean(log(default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2), sdlog = abs(sd(c(default_min(min, max, min_zero, f = log), default_max(max, 10 * min_zero, f = log)))), mode = (default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2, debug = TRUE )
type |
"uniform" calls runif(), "log10_uniform" calls 10^runif(number_of_events, log10_min, log10_max), "triangle" calls EnvStats::rtri(), "lognorm" calls rlnorm(), "norm" calls rnorm() and "log10_norm" calls 10^rnorm(number_of_events, mean = log10_mean, sdev = log10_sdev), (default: "uniform") |
number_of_repeatings |
how often should the random distribution with the same parameters be generated (default: 1) |
number_of_events |
number of events |
value |
constant value (no random number), gets repeated number_of_events times (if 'type' = 'value') |
min |
minimum value (default: 10), only used if 'type' is "runif" or "triangle" |
max |
maximum value (default: 1000), only used if 'type' is "runif" or "triangle" |
percent_within_minmax |
percent of data point within min/max (default: 0.9 i.e. 90 percent |
min_zero |
only used if 'type' is "log10_uniform" or
"log10_norm", "norm" or "lognorm" and "min" value equal zero.
In this case the zero is replaced by this value (default: 0.01), see also
|
log10_min |
minimum value (default: default_min(min, max, min_zero, f = log10)), only used if 'type' is "log10_uniform" or "log10_norm" |
log10_max |
maximum value (default: ifelse(max > 0, log10(max), log10_zero_threshold), only used if 'type' is "log10_uniform" or "log10_norm" |
log10_mean |
mean value (default: (log10_min + log10_max)/2), only used if 'type' is "log10_norm" |
log10_sdev |
standard deviation (default: abs((log10_max- log10_mean) / get_percentile(0.95)), only used if 'type' is "log10_norm" |
mean |
mean value (default: (default_min(min, max, min_zero) / default_max(max, 10*min_zero)) / 2), only used if 'type' is "norm" |
sdev |
standard deviation (default: abs((default_max(max, 10*min_zero) - mean) / get_percentile(0.95))), only used if 'type' is "norm" |
meanlog |
log mean value (default: mean(log((min + max) / 2))), only used if 'type' is "lognorm" |
sdlog |
standard deviation (default: abs(sd(c(default_min(min, max, min_zero, f = log)))) ), only used if 'type' is "lognorm" |
mode |
(default: default_min(min, max, min_zero) + default_max(max, 10 * min_zero) / 2), only used if 'type' is "triangle" |
debug |
print debug information (default: TRUE) |
list with parameters of user defined random distribution and corresponding values
for random triangle see rtri, for default
min/max see default_min, default_max and
get_percentile
Default Max
default_max(org_max, new_max, f = c)default_max(org_max, new_max, f = c)
org_max |
original maximum value |
new_max |
new maximum value for replacement |
f |
function apply on "org_max" to transform to the correct dimension (e.g. "log" in case of "lognorm" or "log10" in case of log10_norm) (default: c()) |
default_max(org_max = 2, new_max = 0.01, f = log10) default_max(org_max = 0, new_max = 0.01, f = log10) default_max(org_max = 2, new_max = 0.01, f = log) default_max(org_max = 0, new_max = 0.01, f = log)default_max(org_max = 2, new_max = 0.01, f = log10) default_max(org_max = 0, new_max = 0.01, f = log10) default_max(org_max = 2, new_max = 0.01, f = log) default_max(org_max = 0, new_max = 0.01, f = log)
Default Min
default_min(org_min, org_max, new_min, f = c)default_min(org_min, org_max, new_min, f = c)
org_min |
original minimum value |
org_max |
original maximum value |
new_min |
new minimum value for replacement |
f |
function apply on org_min and new_min to transform to the correct dimension (e.g. "log" in case of "lognorm" or "log10" in case of log10_norm), (default: c()) |
default_min(org_min = 2, org_max = 100, new_min = 0.01, f = log10) default_min(org_min = 0, org_max = 100, new_min = 0.01, f = log10) default_min(org_min = 2, org_max = 100, new_min = 0.01, f = log) default_min(org_min = 0, org_max = 100, new_min = 0.01, f = log)default_min(org_min = 2, org_max = 100, new_min = 0.01, f = log10) default_min(org_min = 0, org_max = 100, new_min = 0.01, f = log10) default_min(org_min = 2, org_max = 100, new_min = 0.01, f = log) default_min(org_min = 0, org_max = 100, new_min = 0.01, f = log)
Helper function: distributon repeater
distribution_repeater( number_of_repeatings = 10, number_of_events = 365, func, ... )distribution_repeater( number_of_repeatings = 10, number_of_events = 365, func, ... )
number_of_repeatings |
how often should the random distribution with the same parameters be generated (default: 1) |
number_of_events |
number of events |
func |
distribution function to be repeated (e.g. runif, rlnorm, rnorm) |
... |
further parameters passed to func |
data.frame with columns repeatID, eventID and values
distribution_repeater( number_of_repeatings = 2, number_of_events = 10, func = runif, min = 1, max = 10 )distribution_repeater( number_of_repeatings = 2, number_of_events = 10, func = runif, min = 1, max = 10 )
Dose-response model: beta-poisson
dr.betapoisson( dose = sfsmisc::lseq(from = 1, to = 10^10, length = 1000), alpha = 0.328, N50 = 5430 )dr.betapoisson( dose = sfsmisc::lseq(from = 1, to = 10^10, length = 1000), alpha = 0.328, N50 = 5430 )
dose |
vector of dose data (default:
|
alpha |
alpha (default: 3.28E-01) |
N50 |
N50 (default: 5.43E+03) |
tibble
Download dose-response model database from QMRAwiki
dr.db_download(fromInternet = FALSE)dr.db_download(fromInternet = FALSE)
fromInternet |
download from internet (default: FALSE), if FALSE import from local copy |
tibble for different microbial parameters
http://qmrawiki.canr.msu.edu/index.php?title=Table_of_Recommended_Best-Fit_Parameters
Generate table with different doses for dr.db_download()
dr.db_model( dr.db = dr.db_download(), dose = sfsmisc::lseq(from = 1, to = 10^10, length = 1000) )dr.db_model( dr.db = dr.db_download(), dose = sfsmisc::lseq(from = 1, to = 10^10, length = 1000) )
dr.db |
as retrieved by dr.db_download(), default: dr.db_download() |
dose |
vector of dose data (default:
|
tibble
Dose-response model: exponential
dr.expo(dose = sfsmisc::lseq(from = 1, to = 10^10, length = 1000), k = 0.572)dr.expo(dose = sfsmisc::lseq(from = 1, to = 10^10, length = 1000), k = 0.572)
dose |
vector of dose data (default:
|
k |
k-value (default: 5.72E-01) |
tibble
Create random distribution based on configuration file
generate_random_values( config, number_of_repeatings = 1, number_of_events, debug = TRUE )generate_random_values( config, number_of_repeatings = 1, number_of_events, debug = TRUE )
config |
as retrieved by config_read() |
number_of_repeatings |
how often should the random distribution with the same parameters be generated (default: 1) |
number_of_events |
number of events |
debug |
print debug information (default: TRUE) |
list random distributions based on configuration file
Helper function: get percentile
get_percentile(percent_within_minmax = 0.9)get_percentile(percent_within_minmax = 0.9)
percent_within_minmax |
percent of data point within min/max (default: 0.9 i.e. 90 percent) |
get_percentile(0.9) get_percentile(0.95)get_percentile(0.9) get_percentile(0.95)
OpenCPU wrapper: import config from CSV and convert to JSON
opencpu_config_read( confDir = system.file("extdata/configs/dummy", package = "kwb.qmra") )opencpu_config_read( confDir = system.file("extdata/configs/dummy", package = "kwb.qmra") )
confDir |
directory to read configuration files (Default: system.file('extdata/configs/dummy', package = 'kwb.qmra')") |
stores configuration in JSON format
### Example json config file config_json <- kwb.qmra::opencpu_config_read() head(config_json)### Example json config file config_json <- kwb.qmra::opencpu_config_read() head(config_json)
OpenCPU wrapper: run risk calculation and convert results to JSON format
opencpu_simulate_risk( config = config_read(), usePoisson = TRUE, debug = TRUE, lean = TRUE )opencpu_simulate_risk( config = config_read(), usePoisson = TRUE, debug = TRUE, lean = TRUE )
config |
config object as retrieved by |
usePoisson |
should a poisson proccess (see function dose_perEvent()) be used to calculate the dose_perEvent (TRUE) or just the exposure_perEvent column (FALSE), (default: TRUE) |
debug |
print debug information (default: TRUE) |
lean |
if |
JSON list with parameters of user defined random distribution and corresponding values
### Example simulation run ## Read from JSON config_json <- kwb.qmra::opencpu_config_read() config <- jsonlite::fromJSON(config_json) ## Optionally directly import from CSVs # config <- kwb.qmra::config_read() risk <- kwb.qmra::opencpu_simulate_risk(config) risk_json <- jsonlite::toJSON(risk, pretty = TRUE) writeLines(text = risk_json, "risk.json")### Example simulation run ## Read from JSON config_json <- kwb.qmra::opencpu_config_read() config <- jsonlite::fromJSON(config_json) ## Optionally directly import from CSVs # config <- kwb.qmra::config_read() risk <- kwb.qmra::opencpu_simulate_risk(config) risk_json <- jsonlite::toJSON(risk, pretty = TRUE) writeLines(text = risk_json, "risk.json")
plotting
plot_doseresponse(risk)plot_doseresponse(risk)
risk |
list as retrieved by simulate_risk() |
ggplot for reduction
plotting
plot_effluent(risk)plot_effluent(risk)
risk |
list as retrieved by simulate_risk() |
ggplot for effluent
plotting
plot_event_dalys(risk)plot_event_dalys(risk)
risk |
list as retrieved by simulate_risk() |
ggplot for dalys_per_event
plotting
plot_event_dose(risk)plot_event_dose(risk)
risk |
list as retrieved by simulate_risk() |
ggplot for dose per event
plotting
plot_event_exposure(risk)plot_event_exposure(risk)
risk |
list as retrieved by simulate_risk() |
ggplot for exposure per event
plotting
plot_event_illnessProb(risk)plot_event_illnessProb(risk)
risk |
list as retrieved by simulate_risk() |
ggplot for illness probability
plotting
plot_event_infectionProb(risk)plot_event_infectionProb(risk)
risk |
list as retrieved by simulate_risk() |
ggplot for infection probability
plotting volume
plot_event_volume(risk)plot_event_volume(risk)
risk |
list as retrieved by simulate_risk() |
ggplot for volume per event
plotting
plot_inflow(risk)plot_inflow(risk)
risk |
list as retrieved by simulate_risk |
ggplot for inflow
plotting
plot_reduction(risk)plot_reduction(risk)
risk |
list as retrieved by simulate_risk() |
ggplot for reduction
plotting
plot_total_dalys(risk, labelling = FALSE, title = "", tolerance = 1e-06)plot_total_dalys(risk, labelling = FALSE, title = "", tolerance = 1e-06)
risk |
list as retrieved by simulate_risk() |
labelling |
if TRUE labels with absolute DALYs will be plotted (default: FALSE) |
title |
title for plot (default: "") |
tolerance |
accecptable tolerance level of risk (default: 1E-6) |
ggplot for total DALYs
plotting
plot_total_illnessProb(risk, tolerance = 1e-04)plot_total_illnessProb(risk, tolerance = 1e-04)
risk |
list as retrieved by simulate_risk() |
tolerance |
accecptable tolerance level of risk (default: 1E-4) |
ggplot for total illness probability
plotting
plot_total_infectionProb(risk, tolerance = 1e-04)plot_total_infectionProb(risk, tolerance = 1e-04)
risk |
list as retrieved by simulate_risk() |
tolerance |
accecptable tolerance level of risk (default: 1E-4) |
ggplot for total infection probability
Helper function: poisson distribution based on exposure per event
poisson_dose(exposure_perEvent)poisson_dose(exposure_perEvent)
exposure_perEvent |
exposed organisms per event |
dose per event based on poisson process
Create report (not working for "shiny" reports)
report_workflow( confDirs = system.file("extdata/configs/", package = "kwb.qmra"), report_template_dir = system.file("extdata/report", package = "kwb.qmra"), report_template_name = "workflow.Rmd", report_output_dir = NULL, openReport = TRUE )report_workflow( confDirs = system.file("extdata/configs/", package = "kwb.qmra"), report_template_dir = system.file("extdata/report", package = "kwb.qmra"), report_template_name = "workflow.Rmd", report_output_dir = NULL, openReport = TRUE )
confDirs |
directory containing subdirectory/ies of QMRA configurations default: system.file("extdata/configs/", package = "kwb.qmra") |
report_template_dir |
report template directory (default: system.file("extdata/report", package = "kwb.qmra")) |
report_template_name |
default: "workflow.Rmd" |
report_output_dir |
directory where report should be saved, if NULL report_template_dir is used (default: NULL) |
openReport |
open report in browser default: TRUE |
generate html report
JSON risk result object generated with R script (data-raw/risk_json.R)
data(risk_dummy_json)data(risk_dummy_json)
A json list with all risk results generated by opencpu_simulate_risk, using the dataset 'config_dummy_json'
data("risk_dummy_json") risk <- jsonlite::fromJSON(risk_dummy_json) ### only show "stats" elements (skip "events" and "total" due to much data) risk_stats <- list(stats_total = risk$stats_total, stats_logremoval = risk$stats_logremoval) jsonlite::toJSON(risk_stats, pretty = TRUE)data("risk_dummy_json") risk <- jsonlite::fromJSON(risk_dummy_json) ### only show "stats" elements (skip "events" and "total" due to much data) risk_stats <- list(stats_total = risk$stats_total, stats_logremoval = risk$stats_logremoval) jsonlite::toJSON(risk_stats, pretty = TRUE)
Run shiny app
run_app( appDir = system.file("extdata/shiny", package = "kwb.qmra"), launch.browser = TRUE, ... )run_app( appDir = system.file("extdata/shiny", package = "kwb.qmra"), launch.browser = TRUE, ... )
appDir |
directory of shiny app (default: system.file("extdata/shiny", package = "kwb.qmra")) |
launch.browser |
If true, the system's default web browser will be launched automatically after the app is started. Defaults to true in interactive sessions only. This value of this parameter can also be a function to call with the application's URL. |
... |
additional parameters passed to shiny::runApp |
Simulate: exposure
simulate_exposure(config, debug = TRUE)simulate_exposure(config, debug = TRUE)
config |
as retrieved by config_read() |
debug |
print debug information (default: TRUE) |
list with parameters of user defined exposure scenario (number of events and volumes per Event)
Simulate: inflow
simulate_inflow(config, debug = TRUE, lean = FALSE)simulate_inflow(config, debug = TRUE, lean = FALSE)
config |
as retrieved by config_read() |
debug |
print debug information (default: TRUE) |
lean |
if |
list with parameters of user defined random distribution and corresponding values
Simulate: risk
simulate_risk(config, usePoisson = TRUE, debug = TRUE, lean = FALSE)simulate_risk(config, usePoisson = TRUE, debug = TRUE, lean = FALSE)
config |
as retrieved by config_read() |
usePoisson |
should a poisson proccess (see function dose_perEvent()) be used to calculate the dose_perEvent (TRUE) or just the exposure_perEvent column (FALSE), (default: TRUE) |
debug |
print debug information (default: TRUE) |
lean |
if |
list with parameters of user defined random distribution and corresponding values
Simulate: treatment
simulate_treatment(config, wide = FALSE, debug = TRUE, lean = FALSE)simulate_treatment(config, wide = FALSE, debug = TRUE, lean = FALSE)
config |
as retrieved by config_read() |
wide |
if TRUE results will be converted to wide format (default: FALSE) |
debug |
print debug information (default: TRUE) |
lean |
lean (default: FALSE) |
list with parameters of user defined random distribution and corresponding values
Treatment: get WHO reductions
who_getTreatment()who_getTreatment()
list with $untidy and $tidy data frames
http://apps.who.int/iris/bitstream/10665/44584/1/9789241548151_eng.pdf#page=162