run_mc: Run a Monte Carlo simulation of a scenario

Description Usage Arguments Details Value

View source: R/run-mc.R

Description

Run a Monte Carlo simulation for a scenario given fixed distributions for one or more of the simulation parameters. At each iteration all of the parameters for which distributions were supplied will have values selected from their distributions, while other parameters will be held at the base values supplied.

Usage

1
2
3
4
5
6
7
8
run_mc(
  N,
  distparms,
  tmax,
  baseparms = list(),
  scenarioName = "HospCensus",
  rawsims = FALSE
)

Arguments

N

number of MC iterations to run

distparms

Parameter distributions. See details for how to specify a distribution.

tmax

End time for simulations

baseparms

Base parameters. Any parameters without distributions will be set to the values specified here (or to their default values, if unspecified.)

rawsims

Flag indicating whether to return the raw simulation output, or a summarized version.

Details

The distparams input should be a named list of functions that return samples from the indicated variables. For example, if we wanted to have hospFrac distributed as Beta(4, 98) and T0 distributed as Gamma(20, 4), we would write:

1
2
3
distparms <- list(
   T0 = function(N) {rgamma(N, 20, 4)},
   hospFrac = function(N) {rbeta(N, 4, 98)})

Helper functions such as genbeta provide an easy way to generate functions for common distributions. Using the helper functions you would write these distributions as:

1
2
3
distparams <- list(
    T0 = gengamma(20, 4),
    hospFrac = genbeta(4, 98))

Value

A list of data frames, one for each of the forecast variables returned by run_scenario. The form of the outputs depends on the setting of the rawsims input. If rawsims is FALSE, then we get back a data frame with ensemble mean, median, standard deviation, 5th, and 95th percentiles, reported by time. If rawsims is TRUE, then each output is a data frame with the output variable reported by time and MC iteration.


rplzzz/CovMitigation documentation built on June 7, 2021, 8:48 a.m.