Part 3b: Likelihood-Free Markhov Chain Monte Carlo (LFMCMC)
Often in network simulations, we don’t know the model parameters that will produce an accurate model. Likelihood-Free Markhov chain Monte Carlo (LFMCMC) runs a base model over a specified number of simulations, each time modifying the parameters used by the model to bring the model results closer to the observed data we’re trying to model. In epiworldR
, the LFMCMC()
function creates an LFMCMC object that can perform this calibration. In this part of the workshop, we’ll walk through an example.
Example Scenario: Calibrate a COVID-19 SIR Model
Create a True COVID-19 Model
Assume that the true parameters of COVID-19 for a given population of 2,000 agents are as follows:
- Initial Disease Prevalence: 0.01
- Transmission Rate: 0.1
- Recovery Rate: 1/7
We would represent that disease in epiworldR
using the ModelSIR()
and agents_smallworld()
functions.
Running the true model for 50 days results in the following final distribution of agents across the three SIR states:
Code
Susceptible Infected Recovered
1865 0 135
For the rest of the example, we’ll assume we don’t know the true disease parameters, but that we have the observed_data
(e.g., from public health records). We’ll use LFMCMC to recover the transmission and recovery rates from the true model and use the observed_data
to check how close each simulation is to the true values.
Setup LFMCMC
Frist, set up a new SIR model for LFMCMC to use. Since we don’t know the true parameters, we’ll guess. It won’t matter what we choose for the recovery and transmission rates, as we’ll define the initial parameters for LFMCMC before running it.
Next, define the LFMCMC functions (described in more detail here). Since we are trying to recover the Transmission and Recovery rates, our simulation function will test a new set of those two parameters during each iteration of LFMCMC.
Code
# Define the simulation function
simulation_fun <- function(params, lfmcmc_obj) {
set_param(model_sir, "Recovery rate", params[1])
set_param(model_sir, "Transmission rate", params[2])
run(model_sir, ndays = 50)
res <- get_today_total(model_sir)
return(res)
}
# Define the summary function
summary_fun <- function(data, lfmcmc_obj) {
return(data)
}
# Define the proposal function
proposal_fun <- function(old_params, lfmcmc_obj) {
res <- plogis(qlogis(old_params) + rnorm(length(old_params), sd = .1))
return(res)
}
# Define the kernel function
kernel_fun <- function(
simulated_stats, observed_stats, epsilon, lfmcmc_obj
) {
diff <- ((simulated_stats - observed_stats)^2)^epsilon
dnorm(sqrt(sum(diff)))
}
Finally, use the LFMCMC()
function to create the LFMCMC object, add the LFMCMC functions defined above, and pass in the observed COVID-19 data.
Run LFMCMC
Before running LFMCMC, we need to pick the initial parameters (recovery rate = 0.3, transmission rate = 0.3) and choose an epsilon for the kernel function (epsilon = 1.0
). We’ll run LFMCMC for 2000 iterations or samples (n_samples = 2000
).
Check Results
Print the LFMCMC object with a burn-in period of 1,500.
Code
___________________________________________
LIKELIHOOD-FREE MARKOV CHAIN MONTE CARLO
N Samples (total) : 2000
N Samples (after burn-in period) : 500
Elapsed t : 1.00s
Parameters:
-Recovery rate : 0.14 [ 0.13, 0.15] (initial : 0.30)
-Transmission rate : 0.09 [ 0.09, 0.10] (initial : 0.30)
Statistics:
-Susceptible : 1865.49 [ 1864.00, 1866.00] (Observed: 1865.00)
-Infected : 0.00 [ 0.00, 0.00] (Observed: 0.00)
-Recovered : 134.51 [ 134.00, 136.00] (Observed: 135.00)
___________________________________________
Out LFMCMC calibration was successful! The average LFMCMC Recovery rate was 0.14 (true value was 1/7 or 0.1428) and the average Transmission rate was 0.09 (true value was 0.1). The average number of Susceptible agents at Day 50 was 1,865.49 (observed value was 1865) and the average number of Recovered agents was 134.51 (observed value was 135).