Description Usage Arguments Examples
Approximate Bayesian Computation (ABC) for System dynamic models
1 |
lf |
a "model_likefree" object with a compile model and data |
n_posterior |
number of posteriors to collect |
epsilon |
threshold for collecting |
target_acc |
target acceptance rate |
n_test |
number of simulations for testing threshold |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | library(odin2data)
## Example 1: model without warmup stage
test_data <- data.frame(
t = 1:5,
incidence = c(20, 49, 109, 184, 206) / 1000
)
### Load the model file
f <- system.file("models/SIR.txt", package = "odin2data")
test_m <- odin::odin(f, verbose=F)
### Generate a prior and set up it as a list
r_prior <- function() {
list(beta = runif(1, 1, 10), gamma = runif(1, .1, 1))
}
d_prior <- function(pars) {
dunif(pars$beta, 1, 10, log = T) + dunif(pars$gamma, .1, 1, log = T)
}
times = seq(0, 10, 0.2)
y0 <- c(995, 5, 0)
### Compile all elements as a simulation model
sim <- odin2data::compile_model(d_prior, r_prior, y0, ts_sim = times, m_sim = test_m)
### Compile the model with data
lf <- odin2data::compile_model_likefree(test_data, sim)
### Model fitting
post <- odin2data::fit_abc(lf, 100, target_acc = 0.2)
summary(post)
## Example 2: model with warmup stage
fn_pass_y0 <- function(ys) {
ys[nrow(ys), 2:4]
}
test_data <- data.frame(
t = 1:5,
incidence = rep(0.009580023, 5)
)
sim <- odin2data::compile_model(d_prior, r_prior, y0, ts_sim = times, m_sim = test_m,
m_wp = test_m, t_wp = 100, fn_pass_y0 = fn_pass_y0)
lf <- odin2data::compile_model_likefree(test_data, sim)
### Model fitting
post <- odin2data::fit_abc(lf, 100, target_acc = 0.2)
summary(post)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.