Learn R Programming

GHRmodel (version 0.1.1)

sample_ppd: Sample from the Posterior Predictive Distribution

Description

This function refits a specified model from a GHRmodels object and generates samples from its posterior predictive distribution.

Usage

sample_ppd(models, mod_id, s = 1000, nthreads = 8)

Value

A data.frame containing columns for each of the posterior predictive samples and one column with observed data.

Arguments

models

A GHRmodels object.

mod_id

Character; model identifier (from models$mod_gof$model_id).

s

An integer specifying the number of samples to draw from the posterior predictive distribution.

nthreads

An integer specifying the number of threads for parallel computation to refit the model. Default is 8.

Examples

Run this code
# \donttest{
# Load example dataset
data(dengueMS)

# Declare formulas
formulas <- c("dengue_cases ~ tmin +  f(year, model='rw1')")

# Tranform formulas into a 'GHRformulas' object
ghr_formula <- as_GHRformulas(formulas)

# Fit multiple models 
results <- fit_models(
  formulas = ghr_formula,
  data     = dengue_MS[dengue_MS$year %in% 2005:2010,],
  family   = "nbinomial",
  name     = "model",
  offset   = "population",
  nthreads = 2,
  control_compute = list(config = FALSE),
  pb       = TRUE
)

# Generate 100 samples from the posterior predictive distribution of the model
ppd_df <- sample_ppd( 
  results,
  mod_id = "model1", 
  s = 100,
  nthreads = 2)
# }

Run the code above in your browser using DataLab