Learn R Programming

CLRtools (version 0.1.0)

compare_bayesm: Posterior Predictive Check for Multiple Bayesian Models

Description

This function performs a posterior predictive check for one or more Bayesian models by computing the mean and standard deviations of simulated predictions, comparing them to the observed outcome. It produces grouped histograms for each model.

Usage

compare_bayesm(
  models,
  ypredict = NULL,
  data,
  outcome,
  intercept = NULL,
  var.param = NULL
)

Value

Invisibly returns a list with two ggplot objects:

ppc_pe

A ggplot object showing the distribution of simulated mean of the outcome across models.

ppc_sd

A ggplot object showing the distribution of simulated standard deviations of the outcome across models.

Arguments

models

A named list of fitted rstan models (objects of class stanfit).

ypredict

Optional. A named list of posterior predictive matrices. Each matrix should have rows as posterior draws and columns as data points. If not provided, predictions are computed internally. Must have the same names as models.

data

A data frame containing the predictor variables and the outcome used for model prediction.

outcome

A character string naming the outcome variable in data.

intercept

(Optional) A named list with the intercept parameter names for each model. Each entry should be a character string or NULL if no intercept is used. Must have the same names as models.

var.param

A named list mapping each model to a named character vector where each name is a variable in the data and the value is the name of the corresponding parameter/coefficient in the model. Must have the same names as models. Required if ypredict is not provided.