knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
A thorough introduction to Incremental Mixture Approximate Bayesian Computation (IMABC) method can be found in @rutter_microsimulation_2019. Here we will walk through the code found in @imabc_pkg.
library(imabc)
For a more detailed explanation of how the priors functions work, see the vignette("priors")
priors <- define_priors( # x1: Uniform Prior (from base R) x1 = add_prior( dist_base_name = "unif", min = 0.2, max = 0.9 ), # x2: Truncated Normal (from truncnorm package) add_prior( parameter_name = "x2", density_fn = "dtruncnorm", mean = 0.5, sd = 0.05, a = 0.4, b = 0.8, # a = min and b = max min = 0.4, max = 0.8 # User must specify both in truncnorm ), # V3: Fixed parameter (not calibrated) add_prior(0.5) )
A more detailed description will be available in the near future at vignette("targets")
targets <- define_targets( # G1: Grouped targets include T1 and T2 G1 = group_targets( T1 = add_target( target = 1.5, starting_range = c(1.0, 2.0), stopping_range = c(1.49, 1.51) ), add_target( target_name = "T2", target = 0.5, starting_range = c(0.2, 0.9), stopping_range = c(0.49, 0.51) ) ) )
A more detailed description will be available in the near future at vignette("target_functions")
fn1 <- function(x1, x2) { x1 + x2 + sample(c(-1, 1), 1)*rnorm(1, 0, 0.1) } fn2 <- function(x1, x2) { x1 * x2 + sample(c(-1, 1), 1)*rnorm(1, 0, 0.1) } fn <- function(x1, x2) { res <- c() res["T2"] <- fn1(x1, x2) res["T1"] <- fn2(x1, x2) return(res) } target_fun <- define_target_function( targets, priors, FUN = fn, use_seed = FALSE )
The primary function is imabc(). The inputs and their descriptions are as follows:
calibration_results <- imabc( priors = priors, targets = targets_nogroup, target_fun = target_fun, seed = 54321, N_start = 2000, N_centers = 2, Center_n = 500, N_cov_points = 50, N_post = 100 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.