Skip to content

Commit

Permalink
Fill out fields for roxygen docs of LFMCMC
Browse files Browse the repository at this point in the history
  • Loading branch information
apulsipher committed Nov 4, 2024
1 parent 1f1e43f commit d9a2f48
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 14 deletions.
69 changes: 63 additions & 6 deletions R/LFMCMC.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,71 @@
#'
#' @aliases epiworld_lfmcmc
#' @details
#' TODO: Detail LFMCMC
#' Performs a Likelihood-Free Markhov Chain Monte Carlo simulation
#' @param model A model of class [epiworld_model]
#' @returns
#' - The `LFMCMC`function returns a model of class [epiworld_lfmcmc].
#' The `LFMCMC` function returns a model of class [epiworld_lfmcmc].
#' @examples
#' model_sir <- ModelSIR(name = "COVID-19", prevalence = 0.01,
#' transmission_rate = 0.9, recovery_rate = 0.1)
#' model_lfmcmc <- LFMCMC(model_sir)
#' ## Setup an SIR model to use in the simulation
#' model_seed <- 122
#' model_sir <- ModelSIR(name = "COVID-19", prevalence = .1,
#' transmission_rate = .9, recovery_rate = .3)
#' agents_smallworld(
#' model_sir,
#' n = 1000,
#' k = 5,
#' d = FALSE,
#' p = 0.01
#' )
#' verbose_off(model_sir)
#' run(model_sir, ndays = 50, seed = model_seed)
#'
#' ## Setup LFMCMC
#' # Extract the observed data from the model
#' obs_data <- unname(as.integer(get_today_total(model_sir)))
#'
#' # Define the simulation function
#' simfun <- function(params) {
#' set_param(model_sir, "Recovery rate", params[1])
#' set_param(model_sir, "Transmission rate", params[2])
#' run(model_sir, ndays = 50)
#' res <- unname(as.integer(get_today_total(model_sir)))
#' return(res)
#' }
#'
#' # Define the summary function
#' sumfun <- function(dat) {
#' return(dat)
#' }
#'
#' # Create the LFMCMC model
#' lfmcmc_model <- LFMCMC(model_sir) |>
#' set_simulation_fun(simfun) |>
#' set_summary_fun(sumfun) |>
#' use_proposal_norm_reflective() |>
#' use_kernel_fun_gaussian() |>
#' set_observed_data(obs_data)
#'
#' ## Run LFMCMC simulation
#' # Set initial parameters
#' par0 <- as.double(c(0.1, 0.5))
#' n_samp <- 2000
#' epsil <- as.double(1.0)
#'
#' # Run the LFMCMC simulation
#' run_lfmcmc(
#' lfmcmc = lfmcmc_model,
#' params_init_ = par0,
#' n_samples_ = n_samp,
#' epsilon_ = epsil,
#' seed = model_seed
#' )
#'
#' # Print the results
#' set_stats_names(lfmcmc_model, get_states(model_sir))
#' set_par_names(lfmcmc_model, c("Immune recovery", "Infectiousness"))
#'
#' print(lfmcmc_model)
#' @export
LFMCMC <- function(model) {
if (!inherits(model, "epiworld_model"))
Expand All @@ -28,7 +85,7 @@ LFMCMC <- function(model) {
#' @param n_samples_ Number of samples
#' @param epsilon_ Epsilon parameter
#' @param seed Random engine seed
#' @returns The simulated model of class `epiworld_lfmcmc`.
#' @returns The simulated model of class [epiworld_lfmcmc].
#' @export
run_lfmcmc <- function(lfmcmc, params_init_, n_samples_, epsilon_, seed = NULL) UseMethod("run_lfmcmc")

Expand Down
71 changes: 63 additions & 8 deletions man/LFMCMC.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d9a2f48

Please sign in to comment.