Chapter 13: Bayesian inference and decision making with bayestestR

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  warning = FALSE,
  message = FALSE
)
library(glmbayes)
library(bayestestR)

1. Purpose

bayestestR implements a wide range indices for posterior description and decision-oriented summaries (probability of direction, ropes, equivalence tests, etc.). Here we treat the coefficients component of a glmb fit as stored i.i.d. draws and summarize them using bayestestR.

This complements Chapter 12 (optional bayesplot graphics, commented out in the vignette) with tabular summaries you can cite in applied reports.

2. Example: logistic regression posterior for coefficients

data(menarche, package = "MASS")

Age2 <- menarche$Age - 13
Menarche_Model_Data <- data.frame(
  Menarche  = menarche$Menarche,
  Total     = menarche$Total,
  Age2      = Age2
)

ps <- Prior_Setup(
  cbind(Menarche, Total - Menarche) ~ Age2,
  family = binomial(link = "logit"),
  data   = Menarche_Model_Data
)

fit_logit <- glmb(
  cbind(Menarche, Total - Menarche) ~ Age2,
  family  = binomial(link = "logit"),
  pfamily = dNormal(mu = ps$mu, Sigma = ps$Sigma),
  data    = Menarche_Model_Data,
  n             = 800,
  use_parallel  = FALSE
)

coef_draws <- as.data.frame(fit_logit$coefficients)

3. Point and interval summaries

bayestestR::describe_posterior(coef_draws)
bayestestR::hdi(coef_draws, ci = 0.89)
bayestestR::rope(coef_draws, range = c(-0.02, 0.02))
bayestestR::p_direction(coef_draws)

Tune rope(..., range = ...) to match substantive “practical equivalence” hypotheses on the logit scale (see also the binomial likelihood discussion in Chapter 09). For richer reporting pipelines (parameters, performance, …), see the easystats ecosystem linking out from ?bayestestR.

See also



Try the glmbayes package in your browser

Any scripts or data that you put into this service are public.

glmbayes documentation built on Aug. 5, 2026, 1:07 a.m.