Skip to contents

The shrinkr package provides a flexible framework for two-stage Bayesian hierarchical modeling. It enables post-hoc shrinkage of subgroup-specific posterior estimates from any Bayesian model, with support for diverse prior specifications and diagnostic tools.

Key Features

Two-Stage Workflow:

  • Stage 1: Fit any Bayesian model without shrinkage

  • Stage 2: Apply hierarchical shrinkage with flexible priors

Flexible Priors:

  • Standard families (Normal, Student-t, Cauchy, Lognormal)

  • Heavy-tailed (Inverse-Gamma, Half-Cauchy, Half-t)

  • Bounded (Uniform)

  • Mixture priors (spike-and-slab)

  • Truncated distributions

Input Methods:

  • Full posterior samples (via mixture approximation)

  • Point estimates + variance/covariance

Main Functions

Core Workflow:

  • fit_mixture(): Approximate Stage 1 posteriors with Gaussian mixture

  • shrink(): Main user interface for hierarchical shrinkage

Prior Specification:

Extraction & Visualization:

Getting Started

See vignette("getting_started", package = "shrinkr") for a basic workflow, or vignette("brms_integration", package = "shrinkr") for a survival analysis example.

Use Cases

  • Meta-analysis: Shrink study-specific effects

  • Clinical trials: Borrow information across subgroups or historical controls

  • Genomics: Regularize gene-specific effects

  • Simulation studies: Compare shrinkage methods systematically

Package Options

  • shrinkr.refresh: Controls Stan sampling progress output (default: 100)

References

Maronge, J. M. (2026). shrinkr: Modular Bayesian Hierarchical Shrinkage Models. R package version 0.4.3.

Author

Maintainer: Jacob M. Maronge jacob.m.maronge@gsk.com (ORCID)

Authors:

Other contributors:

  • GlaxoSmithKline Research & Development Limited [copyright holder, funder]

  • Trustees of Columbia University (R/stanmodels.R, configure, configure.win) [copyright holder]

Examples

if (FALSE) { # \dontrun{
# This example fits a Stan model, so it is not run during package checks.
library(shrinkr)
priors <- list(
  mu = distributional::dist_normal(0, 5),
  tau = distributional::dist_truncated(distributional::dist_student_t(3, 0, 1), lower = 0)
)
fit <- shrink(
  mle = c(0.0, 0.5, 1.0),
  var_matrix = c(0.25, 0.25, 0.25),
  hierarchical_priors = priors,
  iter = 1000, chains = 2, seed = 1
)
summary(fit)
} # }