OpenCPU wrapper: run risk calculation and convert results to JSON format
Source:R/opencpu.R
opencpu_simulate_risk.Rd
OpenCPU wrapper: run risk calculation and convert results to JSON format
Usage
opencpu_simulate_risk(
config = config_read(),
usePoisson = TRUE,
debug = TRUE,
lean = TRUE
)
Arguments
- config
config object as retrieved by
kwb.qmra::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
TRUE
, a "lean" version of this function is called, seekwb.qmra:::simulate_risk_lean
, (default: TRUE)
Examples
### Example simulation run
## Read from JSON
config_json <- kwb.qmra::opencpu_config_read()
#> Rows: 3 Columns: 10
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (2): name, type
#> dbl (5): value, min, max, mode, mean
#> lgl (3): sd, meanlog, sdlog
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> Rows: 37 Columns: 13
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (3): PathogenName, PathogenGroup, type
#> dbl (4): PathogenID, simulate, min, max
#> lgl (6): value, mode, mean, sd, meanlog, sdlog
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> Rows: 38 Columns: 13
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (4): TreatmentName, TreatmentGroup, PathogenGroup, type
#> dbl (3): TreatmentID, min, max
#> lgl (6): value, mode, mean, sd, meanlog, sdlog
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> Rows: 5 Columns: 4
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (2): TreatmentSchemeName, TreatmentName
#> dbl (2): TreatmentSchemeID, TreatmentID
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> Rows: 37 Columns: 13
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (9): PathogenName, PathogenGroup, Best fit model*, Host type, Dose units...
#> dbl (4): PathogenID, k, alpha, N50
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> Rows: 37 Columns: 4
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): PathogenName
#> dbl (3): PathogenID, infection_to_illness, dalys_per_case
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
config <- jsonlite::fromJSON(config_json)
## Optionally directly import from CSVs
# config <- kwb.qmra::config_read()
risk <- kwb.qmra::opencpu_simulate_risk(config)
#>
#> # STEP 0: BASIC CONFIGURATION
#>
#> Simulated 3 pathogen(s): Campylobacter jejuni and Campylobacter coli, Rotavirus, Giardia duodenalis
#> Number of random distribution repeatings: 10
#> Number of exposure events: 365
#>
#> # STEP 1: INFLOW
#>
#> Simulated pathogen: Campylobacter jejuni and Campylobacter coli
#> Create 10 random distribution(s): uniform (n: 365, min: 10.000000, max: 10000.000000)
#> Warning: row names were found from a short variable and have been discarded
#> Simulated pathogen: Rotavirus
#> Create 10 random distribution(s): uniform (n: 365, min: 10.000000, max: 10000.000000)
#> Warning: row names were found from a short variable and have been discarded
#> Simulated pathogen: Giardia duodenalis
#> Create 10 random distribution(s): uniform (n: 365, min: 10.000000, max: 10000.000000)
#> Warning: row names were found from a short variable and have been discarded
#> Providing inflow events ... ok. (0.00s)
#>
#> # STEP 2: TREATMENT SCHEMES
#>
#> Create 10 random distribution(s): uniform (n: 365, min: 0.200000, max: 2.000000)
#> Create 10 random distribution(s): uniform (n: 365, min: 1.000000, max: 2.000000)
#> Create 10 random distribution(s): uniform (n: 365, min: 0.100000, max: 3.400000)
#> Create 10 random distribution(s): uniform (n: 365, min: 0.200000, max: 4.400000)
#> Create 10 random distribution(s): uniform (n: 365, min: 0.400000, max: 3.300000)
#> Create 10 random distribution(s): uniform (n: 365, min: 0.000000, max: 3.500000)
#> Create 10 random distribution(s): uniform (n: 365, min: 2.000000, max: 6.000000)
#> Create 10 random distribution(s): uniform (n: 365, min: 0.300000, max: 5.000000)
#> Create 10 random distribution(s): uniform (n: 365, min: 0.250000, max: 4.000000)
#> Create 10 random distribution(s): uniform (n: 365, min: 2.000000, max: 6.000000)
#> Create 10 random distribution(s): uniform (n: 365, min: 1.000000, max: 2.000000)
#> Create 10 random distribution(s): uniform (n: 365, min: 2.100000, max: 8.300000)
#> Create 10 random distribution(s): uniform (n: 365, min: 4.000000, max: 4.000000)
#> Create 10 random distribution(s): uniform (n: 365, min: 4.000000, max: 4.000000)
#> Create 10 random distribution(s): uniform (n: 365, min: 4.000000, max: 4.000000)
#>
#> # STEP 3: EXPOSURE
#>
#> Simulated exposure: volume per event
#> Create 10 random distribution(s): triangle (n: 365, min: 0.500000, max: 3.000000, mode = 1.500000)
#>
#> # STEP 4: DOSE RESPONSE
#>
#>
#> # STEP 5: HEALTH
#>
risk_json <- jsonlite::toJSON(risk, pretty = TRUE)
writeLines(text = risk_json, "risk.json")