Learn R Programming

CLRtools (version 0.1.0)

logit_prob_plot: Plot Predicted Probabilities from a Logistic Model

Description

This function visualizes the predicted probabilities from a Bayesian logistic regression model fitted using rstan. It computes the posterior predicted probabilities over a grid defined by two continuous predictor variables, and creates a plot showing how these probabilities vary across their values. Color is used to represent the estimated probability, and the original data points are overlaid for reference.

Usage

logit_prob_plot(
  data,
  ypredict = NULL,
  model = NULL,
  parameters = NULL,
  intercept = NULL,
  outcome,
  predictors.plot
)

Value

A ggplot2 object showing the mean predicted probabilities across the grid of the two specified predictors, with the observed outcome overlaid as colored points.

Arguments

data

A data frame containing the original data used to fit the model.

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).

model

A fitted Stan model object of class 'stanfit' (from rstan). Required if ypredict is not provided.

parameters

A named vector where the names are the predictor variable names (as in the data), and the values are the corresponding parameter names in the Stan model. Required if ypredict is not provided.

intercept

Optional. A character string indicating the name of the intercept parameter in the Stan model (if present).

outcome

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

predictors.plot

A character vector of length 2 specifying which two predictor variables to use for the x and y axes of the plot.