Learn R Programming

CLRtools (version 0.1.0)

summarize_results: Summarize Bayesian Logistic Regression Model Results

Description

This function provides a visual and numeric summary of a Bayesian logistic regression model fitted with rstan. It displays posterior distributions of selected parameters and performs posterior predictive checks based on either user-provided simulations or internal simulations.

Usage

summarize_results(
  model,
  ypredict = NULL,
  data,
  outcome,
  intercept = NULL,
  var.param,
  rounding = 2,
  prob = 0.8,
  point.est = "median"
)

Value

A list with the following components:

posterior_plot

A ggplot object showing posterior distributions of the coefficients.

ppc_mean

A ggplot object showing the posterior predictive check for the point estimate.

ppc_sd

A ggplot object showing the posterior predictive check for the standard deviation.

Also prints parameter summaries and displays plots.

Arguments

model

A fitted model object of class stanfit, from rstan or stanreg, from rstanarm, representing a single-level logistic regression.

ypredict

Optional. A matrix of posterior predictive simulations of the outcome variable (e.g., generated externally). If NULL, predictions will be simulated internally assuming a single-level logistic regression. The matrix should have dimensions S x N, where S is the number of posterior draws (rows) and N is the number of observations (columns).

data

A data frame containing the variables used in the model.

outcome

A character string specifying the name of the binary outcome variable in data.

intercept

Optional. A character string naming the intercept parameter in the model. Defaults to NULL.

var.param

A named character vector mapping dataset variable names to model parameter names. When ypredict is NULL, the variable names must exist in data for posterior prediction. If ypredict is provided, this check is skipped since predictions are supplied directly.

rounding

An integer specifying the number of decimal places for printed parameter summaries. Must be a non-negative integer. Default is 2.

prob

A numeric value between 0 and 1 specifying the width of the credible interval for posterior plots (e.g., 0.8 for 80% intervals). Default is 0.8.

point.est

Character string, either "mean" or "median", indicating the point estimate to use in posterior plots. Default is median.