Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Bayesian inference methods including prior selection, MCMC, and model comparison
.claude/skills/brycewang-stanford-bayesian-statistics-guide/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-12 | ✗→✓ | ▲ Improved | 119% | 0% |
| case-16 | ✗→✓ | ▲ Improved | 60% | 0% |
| case-22 | ✗→✓ | ▲ Improved | 94% | 0% |
| case-07 | ✓→✓ | = Same ✓ | 39% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 22% | 0% |
A skill for applying Bayesian statistical methods to research data analysis. Covers prior specification, Markov chain Monte Carlo (MCMC) sampling, posterior interpretation, model comparison, and reporting standards.
Posterior = (Likelihood x Prior) / Evidence
P(theta | data) = P(data | theta) * P(theta) / P(data)
In practice:
P(theta | data) is proportional to P(data | theta) * P(theta)
(the denominator is a normalizing constant)| Scenario | Bayesian Advantage | |----------|-------------------| | Small sample sizes | Priors regularize estimates | | Complex hierarchical models | Natural framework for multilevel data | | Sequential data collection | Update beliefs as data arrives | | Prior knowledge available | Formally incorporate existing evidence | | Model comparison | Bayes factors and posterior model probabilities | | Prediction | Full posterior predictive distributions |
pythonimport numpy as np from scipy import stats import matplotlib.pyplot as plt def visualize_priors(parameter_name: str, prior_type: str = 'weakly_informative'): """ Visualize common prior choices for a parameter. """ x = np.linspace(-10, 10, 1000) priors = { 'flat': { 'dist': stats.uniform(loc=-100, scale=200), 'description': 'Flat/Uniform: minimal prior info (often improper)', 'recommendation': 'Avoid -- can lead to improper posteriors' }, 'weakly_informative': { 'dist': stats.norm(loc=0, scale=2.5), 'description': 'Weakly informative: Normal(0, 2.5)', 'recommendation': 'Good default for regression coefficients' }, 'informative': { 'dist': stats.norm(loc=0.5, scale=0.2), 'description': 'Informative: based on previous studies', 'recommendation': 'Use when strong prior evidence exists' }, 'horseshoe': { 'dist': stats.cauchy(loc=0, scale=1), 'description': 'Horseshoe-like (Cauchy): sparsity-inducing', 'recommendation': 'Good for variable selection problems' } } prior = priors.get(prior_type, priors['weakly_informative']) return prior # Recommended default priors (Gelman et al., 2008): # Intercept: Normal(0, 10) # Coefficients: Normal(0, 2.5) on standardized predictors # Standard deviation: Half-Cauchy(0, 2.5) or Exponential(1) # Correlation: LKJ(2) for correlation matrices
pythonimport pymc as pm import arviz as az def bayesian_regression(X, y, feature_names=None): """ Fit a Bayesian linear regression model using PyMC. Args: X: Feature matrix (n_samples, n_features) y: Response variable (n_samples,) feature_names: List of feature names """ n_features = X.shape[1] if feature_names is None: feature_names = [f'x{i}' for i in range(n_features)] with pm.Model() as model: # Priors intercept = pm.Normal('intercept', mu=0, sigma=10) betas = pm.Normal('betas', mu=0, sigma=2.5, shape=n_features) sigma = pm.HalfCauchy('sigma', beta=2.5) # Linear predictor mu = intercept + pm.math.dot(X, betas) # Likelihood y_obs = pm.Normal('y_obs', mu=mu, sigma=sigma, observed=y) # MCMC sampling trace = pm.sample( draws=2000, tune=1000, chains=4, cores=4, target_accept=0.9, return_inferencedata=True ) return model, trace # After fitting, analyze results: # az.summary(trace, var_names=['intercept', 'betas', 'sigma']) # az.plot_trace(trace) # az.plot_forest(trace, var_names=['betas'])
pythondef check_mcmc_diagnostics(trace) -> dict: """ Check MCMC convergence diagnostics. """ summary = az.summary(trace) diagnostics = { 'r_hat': { 'values': summary['r_hat'].to_dict(), 'threshold': 1.01, 'pass': (summary['r_hat'] < 1.01).all(), 'interpretation': 'R-hat < 1.01 indicates convergence' }, 'ess_bulk': { 'min_value': summary['ess_bulk'].min(), 'threshold': 400, 'pass': (summary['ess_bulk'] > 400).all(), 'interpretation': 'ESS > 400 ensures reliable posterior estimates' }, 'ess_tail': { 'min_value': summary['ess_tail'].min(), 'threshold': 400, 'pass': (summary['ess_tail'] > 400).all(), 'interpretation': 'Tail ESS > 400 ensures reliable credible intervals' } } # Overall assessment diagnostics['converged'] = all( d['pass'] for d in diagnostics.values() if 'pass' in d ) return diagnostics
pythondef compare_models(traces: dict) -> dict: """ Compare Bayesian models using LOO-CV and WAIC. Args: traces: Dict mapping model names to InferenceData objects """ comparison = az.compare(traces, ic='loo') return { 'ranking': comparison.index.tolist(), 'loo_values': comparison['loo'].to_dict(), 'weights': comparison['weight'].to_dict(), 'interpretation': ( f"Best model: {comparison.index[0]} " f"(weight = {comparison['weight'].iloc[0]:.2f})" ) }
Follow the WAMBS checklist (Depaoli & van de Schoot, 2017):
Example results sentence: "The effect of treatment on outcome was estimated at beta = 0.45, 95% HDI 0.21, 0.68], with a posterior probability of 0.99 that the effect is positive."
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-02 | fail→fail | 18,799 | 14,741 | -22% | 1 | 1 | 0% | 3,659 | 4,836 | +32% | 0 | 0 | — |
case-07 | pass→pass | 17,020 | 12,312 | -28% | 1 | 1 | 0% | 2,955 | 4,093 | +39% | 0 | 0 | — |
case-01 | pass→pass | 23,095 | 33,891 | +47% | 1 | 1 | 0% | 4,909 | 5,975 | +22% | 0 | 0 | — |
case-03 | pass→pass | 14,310 | 14,861 | +4% | 1 | 1 | 0% | 2,773 | 4,683 | +69% | 0 | 0 | — |
case-04 | pass→pass | 7,251 | 9,908 | +37% | 1 | 1 | 0% | 1,641 | 3,972 | +142% | 0 | 0 | — |
case-05 | pass→pass | 11,898 | 8,344 | -30% | 1 | 1 | 0% | 2,549 | 3,608 | +42% | 0 | 0 | — |
case-06 | pass→pass | 8,065 | 6,191 | -23% | 1 | 1 | 0% | 1,611 | 3,001 | +86% | 0 | 0 | — |
case-08 | pass→pass | 7,246 | 8,053 | +11% | 1 | 1 | 0% | 1,261 | 3,234 | +156% | 0 | 0 | — |
case-09 | fail→fail | 17,664 | 15,918 | -10% | 1 | 1 | 0% | 3,108 | 4,612 | +48% | 0 | 0 | — |
case-10 | fail→fail | 15,334 | 15,042 | -2% | 1 | 1 | 0% | 2,382 | 4,317 | +81% | 0 | 0 | — |
case-11 | fail→fail | 16,252 | 17,741 | +9% | 1 | 1 | 0% | 2,912 | 5,050 | +73% | 0 | 0 | — |
case-12 | fail→pass | 8,933 | 8,199 | -8% | 1 | 1 | 0% | 1,477 | 3,228 | +119% | 0 | 0 | — |
case-13 | pass→pass | 13,517 | 13,154 | -3% | 1 | 1 | 0% | 2,452 | 4,291 | +75% | 0 | 0 | — |
case-14 | pass→pass | 10,501 | 10,193 | -3% | 1 | 1 | 0% | 1,764 | 3,598 | +104% | 0 | 0 | — |
case-15 | pass→pass | 13,843 | 11,525 | -17% | 1 | 1 | 0% | 2,293 | 3,805 | +66% | 0 | 0 | — |
case-16 | fail→pass | 16,854 | 15,332 | -9% | 1 | 1 | 0% | 2,761 | 4,417 | +60% | 0 | 0 | — |
case-17 | fail→fail | 12,107 | 10,523 | -13% | 1 | 1 | 0% | 1,890 | 3,613 | +91% | 0 | 0 | — |
case-18 | pass→pass | 18,484 | 17,237 | -7% | 1 | 1 | 0% | 2,845 | 4,622 | +62% | 0 | 0 | — |
case-19 | pass→pass | 7,677 | 4,455 | -42% | 1 | 1 | 0% | 1,312 | 2,582 | +97% | 0 | 0 | — |
case-20 | pass→pass | 3,514 | 2,479 | -29% | 1 | 1 | 0% | 574 | 2,191 | +282% | 0 | 0 | — |
case-21 | pass→pass | 6,377 | 9,324 | +46% | 1 | 1 | 0% | 1,036 | 3,417 | +230% | 0 | 0 | — |
case-22 | fail→pass | 12,411 | 13,611 | +10% | 1 | 1 | 0% | 2,168 | 4,209 | +94% | 0 | 0 | — |
case-23 | pass→pass | 4,914 | 5,101 | +4% | 1 | 1 | 0% | 683 | 2,486 | +264% | 0 | 0 | — |
case-24 | fail→fail | 15,513 | 12,227 | -21% | 1 | 1 | 0% | 2,931 | 4,190 | +43% | 0 | 0 | — |
case-25 | pass→pass | 5,055 | 3,973 | -21% | 1 | 1 | 0% | 824 | 2,483 | +201% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 25 cases were attempted. The headline lift of +12 percentage points is the difference between those two pass rates over the 25 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.