ABCRef | R Documentation |
Produces reference table of simulated outcomes for use in various Approximate Bayesian Computation (ABC) algorithms.
ABCRef( npart, priors, pars, func, sumNames, parallel = FALSE, mc.cores = NA, ... )
npart |
The number of particles (must be a positive integer). |
priors |
A |
pars |
A named vector or matrix of parameters to use for the simulations. If |
func |
Function that runs the simulator. The first argument must be |
sumNames |
A |
parallel |
A |
mc.cores |
Number of cores to use if using parallel processing. |
... |
Extra arguments to be passed to |
Runs simulations for a large number of particles, either pre-specified or
sampled from the a set of given prior distributions. Returns a table of summary
statistics for each particle. Useful for deciding on initial tolerances during an
ABCSMC
run, or for producing a reference table to use in e.g. the
ABC with Random Forests approach of Raynal et al. (2017).
An data.frame
object with npart
rows, where the first p
columns correspond to
the proposed parameters, and the remaining columns correspond to the simulated outputs.
Raynal, L, Marin J-M, Pudlo P, Ribatet M, Robert CP and Estoup A. (2017) <ArXiv:1605.05537>
## set up SIR simulation model transitions <- c( "S -> beta * S * I -> I", "I -> gamma * I -> R" ) compartments <- c("S", "I", "R") pars <- c("beta", "gamma") model <- mparseRcpp( transitions = transitions, compartments = compartments, pars = pars ) model <- compileRcpp(model) ## generate function to run simulators ## and produce final epidemic size and time ## summary statistics simRef <- function(pars, model) { ## run model over a 100 day period with ## one initial infective in a population ## of 120 individuals sims <- model(pars, 0, 100, c(119, 1, 0)) ## return vector of summary statistics c(finaltime = sims[2], finalsize = sims[5]) } ## set priors priors <- data.frame( parnames = c("beta", "gamma"), dist = rep("gamma", 2), stringsAsFactors = FALSE ) priors$p1 <- c(10, 10) priors$p2 <- c(10^4, 10^2) ## produce reference table by sampling from priors ## (add additional arguments to 'func' at the end) refTable <- ABCRef( npart = 100, priors = priors, func = simRef, sumNames = c("finaltime", "finalsize"), model = model ) refTable
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.