rethinking  by rmcelreath

R package for Bayesian data analysis course/book

created 12 years ago
2,279 stars

Top 20.3% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This R package provides tools for Bayesian data analysis, accompanying Richard McElreath's "Statistical Rethinking" book and course. It enables users to specify statistical models explicitly via lists of distributional assumptions, facilitating a deeper understanding of model mechanics for students and researchers. The package supports both quadratic approximation (QUAP) for faster inference and Hamiltonian Monte Carlo (HMC) via Stan integration for more robust posterior sampling.

How It Works

The core innovation is the explicit, list-based model specification (e.g., alist(y ~ dnorm(mu, sigma), mu ~ dnorm(0, 10), sigma ~ dexp(1))). This forces users to define likelihoods and priors for each parameter, promoting pedagogical clarity and offering greater flexibility than formula-based approaches. For inference, quap uses quadratic approximation, while ulam (and map2stan) compiles the model into Stan code for HMC sampling, allowing for complex models including multilevel structures, custom distributions, and missing data imputation.

Quick Start & Requirements

  • Installation:
    • Full Stan integration: Requires C++ toolchain and cmdstanr installation first (cmdstanr::install_cmdstan()). Then, devtools::install_github("rmcelreath/rethinking").
    • "Slim" version (QUAP only): devtools::install_github("rmcelreath/rethinking@slim").
  • Prerequisites: R, C++ toolchain (for Stan), cmdstanr (optional but recommended for HMC).
  • Resources: Stan compilation can be time-consuming.
  • Documentation: https://github.com/rmcelreath/rethinking

Highlighted Details

  • Explicit distributional model specification for pedagogical clarity.
  • ulam function integrates with cmdstanr for efficient HMC sampling and supports within-chain multithreading.
  • Advanced features include multilevel modeling, custom distributions, Gaussian processes, and semi-automated imputation for continuous and discrete missing data.
  • Supports WAIC/LOO calculation via log_lik=TRUE in ulam.

Maintenance & Community

The package is actively maintained by Richard McElreath and associated contributors. Community support is available via the "Statistical Rethinking" community.

Licensing & Compatibility

The package is distributed under the MIT License, allowing for commercial use and integration with closed-source projects.

Limitations & Caveats

  • The full Stan integration requires a one-time setup of the C++ toolchain and CmdStan.
  • Some advanced features or complex models might require direct Stan code customization.
  • Compatibility notes exist for users of the first edition of the "Statistical Rethinking" book.
Health Check
Last commit

11 months ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
2
Star History
41 stars in the last 90 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), Nathan Lambert Nathan Lambert(AI Researcher at AI2), and
1 more.

tianshou by thu-ml

0.1%
9k
PyTorch RL library for algorithm development and application
created 7 years ago
updated 1 day ago
Feedback? Help us improve.