Give your browser Bayesian teeth.
FANGS is a Gibbs sampler that runs Bayesian inference in your browser. No software setup necessary. Fast Accessible Numeric Gibbs Sampler.
Built with Claude Code.
npx serve .Then open http://localhost:3000 in your browser.
The Sampler engine setting chooses how each MCMC sweep is run:
| Engine | What it does | Best for |
|---|---|---|
| Standard (default) | Component-wise Gibbs: one parameter at a time, conjugate draws or slice sampling | Any model FANGS can parse |
| Blocked | Blocked Gibbs for GLMMs: fixed effects updated jointly, all group-level effects updated at once, hyperparameters from sufficient statistics, plus translation moves across the intercept↔random-effect and group-level-covariate↔random-effect ridges | Mixed-effects models; larger data or many groups |
The blocked engine supports normal, Poisson (log link) and Bernoulli/binomial
(logit link) responses whose linear predictor is linear in the coefficients,
with dnorm priors on the coefficients and random intercepts or slopes. That
covers all of the built-in examples. Other models fall back to the standard
sampler automatically, and the status bar says why.
Both engines target the same posterior. On the 50-row example dataset the
blocked engine is 24–103× faster per sweep, and it mixes far better on
hierarchical models — see
plans/sampler-engine-benchmarks.md for
measurements, and plans/gpu-blocked-sampler.md
for the algorithm's design notes.
Install dependencies first (one-time):
npm installThen run all tests:
npx vitest runOr run a specific test file:
npx vitest run tests/parser.test.js
npx vitest run tests/distributions.test.js
npx vitest run tests/integration.test.jsRequires R with the nimble package installed (install.packages("nimble")).
Run from the project root:
Rscript tests/r-reference/linear-model.R
Rscript tests/r-reference/mixed-effects.R
Rscript tests/r-reference/poisson-glm.R
Rscript tests/r-reference/binomial-glm.ROr all at once:
Rscript tests/r-reference/{linear-model,mixed-effects,poisson-glm,binomial-glm}.RReference JSON fixtures are written to tests/r-reference/results/.
Matching app tests are run with: npx vitest run tests/integration.test.js
tests/blocked-sampler.test.js (part of npx vitest run) covers the blocked
sampler: the model compiler, the block update maths, and the posteriors it
produces.
To time the engines against each other, use the CLI harness:
node tests/bench/fangs-cli.mjs --model mixed --engine standard --output /tmp/std.csv
node tests/bench/fangs-cli.mjs --model mixed --engine cpu-blocked --output /tmp/blk.csvPopup content is authored in Quarto .qmd files and rendered to HTML
at build time. The rendered HTML is bundled into src/content/popups-bundle.js as a fallback
so popups work even when opened via file:// without a local server.
Prerequisite: Install Quarto as a system tool.
- Open the relevant
.qmdfile insrc/content/popups/and make your changes. Standard Markdown is supported, plus LaTeX math ($...$inline,$$...$$display). - Run
npm run build:popupsto re-render and regenerate the bundle. - Reload the app.
Step 1 — Write the content
Create a new Quarto file in src/content/popups/:
src/content/popups/my-topic.qmd
Step 2 — Build
npm run build:popupsThis renders all .qmd files to HTML fragments in src/content/popups/_rendered/ and
regenerates src/content/popups-bundle.js.
Step 3 — Attach the trigger to an HTML element
Option A — static HTML element
Add data-popup="my-topic" to any element in index.html. A ? button is appended automatically when the app loads:
<label for="input-foo" data-popup="my-topic">My setting</label>Option B — dynamically created element (JavaScript)
Import attachPopupTrigger and call it after the element exists in the DOM:
import { attachPopupTrigger } from './ui/popups.js';
attachPopupTrigger(myElement, 'my-topic');Step 4 — Commit
Commit the .qmd source file and the updated popups-bundle.js.
Do not commit src/content/popups/_rendered/ (it is git-ignored).
| File | Topic |
|---|---|
mcmc.qmd |
What is MCMC? |
gibbs-sampler.qmd |
How Gibbs sampling works |
sampler-engine.qmd |
Standard vs blocked sampler engines |
chains.qmd |
Multiple chains |
burn-in.qmd |
Burn-in / warm-up |
thinning.qmd |
Thinning |
trace-plot.qmd |
Reading trace plots |
rhat.qmd |
R-hat convergence diagnostic |
ess.qmd |
Effective sample size |
posterior.qmd |
Posterior distributions |
prior.qmd |
Prior distributions |
credible-interval.qmd |
Credible intervals |
ppc.qmd |
Posterior predictive checks |
prior-check.qmd |
Prior predictive checks |
precision.qmd |
Standard deviation (σ) parameterisation |
mixed-effects.qmd |
Mixed-effects models |
posteriors-tab.qmd |
Reading the Posteriors tab |
summary-tab.qmd |
Reading the Summary table |