Bayesian Inference¶
The Bayesian page provides MCMC (Markov Chain Monte Carlo) inference with ArviZ diagnostic visualizations.
Overview¶
Bayesian inference provides:
Uncertainty quantification: Credible intervals for parameters
Full posterior: Complete probability distributions
Diagnostics: Convergence metrics (R-hat, ESS)
Model comparison: Evidence-based model selection
When to Use Bayesian¶
Use Bayesian inference when you need:
Parameter uncertainties
Confidence intervals for predictions
Robust handling of measurement noise
Publication-quality error bars
Configuration¶
MCMC Settings¶
- Warmup Samples
Number of initial samples for adaptation (discarded). Recommended: 1000-2000
- Posterior Samples
Number of samples for inference. Recommended: 2000-4000
- Chains
Number of independent MCMC chains. Recommended: 4 (for R-hat calculation)
- Random Seed
For reproducibility. Default: 42
Prior Configuration¶
Access via Prior Settings panel:
- Default Priors
Automatic priors based on parameter bounds:
Uniform for bounded parameters
Log-uniform for scale parameters
- Custom Priors
Specify distribution for each parameter:
Normal(mean, std)
LogNormal(mean, std)
Uniform(low, high)
HalfNormal(std)
Running Inference¶
Prerequisites¶
Load data and select model
Run NLSQ fit first (provides warm start)
Configure MCMC settings
Starting MCMC¶
Click “Run Bayesian Inference”
Progress shows:
Warmup phase progress
Sampling phase progress
Current acceptance rate
Wait for completion (typically 5-60 seconds)
Warm Start¶
Always run NLSQ first!
Warm start from NLSQ:
Initializes chains near optimum
Reduces warmup time
Improves convergence
Avoids poor initial samples
Diagnostics¶
ArviZ Plot Types¶
The ArviZ Canvas provides multiple diagnostic views:
- Trace Plot (Default)
Left: Posterior density
Right: MCMC chain trace
Check: Chains should mix well
- Pair Plot
Parameter correlations
Divergence markers
Check: No extreme correlations
- Forest Plot
Credible intervals comparison
Point estimates with HDI
Check: Intervals don’t overlap zero (if significant)
- Posterior Plot
Marginal distributions
HDI intervals
Check: Unimodal, well-defined peaks
- Energy Plot
NUTS energy diagnostics
Check: Marginal and transition should overlap
- Rank Plot
Chain rank statistics
Check: Uniform distribution across chains
- ESS Plot
Effective sample size
Check: ESS > 400 for reliable estimates
- Autocorrelation
Chain autocorrelation
Check: Quick decay to zero
Convergence Metrics¶
- R-hat (Gelman-Rubin)
Potential scale reduction factor.
Good: R-hat < 1.01
Acceptable: R-hat < 1.1
Problematic: R-hat > 1.1 (more samples needed)
- ESS (Effective Sample Size)
Independent samples equivalent.
Good: ESS > 400 for all parameters
Low ESS indicates autocorrelation
- Divergences
Numerical integration issues.
Good: 0 divergences
Some: May indicate model issues
Many: Investigate model/data
Results¶
Posterior Summary¶
After inference completes:
Mean: Posterior mean
Std: Posterior standard deviation
HDI 3%/97%: 94% credible interval
MCSE: Monte Carlo standard error
Credible Intervals¶
Different credibility levels:
50% HDI: Core distribution
94% HDI: Standard reporting
99% HDI: Conservative bounds
Prediction Intervals¶
Generate prediction uncertainty:
Click “Plot Predictions”
Shows fit with credible bands
Inner band: Parameter uncertainty
Outer band: Plus observation noise
Exporting Results¶
Posterior Samples¶
Export raw samples:
Go to Export page
Select Posterior Samples
Choose format (CSV, HDF5)
ArviZ InferenceData¶
Export full ArviZ object:
Select ArviZ InferenceData
Save as NetCDF or pickle
Load later for further analysis
Diagnostic Plots¶
Export diagnostic figures:
Right-click any plot
Select Export Plot
Choose format (PNG, PDF, SVG)
Troubleshooting¶
High R-hat¶
R-hat > 1.1 indicates poor convergence:
Increase warmup samples
Increase total samples
Check for multimodality
Simplify model
Low ESS¶
Low effective samples:
Increase total samples
Check autocorrelation
Tune step size (advanced)
Divergences¶
Many divergences indicate problems:
Reparameterize model
Adjust priors
Check data quality
Try non-centered parameterization
Slow Sampling¶
MCMC is slow:
Ensure NLSQ warm start
Reduce model complexity
Use GPU if available
Reduce number of chains
Best Practices¶
Always warm start from NLSQ
Use 4+ chains for diagnostics
Check all diagnostic plots
Report R-hat and ESS with results
Use HDI, not mean±std for reporting
Save InferenceData for reproducibility