rethinking  by rmcelreath

R package for Bayesian data analysis course/book

Created 12 years ago
2,295 stars

Top 19.8% 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

1 year ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
1
Star History
11 stars in the last 30 days

Explore Similar Projects

Starred by Sasha Rush Sasha Rush(Research Scientist at Cursor; Professor at Cornell Tech) and Clément Renault Clément Renault(Cofounder of Meilisearch).

lm.rs by samuel-vitorino

0%
1k
Minimal LLM inference in Rust
Created 1 year ago
Updated 10 months ago
Starred by Elvis Saravia Elvis Saravia(Founder of DAIR.AI), Roy Frostig Roy Frostig(Coauthor of JAX; Research Scientist at Google DeepMind), and
8 more.

numpyro by pyro-ppl

0.1%
3k
Probabilistic programming library using JAX for GPU/TPU/CPU
Created 6 years ago
Updated 1 week ago
Starred by Andrej Karpathy Andrej Karpathy(Founder of Eureka Labs; Formerly at Tesla, OpenAI; Author of CS 231n), Jeff Hammerbacher Jeff Hammerbacher(Cofounder of Cloudera), and
4 more.

gemma_pytorch by google

0.2%
6k
PyTorch implementation for Google's Gemma models
Created 1 year ago
Updated 3 months ago
Feedback? Help us improve.