<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Antonio De Leon</title>
  <link href="https://antonio-de-leon.com/atom.xml" rel="self"/>
  <link href="https://antonio-de-leon.com/"/>
  <updated>2026-07-17T00:26:56+00:00</updated>
  <id>https://antonio-de-leon.com</id>
  <author>
    <name>Antonio De Leon</name>
    <email>jaguir26@ucsc.edu</email>
  </author>

  
  <entry>
    <title>Variational Bayes for Non-Conjugate Models: A Laplace-Delta Tutorial</title>
    <link href="https://antonio-de-leon.com/2025/03/20/VBLD/"/>
    <updated>2025-03-20T00:00:00+00:00</updated>
    <id>https://antonio-de-leon.com/2025/03/20/VBLD</id>
    <content type="html">&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;This tutorial presents a comprehensive guide to the &lt;strong&gt;Variational Bayes with Laplace-Delta (VB-LD)&lt;/strong&gt; method, a framework for approximate Bayesian inference in models containing non-conjugate parameter relationships. VB-LD addresses the challenge of efficiently approximating posterior distributions when conditional conjugacy is absent without resorting to computationally intensive or unstable alternatives, such as Importance Sampling.&lt;/p&gt;

&lt;h3 id=&quot;methodology-overview&quot;&gt;Methodology Overview&lt;/h3&gt;

&lt;p&gt;The VB-LD approach combines two techniques:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Laplace Approximation for Non-Conjugate Updates&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Provides a Gaussian approximation to intractable variational distributions by matching the mode and curvature of the log-posterior&lt;/li&gt;
      &lt;li&gt;Particularly effective when the true posterior is unimodal and approximately Gaussian near its peak&lt;/li&gt;
      &lt;li&gt;Avoids sampling-based approaches that may suffer from high variance or particle degeneracy&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Delta Method for Expectation Propagation&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Enables closed-form approximation of necessary moments through second-order Taylor expansion&lt;/li&gt;
      &lt;li&gt;Crucial for maintaining the mean-field factorization when updating conjugate parameters&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1-preliminaries&quot;&gt;1. Preliminaries&lt;/h2&gt;

&lt;h3 id=&quot;11-mean-field-variational-bayes-mfvb&quot;&gt;1.1 Mean-Field Variational Bayes (MFVB)&lt;/h3&gt;

&lt;p&gt;Consider the observed data \( D \in \mathcal{D} \) and a parameter vector \( \boldsymbol{\theta} = (\boldsymbol{\eta}, \boldsymbol{\psi}) \in \Theta \) where:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\( \boldsymbol{\eta} \): non-conjugate parameters&lt;/li&gt;
  &lt;li&gt;\( \boldsymbol{\psi} \): conjugate parameters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;MFVB posits a &lt;strong&gt;structured variational family&lt;/strong&gt; \( \mathcal{Q} \) of distributions that factorize as:&lt;/p&gt;

\[\mathcal{Q} = \{ q : q(\boldsymbol{\theta}) = q_{\boldsymbol{\eta}}(\boldsymbol{\eta})q_{\boldsymbol{\psi}}(\boldsymbol{\psi}), q_{\boldsymbol{\eta}} \in \mathcal{Q}_{\boldsymbol{\eta}}, q_{\boldsymbol{\psi}} \in \mathcal{Q}_{\boldsymbol{\psi}} \}\]

&lt;p&gt;The optimal approximation \( q^* \in \mathcal{Q} \) minimizes the Kullback-Leibler divergence:&lt;/p&gt;

\[q^* = 	\text{arg} min_{q \in \mathcal{Q}} \text{KL}(q\|p) = 	\text{arg} min_{q \in \mathcal{Q}} \int q(\boldsymbol{\theta}) \log \frac{q(\boldsymbol{\theta})}{p(\boldsymbol{\theta}|D)} d\boldsymbol{\theta}\]

&lt;p&gt;Equivalently, we maximize the Evidence Lower Bound (ELBO):&lt;/p&gt;

&lt;p&gt;\[
\text{ELBO}(q) = \mathbb{E}_q[\log p(D, \boldsymbol{\theta})] - \mathbb{E}_q[\log q(\boldsymbol{\theta})] 
\]&lt;/p&gt;

&lt;p&gt;where:&lt;/p&gt;

&lt;p&gt;\[
\mathbb{E}_q[\log p(D, \boldsymbol{\theta})] := \text{Expected complete-data log-likelihood}
\]&lt;/p&gt;

&lt;p&gt;\[
\mathbb{E}_q[\log q(\boldsymbol{\theta})] := \text{Entropy of } q
\]&lt;/p&gt;

&lt;div class=&quot;blue-box&quot;&gt;
&lt;p&gt;&lt;strong&gt;Optimality Conditions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The stationary points of the ELBO satisfy:&lt;/p&gt;

$$
\log q^*(\boldsymbol{\eta}) = \mathbb{E}_{q^*(\boldsymbol{\psi})}[\log p(D, \boldsymbol{\eta}, \boldsymbol{\psi})] + \text{const.}
$$

$$
\log q^*(\boldsymbol{\psi}) = \mathbb{E}_{q^*(\boldsymbol{\eta})}[\log p(D, \boldsymbol{\eta}, \boldsymbol{\psi})] + \text{const.}
$$
&lt;/div&gt;

&lt;h3 id=&quot;12-coordinate-ascent-variational-inference-cavi&quot;&gt;1.2 Coordinate Ascent Variational Inference (CAVI)&lt;/h3&gt;

&lt;p&gt;The CAVI algorithm iteratively optimizes each variational factor while holding others fixed:&lt;/p&gt;

&lt;div class=&quot;algorithm&quot;&gt;
&lt;p&gt;&lt;strong&gt;Algorithm 1: CAVI for MFVB&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Initialize $ q^{(0)}(\boldsymbol{\eta}) $, $ q^{(0)}(\boldsymbol{\psi}) $ by their setting hyperparameters&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;While&lt;/strong&gt; stopping criteria not met:
    &lt;ol&gt;
      &lt;li&gt;Update non-conjugate parameters:
        $$
        q^{(k)}(\boldsymbol{\eta}) \propto \exp\left(\mathbb{E}_{q^{(k-1)}(\boldsymbol{\psi})}[\log p(D, \boldsymbol{\eta}, \boldsymbol{\psi})]\right)
        $$&lt;/li&gt;
      &lt;li&gt;Update conjugate parameters:
        $$
        q^{(k)}(\boldsymbol{\psi}) \propto \exp\left(\mathbb{E}_{q^{(k)}(\boldsymbol{\eta})}[\log p(D, \boldsymbol{\eta}, \boldsymbol{\psi})]\right)
        $$&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

&lt;h3 id=&quot;13-non-conjugate-challenges&quot;&gt;1.3 Non-Conjugate Challenges&lt;/h3&gt;

&lt;p&gt;When \( \boldsymbol{\eta} \) is non-conjugate, the update:&lt;/p&gt;

&lt;p&gt;\[
q(\boldsymbol{\eta}) \propto \exp\left(\mathbb{E}_{q(\boldsymbol{\psi})}[\log p(D, \boldsymbol{\eta}, \boldsymbol{\psi})]\right) \equiv \exp(f(\boldsymbol{\eta}))
\]&lt;/p&gt;

&lt;p&gt;faces three fundamental difficulties:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The normalizing constant \( Z = \int \exp(f(\boldsymbol{\eta})) d\boldsymbol{\eta} \) is typically intractable&lt;/li&gt;
  &lt;li&gt;Required expectations \( \mathbb{E}_{q(\boldsymbol{\eta})}[g(\boldsymbol{\eta})] \) lack closed forms&lt;/li&gt;
  &lt;li&gt;The ELBO cannot be evaluated exactly&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
&lt;p&gt;&lt;strong&gt;Some Solutions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Importance Sampling&lt;/strong&gt;... but suffers from high variance in high dimensions and is prone to particle collapse&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Quadrature Methods&lt;/strong&gt;... but exponential complexity in $ k = \dim(\boldsymbol{\eta}) $&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Conjugate Modifications&lt;/strong&gt;... but restrictive modeling assumptions&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;h2 id=&quot;2-vb-ld-algorithm&quot;&gt;2. VB-LD Algorithm&lt;/h2&gt;

&lt;h3 id=&quot;21-laplace-approximation-step&quot;&gt;2.1 Laplace Approximation Step&lt;/h3&gt;

&lt;p&gt;Given the variational distribution:&lt;/p&gt;

&lt;p&gt;\[
q(\boldsymbol{\eta}) \propto \exp\left(\mathbb{E}_{q(\boldsymbol{\psi})}[\log p(D,\boldsymbol{\eta},\boldsymbol{\psi})]\right) \equiv \exp(f(\boldsymbol{\eta}))
\]&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Mode Finding&lt;/strong&gt;:
    &lt;ul&gt;
      &lt;li&gt;Compute gradient \( \nabla f(\boldsymbol{\eta}) \)&lt;/li&gt;
      &lt;li&gt;Solve \( \nabla f(\hat{\boldsymbol{\eta}}) = 0 \) via Newton-Raphson:
\[
\boldsymbol{\eta}^{(k+1)} = \boldsymbol{\eta}^{(k)} - [\nabla^2 f(\boldsymbol{\eta}^{(k)})]^{-1}\nabla f(\boldsymbol{\eta}^{(k)})
\]&lt;/li&gt;
      &lt;li&gt;Terminate when \( |\boldsymbol{\eta}^{(k+1)} - \boldsymbol{\eta}^{(k)}| &amp;lt; \epsilon \)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Covariance Approximation&lt;/strong&gt;:
\[
\Sigma = -\left[\nabla^2 f(\hat{\boldsymbol{\eta}})\right]^{-1}
\]
where the Hessian is computed via:
\[
[\nabla^2 f(\boldsymbol{\eta})]_{ij} = \frac{\partial^2 f}{\partial \eta_i \partial \eta_j}
\]&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;blue-box&quot;&gt;
&lt;p&gt;&lt;strong&gt;Laplacian approximation &lt;/strong&gt;&lt;/p&gt;

$$
q(\boldsymbol{\eta}) \approx \mathcal{N}(\hat{\boldsymbol{\eta}}, \Sigma)
$$
&lt;/div&gt;

&lt;h3 id=&quot;22-delta-method-for-expectation-approximation&quot;&gt;2.2 Delta Method for Expectation Approximation&lt;/h3&gt;

&lt;p&gt;When updating \( q(\boldsymbol{\psi}) \), we are required to compute expectations of the form:&lt;/p&gt;

&lt;p&gt;\[
\mathbb{E}_{q(\boldsymbol{\eta})}[g(\boldsymbol{\eta})]
\]&lt;/p&gt;

&lt;p&gt;To do so, we approximate such quantities as follows,&lt;/p&gt;

&lt;div class=&quot;blue-box&quot;&gt;
&lt;p&gt;&lt;strong&gt;Delta method (second-order Taylor approximation)&lt;/strong&gt;&lt;/p&gt;
$$
\mathbb{E}[g(\boldsymbol{\eta})] \approx g(\hat{\boldsymbol{\eta}}) + \frac{1}{2}\text{tr}\left[\nabla^2 g(\hat{\boldsymbol{\eta}})\Sigma\right]
$$
&lt;/div&gt;

&lt;h3 id=&quot;23-complete-vb-ld-algorithm&quot;&gt;2.3 Complete VB-LD Algorithm&lt;/h3&gt;

&lt;div class=&quot;algorithm&quot;&gt;
&lt;p&gt;&lt;strong&gt;Algorithm 2: VB-LD Implementation&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Initialize $ q^{(0)}(\boldsymbol{\psi}) $&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;While&lt;/strong&gt; stopping criteria not met:
    &lt;ol&gt;
      &lt;li&gt;&lt;strong&gt;Laplace Step&lt;/strong&gt;:
        &lt;ul&gt;
          &lt;li&gt;Compute $ \hat{\boldsymbol{\eta}}^{(k)} = 	\text{arg} max f(\boldsymbol{\eta}) $&lt;/li&gt;
          &lt;li&gt;Evaluate $ \Sigma^{(k)} = -[\nabla^2 f(\hat{\boldsymbol{\eta}}^{(k)})]^{-1} $&lt;/li&gt;
          &lt;li&gt;Non-Conjugate Update: $ q^{(k)}(\boldsymbol{\eta}) = \mathcal{N}(\hat{\boldsymbol{\eta}}^{(k)}, \Sigma^{(k)}) $&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Delta Step&lt;/strong&gt;:
        &lt;ul&gt;
          &lt;li&gt;For all required $ g $, compute:
            $\mathbb{E}[g(\boldsymbol{\eta})] \approx g(\hat{\boldsymbol{\eta}}^{(k)}) + \frac{1}{2} \text{tr}[ \nabla^2 g(\hat{\boldsymbol{\eta}}^{(k)})  \Sigma^{(k)} ] $&lt;/li&gt;
          &lt;li&gt;Conjugate Update: Use the previous quantity to update $ q^{(k)}(\boldsymbol{\psi}) $&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;Original VB-LD paper: &lt;a href=&quot;https://arxiv.org/abs/1209.4360&quot;&gt;Wang &amp;amp; Blei (2013)&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
  </entry>
  
  <entry>
    <title>Statistical Computing: A tutorial for UCSC Graduate Students</title>
    <link href="https://antonio-de-leon.com/2025/02/16/HB-Tutorial/"/>
    <updated>2025-02-16T00:00:00+00:00</updated>
    <id>https://antonio-de-leon.com/2025/02/16/HB-Tutorial</id>
    <content type="html">&lt;p&gt;Hi, grads! Whether you’re running Bayesian models, tuning machine learning algorithms, or analyzing massive datasets, this guide aims to help you take advantage of the full potential of UCSC’s &lt;strong&gt;Hummingbird (HB) clusters&lt;/strong&gt;.&lt;/p&gt;

&lt;h3 id=&quot;what-are-the-hummingbird-clusters&quot;&gt;What Are the Hummingbird Clusters?&lt;/h3&gt;
&lt;p&gt;The HB clusters are UCSC’s shared high-performance computing (HPC) systems, built to handle tasks that would overwhelm personal computers. Designed for researchers across disciplines, they offer:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Parallel computing&lt;/strong&gt;: Run thousands of simulations or MCMC chains simultaneously&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;High-speed storage&lt;/strong&gt;: Process TB-scale datasets (e.g., genomics, climate models)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Specialized hardware&lt;/strong&gt;: Access GPU nodes for deep learning&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Transition seamlessly from small interactive tests to large batch jobs&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;who-should-use-hb&quot;&gt;Who Should Use HB?&lt;/h3&gt;
&lt;p&gt;These clusters are ideal for statistical work requiring:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Computational intensity&lt;/strong&gt;: Hierarchical models, bootstrapping, or optimization&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reproducibility&lt;/strong&gt;: Version-controlled environments for collaborative projects&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Speed&lt;/strong&gt;: Accelerate workflows that take days on a laptop&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;whats-in-this-guide&quot;&gt;What’s in This Guide?&lt;/h3&gt;
&lt;p&gt;You’ll learn to:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Test code interactively&lt;/strong&gt; (e.g., debug an RStan model)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Submit batch jobs&lt;/strong&gt; (e.g., parallelize 100 MCMC chains)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Optimize resources&lt;/strong&gt; (avoid memory crashes, leverage GPUs)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Manage workflows&lt;/strong&gt; (from data storage to result analysis)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;introduction-to-cluster-computing-for-stats-grads&quot;&gt;Introduction to Cluster Computing for Stats Grads&lt;/h2&gt;

&lt;h3 id=&quot;brief-glossary&quot;&gt;Brief Glossary:&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Node&lt;/strong&gt;: Dedicated server (128 cores/256GB RAM typical) - Think of it as a powerful workstation&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Core&lt;/strong&gt;: Individual processing unit (Like a CPU thread) - Your basic computation unit&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;GPU Node&lt;/strong&gt;: Specialized nodes with 4  NVIDIA A100 GPUs (80GB VRAM each) for deep learning&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scratch Space&lt;/strong&gt;: 1PB high-speed temporary storage (Auto-cleaned every 14 days) - Perfect for intermediate results&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;i-interactive-development-sessions&quot;&gt;I. Interactive Development Sessions&lt;/h2&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
  &lt;strong&gt;When to Use Interactive:&lt;/strong&gt;  
  &lt;ul&gt;
    &lt;li&gt;Debugging code&lt;/li&gt;
    &lt;li&gt;Exploratory analysis&lt;/li&gt;
    &lt;li&gt;Small simulations&lt;/li&gt;
    &lt;li&gt;Model prototyping&lt;/li&gt;
    &lt;li&gt;Visualization&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;h3 id=&quot;example-1-debugging-bayesian-models-in-r&quot;&gt;Example 1: Debugging Bayesian Models in R&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Request interactive resources: 4 cores, 8GB RAM for 2 hours&lt;/span&gt;
srun &lt;span class=&quot;nt&quot;&gt;--pty&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--mem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;8G &lt;span class=&quot;nt&quot;&gt;--cpus-per-task&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;4 &lt;span class=&quot;nt&quot;&gt;--time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;02:00:00 bash

&lt;span class=&quot;c&quot;&gt;# Load R environment with Bayesian stack&lt;/span&gt;
module load R/4.3.0

&lt;span class=&quot;c&quot;&gt;# Start R session with debugging capabilities&lt;/span&gt;
R
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; library&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;rstan&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;          &lt;span class=&quot;c&quot;&gt;# Load STAN interface&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; debug&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;fit_model&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;        &lt;span class=&quot;c&quot;&gt;# Set breakpoint in function&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;hierarchical_bayes.R&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c&quot;&gt;# Run script until breakpoint&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; where                  &lt;span class=&quot;c&quot;&gt;# Show call stack when breakpoint hits&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;example-2-interactive-ml-development-with-jupyter&quot;&gt;Example 2: Interactive ML Development with Jupyter&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Request heavier resources for data e ploration: 8 cores, 16GB RAM&lt;/span&gt;
srun &lt;span class=&quot;nt&quot;&gt;--pty&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--mem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;16G &lt;span class=&quot;nt&quot;&gt;--cpus-per-task&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;8 &lt;span class=&quot;nt&quot;&gt;--time&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;04:00:00 bash

&lt;span class=&quot;c&quot;&gt;# Load Python environment&lt;/span&gt;
module load python/3.11

&lt;span class=&quot;c&quot;&gt;# Start Jupyter Lab on cluster (no local browser)&lt;/span&gt;
python &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; jupyter lab &lt;span class=&quot;nt&quot;&gt;--no-browser&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--port&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;8889

&lt;span class=&quot;c&quot;&gt;# On your local machine, create SSH tunnel:&lt;/span&gt;
ssh &lt;span class=&quot;nt&quot;&gt;-L&lt;/span&gt; 8889:localhost:8889 cruzid@hb.ucsc.edu
&lt;span class=&quot;c&quot;&gt;# Now access via http://localhost:8889 in local browser&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;ii-batch-processing-for-production-workloads&quot;&gt;II. Batch Processing for Production Workloads&lt;/h2&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
  &lt;strong&gt;When to Use Batch Processing:&lt;/strong&gt;  
  &lt;ul&gt;
    &lt;li&gt;Long-running computations (&amp;gt;4 hours)&lt;/li&gt;
    &lt;li&gt;Parameter sweeps/optimization runs&lt;/li&gt;
    &lt;li&gt;Production model training/inference&lt;/li&gt;
    &lt;li&gt;Final analyses requiring full resources&lt;/li&gt;
    &lt;li&gt;Reproducible pipeline executions&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;h3 id=&quot;example-1-large-scale-bayesian-inference&quot;&gt;Example 1: Large-Scale Bayesian Inference&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --job-name=stan_meta          # Job identifier&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --output=mcmc_%A_%a.log       # Log file template (JobID_ArrayID)&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --array=1-100                 # Parallelize 100 independent chains&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --cpus-per-task=4             # 4 cores per chain (for within-chain parallel)&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --mem=16G                     # 16GB RAM per chain&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --time=24:00:00               # 24hr ma  runtime&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Load environment&lt;/span&gt;
module load R/4.3.0

&lt;span class=&quot;c&quot;&gt;# Run STAN model with chain-specific data&lt;/span&gt;
Rscript run_stan.R &lt;span class=&quot;nt&quot;&gt;--model&lt;/span&gt; hierarchical &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                  &lt;span class=&quot;nt&quot;&gt;--data&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;SLURM_ARRAY_TASK_ID&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt; 
                  &lt;span class=&quot;nt&quot;&gt;--iter&lt;/span&gt; 5000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;example-2-distributed-ml-training&quot;&gt;Example 2: Distributed ML Training&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --job-name= gb_ensemble       # Job name&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --nodes=2                     # Use 2 physical servers&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --ntasks-per-node=16          # 32 total tasks (16 per node)&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --mem=128G                    # 128GB total RAM (64GB/node)&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --time=48:00:00               # 2-day ma  runtime&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#SBATCH --gres=gpu:2                  # Request 2 GPUs per node&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Load ML environment&lt;/span&gt;
module load python/3.11

&lt;span class=&quot;c&quot;&gt;# Train  GBoost ensemble with cross-validation&lt;/span&gt;
python train_ensemble.py &lt;span class=&quot;nt&quot;&gt;--n-estimators&lt;/span&gt; 1000 &lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt; &lt;span class=&quot;c&quot;&gt;# 1000 trees&lt;/span&gt;
                        &lt;span class=&quot;nt&quot;&gt;--depth-range&lt;/span&gt; 3-10 &lt;span class=&quot;se&quot;&gt;\ &lt;/span&gt;  &lt;span class=&quot;c&quot;&gt;# Search depth 3-10&lt;/span&gt;
                        &lt;span class=&quot;nt&quot;&gt;--gpu&lt;/span&gt;                  &lt;span class=&quot;c&quot;&gt;# Enable GPU acceleration&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;reproducible-environment-setup&quot;&gt;Reproducible Environment Setup&lt;/h2&gt;

&lt;h3 id=&quot;statistical-computing-environments&quot;&gt;Statistical Computing Environments&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# R: Create project-specific environment with renv&lt;/span&gt;
module load R/4.3.0
R &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;renv::init()&quot;&lt;/span&gt;            &lt;span class=&quot;c&quot;&gt;# Initialize project&lt;/span&gt;
R &lt;span class=&quot;nt&quot;&gt;-e&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;renv::install(&apos;brms&apos;)&quot;&lt;/span&gt;   &lt;span class=&quot;c&quot;&gt;# Install Bayesian regression models&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# Python: Lock dependencies with conda-lock&lt;/span&gt;
module load miniconda3
conda create &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; stats_proj &lt;span class=&quot;nv&quot;&gt;python&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;3.11  &lt;span class=&quot;c&quot;&gt;# New environment&lt;/span&gt;
conda &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; stats_proj numpy pandas scikit-learn  &lt;span class=&quot;c&quot;&gt;# Core stack&lt;/span&gt;
conda-lock lock &lt;span class=&quot;nt&quot;&gt;--file&lt;/span&gt; environment.yml &lt;span class=&quot;nt&quot;&gt;--platform&lt;/span&gt; linu &lt;span class=&quot;nt&quot;&gt;-64&lt;/span&gt;  &lt;span class=&quot;c&quot;&gt;# Create reproducible lockfile&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;green-box &quot;&gt;
 &lt;strong&gt;Big Data Best Practices&lt;/strong&gt;
 &lt;ul&gt;
   &lt;li&gt;&lt;u&gt;Chunked Processing:&lt;/u&gt; Use dask.dataframe.read_csv(chunksize=1e6) for memory-efficient ETL&lt;/li&gt;
   &lt;li&gt;&lt;u&gt;Memory Mapping:&lt;/u&gt; numpy.memmap(&apos;large_array.npy&apos;) for out-of-core 100GB+ arrays&lt;/li&gt;
   &lt;li&gt;&lt;u&gt;Columnar Storage:&lt;/u&gt; pd.read_parquet(&apos;data.parquet&apos;) for fast I/O of structured data&lt;/li&gt;
 &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;red-box &quot;&gt;
 &lt;strong&gt;Pro Tip:&lt;/strong&gt; Always test workflows interactively before submitting batch jobs!
 &lt;ul&gt;
   &lt;li&gt;Validate data loading in small sessions&lt;/li&gt;
   &lt;li&gt;Profile memory usage with RStudio/python -m memory_profiler&lt;/li&gt;
   &lt;li&gt;Test single array job element before full submission&lt;/li&gt;
 &lt;/ul&gt;
&lt;/div&gt;

&lt;h2 id=&quot;performance-optimization-guide&quot;&gt;Performance Optimization Guide&lt;/h2&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
 &lt;strong&gt;Understanding Cluster Resources&lt;/strong&gt;
 &lt;ul&gt;
   &lt;li&gt;All compute happens on &lt;u&gt;remote servers&lt;/u&gt; - your laptop just submits jobs&lt;/li&gt;
   &lt;li&gt;Storage paths like /hb/home are &lt;u&gt;network-mounted&lt;/u&gt; - accessible from all nodes&lt;/li&gt;
   &lt;li&gt;Always test scripts with small resources first!&lt;/li&gt;
 &lt;/ul&gt;
&lt;/div&gt;

&lt;h3 id=&quot;memory-management-essentials&quot;&gt;Memory Management Essentials&lt;/h3&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# For R: Profile memory usage with Valgrind&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# This creates detailed memory usage reports&lt;/span&gt;
module load R/4.3.0
R &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;valgrind --tool=massif&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; bayesian_analysis.R
&lt;span class=&quot;c&quot;&gt;# After running, analyze with:&lt;/span&gt;
ms_print massif.out.&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; memory_report.txt

&lt;span class=&quot;c&quot;&gt;# For Python: Track memory allocation&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# First install memory profiler in your environment&lt;/span&gt;
pip &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;memray
&lt;span class=&quot;c&quot;&gt;# Run profiling and generate report&lt;/span&gt;
python &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; memray run &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; profile.bin ml_pipeline.py
python &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; memray stats &lt;span class=&quot;nt&quot;&gt;--json&lt;/span&gt; profile.bin &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; memory_stats.json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;green-box&quot;&gt;
 &lt;strong&gt;Why Memory Matters:&lt;/strong&gt;
 &lt;ul&gt;
   &lt;li&gt;Jobs exceeding requested memory get &lt;u&gt;automatically killed&lt;/u&gt;&lt;/li&gt;
   &lt;li&gt;Use 10-20% less than node maximums for safety&lt;/li&gt;
   &lt;li&gt;Monitor memory during runs with &lt;code&gt;seff JOBID&lt;/code&gt;&lt;/li&gt;
 &lt;/ul&gt;
&lt;/div&gt;

&lt;h3 id=&quot;parallel-computing-patterns-explained&quot;&gt;Parallel Computing Patterns Explained&lt;/h3&gt;

&lt;table&gt;
 &lt;tr&gt;
   &lt;th&gt;Method&lt;/th&gt;
   &lt;th&gt;SLURM Directives&lt;/th&gt;
   &lt;th&gt;When to Use&lt;/th&gt;
   &lt;th&gt;Example Command&lt;/th&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
   &lt;td&gt;Embarrassing Parallel&lt;/td&gt;
   &lt;td&gt;--array=1-100&lt;/td&gt;
   &lt;td&gt;Independent tasks (Bootstrap/permutation tests)&lt;/td&gt;
   &lt;td&gt;&lt;code&gt;sbatch --array=1-100 job.sh&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
   &lt;td&gt;MPI (Message Passing)&lt;/td&gt;
   &lt;td&gt;--nodes=4 --ntasks-per-node=16&lt;/td&gt;
   &lt;td&gt;Inter-process communication (Gibbs sampling)&lt;/td&gt;
   &lt;td&gt;&lt;code&gt;mpirun -np 64 ./model&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
   &lt;td&gt;Multithreading&lt;/td&gt;
   &lt;td&gt;--cpus-per-task=32&lt;/td&gt;
   &lt;td&gt;Shared-memory tasks (XGBoost/CV tuning)&lt;/td&gt;
   &lt;td&gt;&lt;code&gt;export OMP_NUM_THREADS=32&lt;/code&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;

&lt;div class=&quot;green-box&quot;&gt;
 &lt;strong&gt;Key Concept:&lt;/strong&gt; Always match parallel method to your algorithm:
 &lt;ul&gt;
   &lt;li&gt;Embarrassing Parallel: No data sharing between tasks&lt;/li&gt;
   &lt;li&gt;MPI: Needs data exchange between processes&lt;/li&gt;
   &lt;li&gt;Multithreading: Single process with multiple threads&lt;/li&gt;
 &lt;/ul&gt;
&lt;/div&gt;

&lt;h2 id=&quot;getting-help-with-hpc&quot;&gt;Getting Help with HPC&lt;/h2&gt;

&lt;div class=&quot;green-box&quot;&gt;
 &lt;strong&gt;Cluster Support Channels&lt;/strong&gt;
 &lt;ul&gt;
   &lt;li&gt;Email Support: hummmingbird@ucsc.edu&lt;/li&gt;
   &lt;li&gt;Slack Channel: &lt;a href=&quot;https://join.slack.com/t/ucschummingbi-lph3072/shared_invite/zt-19mbwqvx1-GqguQcumVBLss~nzjOHAYg&quot;&gt;Link&lt;/a&gt; &lt;/li&gt;
   &lt;li&gt;Documentation at  &lt;a href=&quot;https://hummingbird.ucsc.edu/docs&quot;&gt;https://hummingbird.ucsc.edu/docs&lt;/a&gt; &lt;/li&gt;
 &lt;/ul&gt;
&lt;/div&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Check job efficiency - run this while job is active&lt;/span&gt;
seff &lt;span class=&quot;si&quot;&gt;$(&lt;/span&gt;squeue &lt;span class=&quot;nt&quot;&gt;-u&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$USER&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-h&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; %i&lt;span class=&quot;si&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Look for:&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# - CPU Utilization: Should be &amp;gt;90% for good efficiency&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# - Memory Usage: Should be &amp;lt; requested amount&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;red-box&quot;&gt;
 &lt;strong&gt;Avoid These Common Mistakes&lt;/strong&gt;
 &lt;ul&gt;
   &lt;li&gt;&lt;u&gt;Memory Overallocation:&lt;/u&gt;&lt;br /&gt;
   Bad: &lt;code&gt;--mem=256G&lt;/code&gt; (max is 256GB/node)&lt;br /&gt;
   Good: &lt;code&gt;--mem=230G&lt;/code&gt; (leave 10% margin)&lt;/li&gt;
   
   &lt;li&gt;&lt;u&gt;Ignoring Error Logs:&lt;/u&gt;&lt;br /&gt;
   Always check &lt;code&gt;slurm-JOBID.err&lt;/code&gt; after failures&lt;/li&gt;
   
   &lt;li&gt;&lt;u&gt;Local Installs:&lt;/u&gt;&lt;br /&gt;
   Never use &lt;code&gt;pip install --user&lt;/code&gt; - it can break cluster environments&lt;/li&gt;
 &lt;/ul&gt;
&lt;/div&gt;

</content>
  </entry>
  
  <entry>
    <title>The Energy Score for Multivariate Normal Distributions</title>
    <link href="https://antonio-de-leon.com/2025/02/12/Multivariate_CRPS/"/>
    <updated>2025-02-12T00:00:00+00:00</updated>
    <id>https://antonio-de-leon.com/2025/02/12/Multivariate_CRPS</id>
    <content type="html">&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;The Energy Score serves as the multivariate extension of the Continuous Ranked Probability Score (CRPS), maintaining its desirable properties while handling vector-valued forecasts. This post presents the closed-form expression for multivariate normal distributions and its connection to classical CRPS results.&lt;/p&gt;

&lt;div class=&quot;green-box&quot;&gt;
&lt;strong&gt;Insight:&lt;/strong&gt;  
&lt;li&gt;The Energy Score generalizes CRPS through expectations of pairwise distances, avoiding direct integration over multivariate CDFs&lt;/li&gt;
&lt;li&gt;Special function relationships enable closed-form solutions for normal distributions&lt;/li&gt;
&lt;/div&gt;

&lt;h2 id=&quot;energy-score-definition&quot;&gt;Energy Score: Definition&lt;/h2&gt;

&lt;p&gt;For a $d$-dimensional forecast distribution $P$ and observation vector $\mathbf{y} \in \mathbb{R}^d$:&lt;/p&gt;

\[\text{ES}(P, \mathbf{y}) = \mathbb{E}\left[\|\mathbf{X} - \mathbf{y}\|\right] - \frac{1}{2} \mathbb{E}\left[\|\mathbf{X} - \mathbf{X&apos;}\|\right]\]

&lt;p&gt;where $\mathbf{X}, \mathbf{X’} \sim P$ are independent random vectors.&lt;/p&gt;

&lt;h2 id=&quot;the-multivariate-normal-case&quot;&gt;The Multivariate Normal Case&lt;/h2&gt;

&lt;p&gt;For $P = \mathcal{N}_d(\boldsymbol{\mu}, \mathbf{\Sigma})$ and observation $\mathbf{y}$:&lt;/p&gt;

\[\text{ES}(P, \mathbf{y}) = \sqrt{2\text{tr}(\mathbf{\Sigma})} \cdot \frac{\Gamma\left(\frac{d+1}{2}\right)}{\Gamma\left(\frac{d}{2}\right)} \left[ {}_1F_1\left(-\frac{1}{2}; \frac{d}{2}; -\frac{\delta^2}{2}\right) - 1 \right]\]

&lt;p&gt;&lt;strong&gt;Components&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;$\delta^2 = (\boldsymbol{\mu} - \mathbf{y})^\top \mathbf{\Sigma}^{-1} (\boldsymbol{\mu} - \mathbf{y})$ (Mahalanobis distance squared)&lt;/li&gt;
  &lt;li&gt;${}_1F_1$: Confluent hypergeometric function&lt;/li&gt;
  &lt;li&gt;$\Gamma$: Gamma function&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
&lt;strong&gt;Practical Note:&lt;/strong&gt;  
&lt;li&gt;Requires special function implementations (e.g., scipy.special.hyp1f1)&lt;/li&gt;
&lt;li&gt;Reduces to familiar CRPS when $d=1$&lt;/li&gt;
&lt;/div&gt;

&lt;h2 id=&quot;special-cases&quot;&gt;Special Cases&lt;/h2&gt;

&lt;h3 id=&quot;isotropic-covariance&quot;&gt;Isotropic Covariance&lt;/h3&gt;

&lt;p&gt;When $\mathbf{\Sigma} = \sigma^2\mathbf{I}_d$:&lt;/p&gt;

\[\text{ES}(P, \mathbf{y}) = \sqrt{2d}\sigma \cdot \frac{\Gamma\left(\frac{d+1}{2}\right)}{\Gamma\left(\frac{d}{2}\right)} \left[ {}_1F_1\left(-\frac{1}{2}; \frac{d}{2}; -\frac{\|\boldsymbol{\mu} - \mathbf{y}\|^2}{2\sigma^2}\right) - 1 \right]\]

&lt;h3 id=&quot;univariate-case-classical-crps&quot;&gt;Univariate Case (Classical CRPS)&lt;/h3&gt;

&lt;p&gt;For $P = \mathcal{N}(\mu, \sigma^2)$ and observation $y$:&lt;/p&gt;

\[\text{CRPS}(P, y) = \sigma \left[ z(2\Phi(z) - 1) + \sqrt{\frac{2}{\pi}}(e^{-z^2/2} - 1) \right]\]

&lt;p&gt;where $z = \frac{y - \mu}{\sigma}$ and $\Phi$ is the standard normal CDF.&lt;/p&gt;

&lt;h2 id=&quot;computational-approaches&quot;&gt;Computational Approaches&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Component&lt;/th&gt;
      &lt;th&gt;Implementation Strategy&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;${}_1F_1$ function&lt;/td&gt;
      &lt;td&gt;scipy.special.hyp1f1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Gamma functions&lt;/td&gt;
      &lt;td&gt;Standard math libraries&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;High-dimensional cases&lt;/td&gt;
      &lt;td&gt;Monte Carlo sampling&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;div class=&quot;green-box&quot;&gt;
&lt;strong&gt;Implementation Suggestion:&lt;/strong&gt;  
&lt;li&gt;For d &amp;gt; 3, consider Monte Carlo approximation:&lt;/li&gt;
$$
\text{ES}(P, \mathbf{y}) \approx \frac{1}{N}\sum_{i=1}^N \|\mathbf{X}_i - \mathbf{y}\| - \frac{1}{2N^2}\sum_{i,j=1}^N \|\mathbf{X}_i - \mathbf{X}_j\|
$$
&lt;/div&gt;

&lt;h2 id=&quot;proof-sketch&quot;&gt;Proof Sketch&lt;/h2&gt;

&lt;h3 id=&quot;key-steps&quot;&gt;Key Steps&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Non-central Chi Distribution&lt;/strong&gt;: $|\mathbf{X}-\mathbf{y}|$ follows a non-central chi distribution&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Central Chi Moments&lt;/strong&gt;: $\mathbb{E}[|\mathbf{X}-\mathbf{X’}|]$ uses central chi properties&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hypergeometric Connection&lt;/strong&gt;: Relate Bessel functions to ${}_1F_1$ through series expansions&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;technical-lemma&quot;&gt;Technical Lemma&lt;/h3&gt;

&lt;p&gt;For $\mathbf{V} \sim \mathcal{N}_d(\boldsymbol{\nu}, \mathbf{\Omega})$:&lt;/p&gt;

\[\mathbb{E}[\|\mathbf{V}\|] = \sqrt{2\text{tr}(\mathbf{\Omega})} \cdot \frac{\Gamma\left(\frac{d+1}{2}\right)}{\Gamma\left(\frac{d}{2}\right)} \cdot {}_1F_1\left(-\frac{1}{2}; \frac{d}{2}; -\frac{\boldsymbol{\nu}^\top \mathbf{\Omega}^{-1} \boldsymbol{\nu}}{2}\right)\]

&lt;h2 id=&quot;comments&quot;&gt;Comments&lt;/h2&gt;

&lt;p&gt;The Energy Score’s extension of CRPS to multivariate settings addresses a critical need in modern probabilistic forecasting. Where the univariate CRPS revolutionized verification of scalar forecasts [1], complex systems increasingly demand &lt;em&gt;joint calibration assessments&lt;/em&gt; of vector-valued predictions - from weather models (temperature-pressure-wind vectors) to financial risk (correlated asset returns).&lt;/p&gt;

&lt;div class=&quot;green-box&quot;&gt;
&lt;strong&gt;Some Motivations:&lt;/strong&gt;
&lt;li&gt;&lt;strong&gt;Dependency Awareness:&lt;/strong&gt; Unlike marginal CRPS averaging, the Energy Score&apos;s pairwise distance terms (𝔼‖𝐗−𝐗&apos;‖) directly penalize misrepresented correlations [2]&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Properness Preservation:&lt;/strong&gt; Maintains the CRPS&apos; crucial property of being strictly proper - forecasters can&apos;t game the system by misrepresenting uncertainties [1]&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consistency:&lt;/strong&gt; Reduces exactly to CRPS when 𝑑=1, ensuring backward compatibility&lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;While computation requires special functions (${}_1F_1$, Γ) or Monte Carlo methods, this cost reflects the intrinsic complexity of multivariate dependence structures. As shown in [3], alternative scores like the variogram score make different tradeoffs, but the Energy Score remains uniquely tied to the CRPS.&lt;/p&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
&lt;strong&gt;Implementation Insight:&lt;/strong&gt;  
&lt;li&gt;For high-𝑑 systems, the hypergeometric term ${}_1F_1(−1/2;𝑑/2;−𝛿^2/2)$ approaches $e^{−𝛿^2/(2𝑑)}$ - suggestion some interesting  connections to Gaussian kernels in RKHS theory [2]&lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;As multivariate probabilistic AI/ML systems proliferate, the Energy Score provides a principled verification framework - one that honors the CRPS’ “properness” philosophy.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://doi.org/10.1198/016214506000001437&quot;&gt;Gneiting, T., &amp;amp; Raftery, A. E. (2007). Strictly proper scoring rules, prediction, and estimation. &lt;em&gt;JASA&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://doi.org/10.1016/j.jspi.2013.03.018&quot;&gt;Székely, G. J., &amp;amp; Rizzo, M. L. (2013). Energy statistics: A class of statistics based on distances. &lt;em&gt;JSPI&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://doi.org/10.1016/j.apenergy.2012.05.010&quot;&gt;Pinson, P., &amp;amp; Girard, R. (2012). Evaluating the quality of scenarios of short-term wind power generation. &lt;em&gt;Applied Energy&lt;/em&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
</content>
  </entry>
  
  <entry>
    <title>On Bayesian Methodology. Part 6/6</title>
    <link href="https://antonio-de-leon.com/2024/12/19/statistics-bayesian-methods_6/"/>
    <updated>2024-12-19T00:00:00+00:00</updated>
    <id>https://antonio-de-leon.com/2024/12/19/statistics-bayesian-methods_6</id>
    <content type="html">&lt;h2 id=&quot;final-comments&quot;&gt;Final Comments&lt;/h2&gt;

&lt;h3 id=&quot;different-perspectives-on-statistical-modeling-and-prediction&quot;&gt;Different Perspectives on Statistical Modeling and Prediction&lt;/h3&gt;
&lt;p&gt;Statistical modeling and prediction can be approached from several perspectives, each with unique goals and implications:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Traditional Statistical Perspective:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Models are typically predefined, and the goal is to accurately summarize the posterior distribution.&lt;/li&gt;
      &lt;li&gt;Computation continues until approximate convergence is achieved, with approximations used sparingly.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Machine Learning Perspective:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;The primary focus is on prediction rather than parameter estimation.&lt;/li&gt;
      &lt;li&gt;Computation halts once cross-validation accuracy plateaus, emphasizing scalability and efficiency within a fixed computational budget.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Model Exploration Perspective:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Applied statistical work often involves trying out many models, some of which may exhibit poor data fit, low predictive performance, or slow convergence.&lt;/li&gt;
      &lt;li&gt;Approximations are more acceptable here but must faithfully reproduce key posterior features.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;green-box&quot;&gt;
  &lt;strong&gt;Key Insight:&lt;/strong&gt;  
 &lt;li&gt; The distinction here is not between inference vs. prediction or exploratory vs. confirmatory analysis, but rather how much trust is placed in a model and how computation approximates it. &lt;/li&gt;
&lt;/div&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
  &lt;strong&gt;Model Trust:&lt;/strong&gt;  
 &lt;li&gt;  The process of iterative model building highlights how much computation and model development rely on trust in individual models and their approximations. &lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;These differing perspectives influence how statistical methods evolve as new challenges emerge in applied settings.&lt;/p&gt;

&lt;h3 id=&quot;justification-of-iterative-model-building&quot;&gt;Justification of Iterative Model Building&lt;/h3&gt;
&lt;p&gt;The iterative model-building process is central to modern Bayesian Workflows and represents the next transformative step in data science:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Historical Progression:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Data Summarization:&lt;/strong&gt; The foundation of statistics up to 1900.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Modeling:&lt;/strong&gt; Began with Gauss and Laplace, continuing to this day.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Computation:&lt;/strong&gt; The current focus, enabling iterative workflows and complex modeling.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Real-World Considerations:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;A Bayesian Workflow acknowledges the limitations of human and computational resources.&lt;/li&gt;
      &lt;li&gt;The goal is to simplify processes for humans, even in idealized settings where exact computation is automated.&lt;/li&gt;
      &lt;li&gt;Fully automated computation yielding perfect results remains unattainable.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;green-box&quot;&gt;
  &lt;strong&gt;Simplifying Challenges:&lt;/strong&gt;   
  &lt;li&gt; Computational challenges are easier to address when fewer &quot;moving parts&quot; exist in the modeling process. &lt;/li&gt;
&lt;/div&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;model-selection-and-overfitting&quot;&gt;Model Selection and Overfitting&lt;/h3&gt;
&lt;p&gt;An iterative workflow risks overfitting, as model improvement often involves conditioning on data discrepancies:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Double Dipping:&lt;/strong&gt; Using data multiple times during model iteration can compromise the frequency properties of inferences.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;red-box&quot;&gt;
&lt;strong&gt;Warning:&lt;/strong&gt;  
  &lt;li&gt; Double dipping and post-selection inference can lead to overfitting. Model improvement conditioned on discrepancies must be carefully managed. &lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Garden of Forking Paths:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The model-building process often involves paths that depend on the specific data observed.&lt;/li&gt;
  &lt;li&gt;Instead of selecting the best-fitting model, a Bayesian Workflow emphasizes iterative improvements, ensuring each step is justified.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;blue-box&quot;&gt;
&lt;strong&gt;Example:&lt;/strong&gt;  
 &lt;li&gt;  Suppose model \(M_1\) fails a posterior predictive check, leading to the development of \(M_2\), which incorporates more prior information and better fits the data. Had the data differed, \(M_1\) might have sufficed. This highlights the iterative nature of a Bayesian Workflow. &lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;To mitigate post-selection inference issues:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Embed multiple models in a larger framework.&lt;/li&gt;
  &lt;li&gt;Use predictive model averaging or incorporate all models simultaneously.&lt;/li&gt;
  &lt;li&gt;Perform severe tests of the assumptions underlying each model.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;bigger-datasets-demand-bigger-models&quot;&gt;Bigger Datasets Demand Bigger Models&lt;/h3&gt;
&lt;p&gt;Larger datasets enable the fitting of complex models, such as hierarchical Bayesian models and deep learning approaches:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;These models facilitate information aggregation and partial pooling across diverse data sources.&lt;/li&gt;
  &lt;li&gt;Effective modeling requires:
    &lt;ol&gt;
      &lt;li&gt;&lt;strong&gt;Regularization:&lt;/strong&gt; To stabilize estimates.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Latent Variable Modeling:&lt;/strong&gt; To address missingness and measurement errors.&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
&lt;strong&gt;Insight:&lt;/strong&gt;  
  &lt;li&gt; A model does not exist in isolation; it emerges from engagement with the application and available data. &lt;/li&gt;
&lt;/div&gt;

&lt;h3 id=&quot;prediction-generalization-and-poststratification&quot;&gt;Prediction, Generalization, and Poststratification&lt;/h3&gt;
&lt;p&gt;Statistical tasks often involve generalization, which Bayesian methods address effectively:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Generalizing from Sample to Population:&lt;/strong&gt; Using hierarchical models and partial pooling.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Generalizing from Control to Treatment Groups:&lt;/strong&gt; Leveraging regularization to handle large nonparametric models.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Generalizing from Observed Data to Underlying Constructs:&lt;/strong&gt; Applying multilevel modeling for latent variables.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;green-box&quot;&gt;
&lt;strong&gt;Key Principle:&lt;/strong&gt;  
  &lt;li&gt; Just as priors are understood in the context of the likelihood, models should be understood in light of their intended use. &lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Methods in Bayesian Framework:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hierarchical modeling and transportability via Bayesian graph models.&lt;/li&gt;
  &lt;li&gt;Regularization to handle complex, large-scale models.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The iterative nature of Bayesian Workflow, with its emphasis on model trust, computational efficiency, and careful navigation of overfitting risks, reflects the dynamic and evolving nature of modern statistical practice. By embedding models within a larger framework and embracing the iterative process, a Bayesian Workflow ensures robust and insightful statistical analyses.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>On Bayesian Methodology. Part 5/6</title>
    <link href="https://antonio-de-leon.com/2024/12/02/statistics-bayesian-methods_5/"/>
    <updated>2024-12-02T00:00:00+00:00</updated>
    <id>https://antonio-de-leon.com/2024/12/02/statistics-bayesian-methods_5</id>
    <content type="html">&lt;h2 id=&quot;vii-understanding-and-comparing-multiple-models&quot;&gt;VII. Understanding and Comparing Multiple Models&lt;/h2&gt;

&lt;h3 id=&quot;visualizing-models-in-relation-to-each-other&quot;&gt;Visualizing Models in Relation to Each Other&lt;/h3&gt;
&lt;p&gt;A key aspect of a Bayesian Workflow is fitting multiple models for a single problem. This process is not about selecting the best model or averaging models, but rather using a series of fitted models to gain a deeper understanding of each one.&lt;/p&gt;

&lt;div class=&quot;red-box&quot;&gt;
  &lt;strong&gt;Remark:&lt;/strong&gt;  
  &lt;li&gt; Model comparison in this context is not about selecting or averaging but about exploring the &lt;strong&gt;process&lt;/strong&gt; of fitting multiple models to understand them better. &lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Considerations When Fitting Multiple Models:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Be aware of researcher degrees of freedom:
    &lt;ul&gt;
      &lt;li&gt;Overfitting can occur if a single “best” model is chosen.&lt;/li&gt;
      &lt;li&gt;A set of fitted models might appear to bracket total uncertainty, but other unconsidered models could still contribute.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Multiverse analysis: Evaluate situations where multiple models pass all checks to ensure robustness.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;cross-validation-and-model-averaging&quot;&gt;Cross-validation and Model Averaging&lt;/h3&gt;
&lt;p&gt;Cross-validation (CV) is a powerful tool for evaluating models, but it requires careful interpretation:&lt;/p&gt;

&lt;div class=&quot;red-box&quot;&gt;
  &lt;strong&gt;Key Principle:&lt;/strong&gt;  
  &lt;li&gt; If there is significant uncertainty in model comparisons, avoid selecting the single model with the best cross-validation result. This discards the uncertainty from the CV process. &lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Alternative Approaches:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Stacking:&lt;/strong&gt;&lt;br /&gt;
Combines inferences by weighting models to minimize cross-validation error. Stacking can sometimes be seen as pointwise model selection.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Scaffold Models:&lt;/strong&gt;&lt;br /&gt;
Include models that are deliberately simple (e.g., for comparison), experimental, or flawed (e.g., with coding errors). These models serve as benchmarks or stepping stones but are not included in final predictions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While a Bayesian Workflow emphasizes continuous model expansion over averaging, there are cases where averaging predictions over competing Bayesian models is reasonable.&lt;/p&gt;

&lt;h3 id=&quot;comparing-a-large-number-of-models&quot;&gt;Comparing a Large Number of Models&lt;/h3&gt;
&lt;p&gt;When faced with many candidate models, the goal is often to find a simpler model with comparable predictive performance to a more complex, expanded model.&lt;/p&gt;

&lt;div class=&quot;red-box&quot;&gt;
  &lt;strong&gt;Warning:&lt;/strong&gt;  
  &lt;li&gt; Selecting one model based solely on minimizing cross-validation error risks overfitting and suboptimal choices. &lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Projection Predictive Variable Selection:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;A stable and reliable method to identify smaller models with strong predictive performance.&lt;/li&gt;
  &lt;li&gt;Avoids overfitting by:
    &lt;ul&gt;
      &lt;li&gt;Projecting submodels based on the expanded model’s predictions.&lt;/li&gt;
      &lt;li&gt;Not fitting each model independently to the data.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This approach enables efficient comparison of a large number of models while maintaining robust predictive performance.&lt;/p&gt;

&lt;p&gt;Understanding and comparing multiple models is an integral part of Bayesian Workflow. By focusing on the process of model fitting rather than rigid selection or averaging, practitioners can better navigate uncertainty and extract meaningful insights from their analyses. Tools like stacking and projection predictive variable selection ensure that model comparison remains both rigorous and practical.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>On Bayesian Methodology. Part 4/6</title>
    <link href="https://antonio-de-leon.com/2024/11/13/statistics-bayesian-methods_4/"/>
    <updated>2024-11-13T00:00:00+00:00</updated>
    <id>https://antonio-de-leon.com/2024/11/13/statistics-bayesian-methods_4</id>
    <content type="html">&lt;h2 id=&quot;iv-addressing-computational-problems&quot;&gt;IV. Addressing Computational Problems&lt;/h2&gt;

&lt;div class=&quot;red-box&quot;&gt;
  &lt;strong&gt;The Folk Theorem of Statistical Computing: &lt;/strong&gt;   
 &lt;li&gt; When computational problems arise, they often indicate an issue with the model itself.  &lt;/li&gt;
 &lt;li&gt; Many cases of poor convergence are tied to regions of parameter space that are either irrelevant or nonsensical. &lt;/li&gt;
  &lt;li&gt; Instead of throwing more computational resources at the problem, the first step should be to identify and address potential model pathologies. &lt;/li&gt;
&lt;/div&gt;

&lt;h3 id=&quot;starting-at-simple-and-complex-models-and-meeting-in-the-middle&quot;&gt;Starting at Simple and Complex Models and Meeting in the Middle&lt;/h3&gt;
&lt;p&gt;Diagnosing computational problems often requires a two-pronged approach:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Simplify the problematic model step by step until it works reliably.&lt;/li&gt;
  &lt;li&gt;Start with a simple, well-understood model and gradually add features until the issue reappears.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This process helps isolate the root cause of the problem.&lt;/p&gt;

&lt;h3 id=&quot;getting-a-handle-on-models-that-take-a-long-time-to-fit&quot;&gt;Getting a Handle on Models That Take a Long Time to Fit&lt;/h3&gt;
&lt;p&gt;Slow computation is often symptomatic of deeper issues, such as poorly performing Hamiltonian Monte Carlo (HMC). However, debugging becomes harder as computation times increase.&lt;br /&gt;
Key strategies include:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Viewing model choices as provisional.&lt;/li&gt;
  &lt;li&gt;Fitting multiple models to understand computational and inferential behavior in the applied problem.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;monitoring-intermediate-quantities&quot;&gt;Monitoring Intermediate Quantities&lt;/h3&gt;
&lt;p&gt;Saving and plotting intermediate quantities during computation can reveal hidden issues with the model or algorithm. These visualizations often provide valuable clues for debugging.&lt;/p&gt;

&lt;h3 id=&quot;stacking-to-reweight-poorly-mixing-chains&quot;&gt;Stacking to Reweight Poorly Mixing Chains&lt;/h3&gt;
&lt;p&gt;In situations where multiple chains mix slowly but remain within reasonable ranges, stacking can be used:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Combine simulations by assigning weights to chains through cross-validation.&lt;/li&gt;
  &lt;li&gt;Particularly useful during model exploration when diagnostics suggest some progress but full convergence remains elusive.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;posterior-distributions-with-multimodality-and-difficult-geometry&quot;&gt;Posterior Distributions with Multimodality and Difficult Geometry&lt;/h3&gt;
&lt;p&gt;Multimodality and complex posterior geometries pose significant challenges:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Disjoint Posterior Volumes:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Near-zero mass for all but one mode.&lt;/li&gt;
      &lt;li&gt;Symmetric volumes, such as label switching in mixture models.&lt;/li&gt;
      &lt;li&gt;Distinct volumes with significant probability mass.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unstable Tails:&lt;/strong&gt;&lt;br /&gt;
A single posterior volume with arithmetically unstable regions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each scenario requires tailored strategies for efficient computation.&lt;/p&gt;

&lt;h3 id=&quot;reparameterization&quot;&gt;Reparameterization&lt;/h3&gt;
&lt;p&gt;HMC-based samplers perform best when:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The mass matrix is well-tuned.&lt;/li&gt;
  &lt;li&gt;The posterior geometry is smooth, with no sharp corners or irregularities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For many classical models, results like the Bernstein-von Mises theorem simplify posterior geometry with sufficient data. When this is not the case, reparameterization can significantly improve computational performance by simplifying posterior geometry.&lt;/p&gt;

&lt;h3 id=&quot;marginalization&quot;&gt;Marginalization&lt;/h3&gt;
&lt;p&gt;Challenging geometries in posterior distributions often stem from parameter interactions. Marginalizing over certain parameters can simplify computations:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Approximations like the Laplace method can be particularly effective for latent Gaussian models.&lt;/li&gt;
  &lt;li&gt;Exploiting the structure of the problem can lead to substantial improvements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;adding-prior-information&quot;&gt;Adding Prior Information&lt;/h3&gt;
&lt;p&gt;Many computational issues can be mitigated by incorporating prior information:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Priors help address weakly informative data regions, improving model behavior without sacrificing inference quality.&lt;/li&gt;
  &lt;li&gt;While the primary purpose of priors is not to fix fitting problems, their inclusion often resolves computational challenges.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;red-box&quot;&gt;
  &lt;strong&gt;Identifiability?&lt;/strong&gt;  
  &lt;li&gt; “Identification” is an asymptotic property in classical statistics &lt;/li&gt;
  &lt;li&gt; Bayesian inference prioritizes inference with finite data. &lt;/li&gt;
  &lt;li&gt; If data are insufficient for certain aspects of the model, priors can supply the necessary information. &lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Ladder of Abstraction:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Poor mixing of MCMC.&lt;/li&gt;
  &lt;li&gt;Difficult geometry as a mathematical explanation.&lt;/li&gt;
  &lt;li&gt;Weakly informative data as a statistical explanation.&lt;/li&gt;
  &lt;li&gt;Substantive prior information as a solution.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Addressing computational issues can start at either end of this ladder, transitioning from troubleshooting to workflow optimization.&lt;/p&gt;

&lt;h3 id=&quot;adding-data&quot;&gt;Adding Data&lt;/h3&gt;
&lt;p&gt;Similar to priors, additional data can constrain models and resolve computational problems:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Incorporate new data sources into the model.&lt;/li&gt;
  &lt;li&gt;Models that work well with larger datasets may struggle in small data regimes; expanding the dataset can improve performance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Addressing computational problems in Bayesian modeling involves a combination of simplifying models, leveraging prior information, and refining computational techniques. A systematic approach, starting with diagnostics and iterative improvements, ensures both model reliability and computational efficiency.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;v-evaluating-and-using-a-fitted-model&quot;&gt;V. Evaluating and Using a Fitted Model&lt;/h2&gt;

&lt;p&gt;Evaluating a fitted model involves multiple checks, each tailored to the specific goals of the analysis. The aspects of the model that require evaluation depend on the application and the intended users of the statistical methods.&lt;/p&gt;

&lt;h3 id=&quot;posterior-predictive-checking&quot;&gt;Posterior Predictive Checking&lt;/h3&gt;
&lt;p&gt;Posterior predictive checking involves simulations from the posterior distribution to evaluate model performance:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;While there’s no universal guide for which checks to perform, conducting a few direct checks can safeguard against gross misspecification.&lt;/li&gt;
  &lt;li&gt;Similarly, there’s no definitive rule for deciding when a failed check necessitates adjustments to the model.&lt;/li&gt;
  &lt;li&gt;The choice of checks depends on the analysis goals and the costs and benefits of adjustments.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;green-box&quot;&gt;
   &lt;strong&gt;Key Principle:&lt;/strong&gt;   
  &lt;li&gt; Seek “severe tests”—checks likely to fail if the model produces misleading answers to critical questions. &lt;/li&gt;
&lt;/div&gt;

&lt;h3 id=&quot;cross-validation-and-influence-of-individual-data-points&quot;&gt;Cross-Validation and Influence of Individual Data Points&lt;/h3&gt;
&lt;p&gt;Cross-validation (CV) enhances predictive diagnostics, especially for flexible models, by providing insights into model fit and data influence:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Calibration Checks:&lt;/strong&gt; Use the cross-validation predictive distribution to assess calibration.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Difficult Observations:&lt;/strong&gt; Identify observations or groups that are hard to predict.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Influence Diagnostics:&lt;/strong&gt; Examine the additional information provided by individual observations.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;Leave-one-out cross-validation (LOO-CV) is a popular method, though it doesn’t always align with inferential goals for multilevel (hierarchical) models.&lt;/li&gt;
  &lt;li&gt;Calibration insights:
    &lt;ul&gt;
      &lt;li&gt;Posterior predictive checking compares marginal prediction distributions to data.&lt;/li&gt;
      &lt;li&gt;LOO-CV predictive checking evaluates the calibration of conditional predictive distributions.&lt;/li&gt;
      &lt;li&gt;Probability integral transformations (PIT) under good calibration are uniform.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;blue-box&quot;&gt;
  &lt;strong&gt;  Practical Tip:&lt;/strong&gt;   
  &lt;li&gt; Cross-validation for multilevel models requires thoughtful implementation to ensure alignment with inferential goals. &lt;/li&gt;
&lt;/div&gt;

&lt;h3 id=&quot;influence-of-prior-information&quot;&gt;Influence of Prior Information&lt;/h3&gt;
&lt;p&gt;Understanding how prior information affects posterior inferences is essential for a robust evaluation:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;A statistical model can be understood in two ways:
    &lt;ol&gt;
      &lt;li&gt;&lt;strong&gt;Generatively:&lt;/strong&gt; Explore how parameters map to data using prior predictive simulations.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Inferentially:&lt;/strong&gt; Examine the path from inputs (data and priors) to outputs (estimates and uncertainties).&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sensitivity Analysis:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Measure shrinkage between prior and posterior distributions, such as comparing posterior standard deviations or quantiles.&lt;/li&gt;
      &lt;li&gt;Use importance sampling to approximate and compare posteriors across models.&lt;/li&gt;
      &lt;li&gt;Conduct static sensitivity analysis to study posterior sensitivity to prior perturbations without re-fitting the model.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;green-box&quot;&gt;
  &lt;strong&gt;Practical Insight:&lt;/strong&gt;   
  &lt;li&gt; Sensitivity analysis highlights the balance between prior information and data, offering valuable diagnostic insights without excessive computation. &lt;/li&gt;
&lt;/div&gt;

&lt;h3 id=&quot;summarizing-inference-and-propagating-uncertainty&quot;&gt;Summarizing Inference and Propagating Uncertainty&lt;/h3&gt;
&lt;p&gt;Traditional methods of summarizing Bayesian inference often fail to fully represent the complexity of variation and uncertainty:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tables and graphs of parameter estimates and uncertainties only capture one-dimensional margins.&lt;/li&gt;
  &lt;li&gt;Marginal posterior distribution graphs become unwieldy for models with many parameters and fail to illustrate the interplay of hierarchical model uncertainties.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Tools for Advanced Summaries:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Use visualization tools like the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bayesplot&lt;/code&gt; R package to effectively summarize and explore Bayesian inference results.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Evaluating a fitted model is a multifaceted process. It involves a combination of diagnostic checks, sensitivity analyses, and advanced visualization techniques. The goal is not just to identify potential misfits but to refine the model for better inference and predictive accuracy.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;vi-modifying-a-model&quot;&gt;VI. Modifying a Model&lt;/h2&gt;

&lt;h3 id=&quot;constructing-a-model-for-the-data&quot;&gt;Constructing a Model for the Data&lt;/h3&gt;
&lt;p&gt;Model construction is a creative process where the modeler combines existing components to account for new data, enhance features of existing data, or establish links to underlying processes.&lt;/p&gt;

&lt;div class=&quot;green-box&quot;&gt;
  &lt;strong&gt;Model Building as a Task:&lt;/strong&gt;  
  &lt;li&gt; Model construction is akin to a language-like task, where components are assembled to encompass new data, existing data features, and links to underlying processes. &lt;/li&gt;
&lt;/div&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
  &lt;strong&gt;Reasons for Model Expansion:&lt;/strong&gt;  
  &lt;li&gt; Response to new data.  &lt;/li&gt;
  &lt;li&gt; Failures of models fit to existing data.   &lt;/li&gt;
  &lt;li&gt; Computational challenges with current fitting procedures. &lt;/li&gt;
&lt;/div&gt;

&lt;h3 id=&quot;incorporating-additional-data&quot;&gt;Incorporating Additional Data&lt;/h3&gt;
&lt;p&gt;Expanding a model to include more data is a critical step in a Bayesian Workflow.&lt;br /&gt;
It’s often said that the value of a statistical method lies not just in how it handles data but in the choice of what data to use.&lt;/p&gt;

&lt;h3 id=&quot;working-with-prior-distributions&quot;&gt;Working with Prior Distributions&lt;/h3&gt;
&lt;p&gt;Traditionally, Bayesian statistics refers to noninformative or fully informative priors, but in practice, these rarely exist:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Uniform Prior:&lt;/strong&gt; Depends on parameterization, carrying implicit information.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Reference Prior:&lt;/strong&gt; Based on asymptotic regimes and fictional data assumptions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Informative Prior:&lt;/strong&gt; Rarely encompasses all available knowledge.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Ladder of Priors:&lt;/strong&gt;&lt;br /&gt;
Think of prior distributions as existing on a continuum:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Improper flat prior.&lt;/li&gt;
  &lt;li&gt;Super-vague but proper prior.&lt;/li&gt;
  &lt;li&gt;Very weakly informative prior.&lt;/li&gt;
  &lt;li&gt;Generic weakly informative prior.&lt;/li&gt;
  &lt;li&gt;Specific informative prior.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Priors also act as constraints, shrinking estimates toward simpler models. However, the need for prior information varies based on:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The role of the parameter in the model.&lt;/li&gt;
  &lt;li&gt;The parameter’s position in the hierarchy.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;red-box&quot;&gt;
  &lt;strong&gt;Critical Insight:&lt;/strong&gt;   
  Priors must be specified for each model in the workflow. Expanded models often require additional thought regarding parameterization and joint priors to avoid unintended effects like cancellations or overly stabilizing priors.
&lt;/div&gt;

&lt;p&gt;When introducing new parameters:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Consider tightening priors on overarching metrics like means and standard deviations.&lt;/li&gt;
  &lt;li&gt;Be cautious of the concentration of measure in higher-dimensional spaces.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;a-topology-of-models&quot;&gt;A Topology of Models&lt;/h3&gt;
&lt;p&gt;Models within a framework can be thought of as forming a topology or network structure. This structure reflects connections and partial orderings rather than probabilities assigned to individual models.&lt;/p&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
  &lt;strong&gt; Model Topology?:&lt;/strong&gt;    
  &lt;li&gt; A topology of models refers to their connections and relationships, not a probability space. The goal is not to average over models but to navigate among them effectively.&lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Examples of Model Navigation Tools:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Automatic Statistician:&lt;/strong&gt; Explores models in specified but open-ended classes, like time series or regression models, using inference and model criticism.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Prophet:&lt;/strong&gt; A time series forecasting tool allowing users to build models from predefined building blocks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Model Operations:&lt;/strong&gt;
Models, treated as probabilistic random variables, can be combined in multiple ways:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Additive, multiplicative, linear mixing, log-linear mixing, pointwise mixing, and more.&lt;br /&gt;
Each model has its internal structure, with parameters estimated from data, and parameters across models can interact (e.g., shared parameters).&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;blue-box&quot;&gt;
  &lt;strong&gt;Applications:&lt;/strong&gt;  
  &lt;li&gt; &lt;strong&gt;Forecasting:&lt;/strong&gt; Using interconnected models to predict future outcomes. &lt;/li&gt; 
  &lt;li&gt; &lt;strong&gt;Causal Inference:&lt;/strong&gt; Exploring relationships between variables using networked model structures. &lt;/li&gt;
&lt;/div&gt;
</content>
  </entry>
  
  <entry>
    <title>On Bayesian Methodology. Part 3/6</title>
    <link href="https://antonio-de-leon.com/2024/11/01/statistics-bayesian-methods_3/"/>
    <updated>2024-11-01T00:00:00+00:00</updated>
    <id>https://antonio-de-leon.com/2024/11/01/statistics-bayesian-methods_3</id>
    <content type="html">&lt;h2 id=&quot;iii-using-constructed-data-to-find-and-understand-problems&quot;&gt;III. Using Constructed Data to Find and Understand Problems&lt;/h2&gt;

&lt;h3 id=&quot;fake-data-simulation&quot;&gt;Fake-Data Simulation&lt;/h3&gt;
&lt;p&gt;The core idea of fake-data simulation is to test whether a procedure can recover correct parameter values when applied to simulated data. This involves the following steps:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Simulate Fake Data:&lt;/strong&gt;&lt;br /&gt;
Choose reasonable parameter values and generate a fake dataset that matches the size, structure, and shape of the original data.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Evaluate the Procedure:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Information Beyond the Prior:&lt;/strong&gt; Simulate fake data from the model using fixed, known parameters and check if the observed data adds meaningful information. Analyze point estimates and the coverage of posterior intervals.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Parameter Recovery:&lt;/strong&gt; Assess whether the true parameters are recovered within the uncertainty range implied by the fitted posterior distribution.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Behavior Across Parameter Space:&lt;/strong&gt; Explore how the model behaves in different regions of the parameter space, revealing the various “stories” the model encodes about data generation.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Two-Step Procedure:&lt;/strong&gt;&lt;br /&gt;
Fit the model to real data, draw parameters from the resulting posterior distribution, and use these parameters for fake-data checking.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&quot;red-box&quot;&gt;
  &lt;strong&gt;Key Insight:&lt;/strong&gt;  
   &lt;li&gt; If a model cannot make reliable inferences on fake data generated from itself, it’s unlikely to provide reasonable inferences on real data.  &lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;While fake-data simulations help evaluate a model’s ability to recover parameters, they also highlight potential weaknesses. For example:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Creating fake data that causes the procedure to fail can deepen understanding of an inference method.&lt;/li&gt;
  &lt;li&gt;Overparameterized models may yield comparable predictions despite wildly different parameter estimates, limiting the usefulness of predictive checks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;simulation-based-calibration-sbc&quot;&gt;Simulation-Based Calibration (SBC)&lt;/h3&gt;
&lt;p&gt;SBC provides a more comprehensive approach than truth-point benchmarking by fitting the model multiple times and comparing posterior distributions to simulated data. However, SBC has its challenges:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Computational Cost:&lt;/strong&gt; Requires significant resources to fit the model repeatedly.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Priors and Modeler Bias:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Weakly informative priors, often chosen conservatively, can lead to extreme datasets during SBC.&lt;/li&gt;
      &lt;li&gt;This mismatch can obscure insights about calibration and posterior behavior.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;purple-box&quot;&gt;
  &lt;strong&gt;Open Research Question:&lt;/strong&gt;    
  How effective is SBC with a limited number of simulations?  
&lt;/div&gt;

&lt;p&gt;Simulation-based calibration and truth-point benchmarking are complementary, with SBC offering broader insights but at a higher computational expense.&lt;/p&gt;

&lt;h3 id=&quot;experimentation-using-constructed-data&quot;&gt;Experimentation Using Constructed Data&lt;/h3&gt;
&lt;p&gt;Simulating data from different scenarios provides valuable insights into models and inference methods. This experimentation allows practitioners to:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Understand how a model performs under varying conditions.&lt;/li&gt;
  &lt;li&gt;Explore the limits of inferences by fitting the model to data generated from challenging scenarios.&lt;/li&gt;
  &lt;li&gt;Gain a deeper understanding of both computational issues and the underlying data.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;red-box&quot;&gt;
  &lt;strong&gt;Important Consideration:&lt;/strong&gt; Testing a model with a single fake dataset is not sufficient.  
   &lt;li&gt; Even if the computational algorithm works, there’s a 5% chance that a random draw will fall outside a 95% uncertainty interval. &lt;/li&gt;  
   &lt;li&gt; Bayesian inference is calibrated only when averaging over the prior.   &lt;/li&gt;
   &lt;li&gt; Parameter recovery can fail not because of algorithmic errors but due to insufficient information in the observed data.  &lt;/li&gt;
&lt;/div&gt;

&lt;p&gt;Simulation of statistical systems under diverse conditions not only addresses computational challenges but also enhances our understanding of data and inference.&lt;/p&gt;

&lt;hr /&gt;
</content>
  </entry>
  
  <entry>
    <title>On Bayesian Methodology Part. 2/6</title>
    <link href="https://antonio-de-leon.com/2024/10/11/statistics-bayesian-methods_2/"/>
    <updated>2024-10-11T00:00:00+00:00</updated>
    <id>https://antonio-de-leon.com/2024/10/11/statistics-bayesian-methods_2</id>
    <content type="html">&lt;h2 id=&quot;i-before-fitting-a-model&quot;&gt;I. Before Fitting a Model&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Choosing an Initial Model&lt;/strong&gt;&lt;br /&gt;
The starting point of almost all analyses is to adapt what has been done before. Drawing from existing methods provides a foundation for further refinement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Modular Construction&lt;/strong&gt;&lt;br /&gt;
A Bayesian model is built from &lt;strong&gt;modules&lt;/strong&gt; rather than whole models. Naming and constructing models in a modular fashion makes it easier to:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Identify connections between seemingly different models.&lt;/li&gt;
  &lt;li&gt;Adapt models to the specific requirements of an analysis project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Modules often act as placeholders, which can be replaced or expanded as necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scaling and Transforming the Parameters&lt;/strong&gt;&lt;br /&gt;
Parameters should be interpretable for both practical and ethical reasons. Transformations can make parameters more meaningful, aiding in:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Clear communication of results.&lt;/li&gt;
  &lt;li&gt;Effective use of prior information.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Prior Predictive Checking&lt;/strong&gt;&lt;br /&gt;
Prior predictive checks are invaluable for understanding the implications of prior distributions within generative models.&lt;/p&gt;

&lt;div class=&quot;green-box&quot;&gt;
  &lt;strong&gt;Key Approaches&lt;/strong&gt;  
  &lt;ul&gt;
    &lt;li&gt;Considering priors on outcomes and deriving corresponding joint priors on parameters.&lt;/li&gt;
    &lt;li&gt;Using simulations to elicit expert knowledge on measurable quantities, which is often easier than soliciting opinions on unobservable model parameters.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Generative and Partially Generative Models&lt;/strong&gt;&lt;br /&gt;
Fully Bayesian data analysis typically requires a &lt;strong&gt;generative model&lt;/strong&gt;, a joint probability distribution for all data and parameters.&lt;/p&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
  &lt;strong&gt;Insights&lt;/strong&gt;  
  &lt;ul&gt;
    &lt;li&gt;Bayesian inference does not require the generative model. It only needs the likelihood derived from the data, and different generative models can share the same likelihood.&lt;/li&gt;
    &lt;li&gt;Bayesian data analysis, however, depends on the generative model to enable predictive simulation and model checking.&lt;/li&gt;
    &lt;li&gt;The Bayesian workflow evaluates a series of generative models to improve understanding and predictions.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;p&gt;Prior and posterior predictive checks can vary under different generative models while satisfying the likelihood principle.&lt;br /&gt;
Some models commonly used in Bayesian analysis are not fully generative:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Regression models and survival data with censoring.&lt;/li&gt;
  &lt;li&gt;Models with improper priors, which lack a joint distribution for data and parameters and cannot sample from the prior predictive distribution. Improper priors often serve as placeholders on the path to a fully Bayesian model.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In applied Bayesian work, complexity often arises from incorporating multiple data sources. This necessitates balancing simplicity with flexibility in modeling.&lt;/p&gt;

&lt;div class=&quot;green-box&quot;&gt;
  &lt;strong&gt;Progression of Generative Models&lt;/strong&gt;  
  &lt;ul&gt;
    &lt;li&gt;At one extreme, non-generative methods consist solely of data summaries with no model for the data.&lt;/li&gt;
    &lt;li&gt;Classical statistical models provide probability distributions \( p(y; \theta) \) for data \( y \) given parameters \( \theta \), but no distribution for \( \theta \).&lt;/li&gt;
    &lt;li&gt;Partially generative Bayesian models include unmodeled data \( x \), such as sample sizes, design settings, or hyperparameters, represented as \( p(y, \theta \mid x) \).&lt;/li&gt;
    &lt;li&gt;Fully generative models encompass everything, represented as \( p(y, \theta, x) \), leaving no data “left out.”&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ii-fitting-a-model&quot;&gt;II. Fitting a Model&lt;/h2&gt;

&lt;p&gt;Bayesian computation has evolved significantly over time. Early methods relied on analytic calculations and normal approximations. In the 1990s, the advent of advanced algorithms expanded the landscape for exploring posterior distributions:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Gibbs and Metropolis Algorithms:&lt;/strong&gt; Enabled Bayesian inference for many models.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sequential Monte Carlo (SMC):&lt;/strong&gt; A generalization of Metropolis applicable to broader Bayesian computations.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Variational Inference (VI):&lt;/strong&gt; A fast but potentially inaccurate approximation, building on the expectation-maximization (EM) algorithm.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Hamiltonian Monte Carlo (HMC):&lt;/strong&gt; Uses gradient computations to navigate continuous probability spaces efficiently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These innovations have revolutionized Bayesian workflow, but safe usage requires strong diagnostics to flag unreliable computations.&lt;/p&gt;

&lt;h3 id=&quot;initial-values-adaptation-and-warmup&quot;&gt;Initial Values, Adaptation, and Warmup&lt;/h3&gt;
&lt;p&gt;The initial phase of inference algorithms is critical:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Initial Values:&lt;/strong&gt; While theoretically irrelevant in the asymptotic limit, poor initial values can bias results.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Warmup Phase:&lt;/strong&gt; Moves simulations from unrepresentative initial values toward the typical set, a concept in information theory. This phase serves three purposes:
    &lt;ol&gt;
      &lt;li&gt;Reduces bias from initial values.&lt;/li&gt;
      &lt;li&gt;Provides information to tune algorithm parameters.&lt;/li&gt;
      &lt;li&gt;Flags computational issues early.&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;how-long-to-run-an-iterative-algorithm&quot;&gt;How Long to Run an Iterative Algorithm&lt;/h3&gt;
&lt;p&gt;The duration of iterative algorithms like MCMC impacts result reliability and computational efficiency:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Convergence Diagnostics:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Standard practice: Run until a mixing measure, Vehtari et al. (2020), is below 1.01 for all parameters.&lt;/li&gt;
      &lt;li&gt;Monitor the multivariate mixing statistic, Lambert and Vehtari (2020).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Balancing Accuracy and Speed:&lt;/strong&gt;&lt;br /&gt;
While increasing adequate sample size or reducing Monte Carlo error improves accuracy, it limits model exploration if computation is too slow.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Leveraging Parallelism:&lt;/strong&gt;&lt;br /&gt;
Instead of increasing iterations, variance reduction can be achieved by increasing parallel chains.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;approximate-algorithms-and-models&quot;&gt;Approximate Algorithms and Models&lt;/h3&gt;
&lt;p&gt;Markov chain simulation is an approximation where theoretical error reduces with more iterations. However, scalability challenges arise as models and datasets grow larger, necessitating faster alternatives:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Techniques for Approximation:&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;Empirical Bayes&lt;/li&gt;
      &lt;li&gt;Linearization&lt;/li&gt;
      &lt;li&gt;Laplace approximation&lt;/li&gt;
      &lt;li&gt;Nested approximations (e.g., INLA)&lt;/li&gt;
      &lt;li&gt;Data-splitting (e.g., expectation propagation)&lt;/li&gt;
      &lt;li&gt;Mode-finding (e.g., variational inference)&lt;/li&gt;
      &lt;li&gt;Penalized maximum likelihood&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Diagnostics for Approximate Algorithms:&lt;/strong&gt;&lt;br /&gt;
Use diagnostic tools to ensure the algorithm reproduces key posterior features for the specific model.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;yellow-box&quot;&gt;
  &lt;strong&gt;Insights&lt;/strong&gt;: Approximate algorithms can be viewed as exact algorithms for approximate models.  
  &lt;ul&gt;
    &lt;li&gt; &lt;strong&gt;Empirical Bayes:&lt;/strong&gt;   Replaces prior distributions with data-dependent point-mass priors. &lt;/li&gt;
    &lt;li&gt; strong&amp;gt;Laplace Approximation:&amp;lt;/strong&amp;gt;   Data-dependent linearization of the model.   &lt;/li&gt;
    &lt;li&gt; &lt;strong&gt;Nested Laplace Approximation:&lt;/strong&gt;   Linearizes conditional posterior distributions.&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;h3 id=&quot;fit-fast-fail-fast&quot;&gt;Fit Fast, Fail Fast&lt;/h3&gt;
&lt;p&gt;Efficient Bayesian workflow emphasizes quickly identifying and discarding flawed models:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Failing Fast:&lt;/strong&gt; Saves time by avoiding perfect inference for fundamentally flawed models.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;red-box&quot;&gt;
  &lt;strong&gt;Fast Algorithms vs. Early Failure&lt;/strong&gt;  
  There is extensive literature on fast approximation algorithms to fit desired models, but less focus on algorithms designed to minimize time spent on models that will ultimately be abandoned.
&lt;/div&gt;
</content>
  </entry>
  
  <entry>
    <title>On Bayesian Methodology. Part 1/6</title>
    <link href="https://antonio-de-leon.com/2024/09/29/statistics-bayesian-methods/"/>
    <updated>2024-09-29T00:00:00+00:00</updated>
    <id>https://antonio-de-leon.com/2024/09/29/statistics-bayesian-methods</id>
    <content type="html">&lt;h1 id=&quot;a-bayesian-methodology-workflow-towards-an-all-encompassing-framework&quot;&gt;A Bayesian Methodology Workflow. Towards an all-encompassing framework.&lt;/h1&gt;

&lt;p&gt;In today’s data-driven world, the need for a robust and systematic framework for applied Bayesian Statistics has never been more critical. As scientific challenges grow increasingly complex, spanning diverse fields such as environmental science, medicine, economics, and machine learning, the ability to manage uncertainty and interpret data meaningfully is paramount. A workflow that eases the navigation of model building, inference, and validation processes.&lt;/p&gt;

&lt;p&gt;Statistical analysis serves as a cornerstone of the scientific method, acting as a bridge between theoretical models and empirical evidence. Within this broader context, Bayesian analysis stands out for its flexibility in incorporating prior knowledge and capacity to provide probabilistic interpretations of uncertainty. A Bayesian workflow framework would improve this process by unifying data exploration, model development, and post-inference critique stages, ensuring that each step aligns with the ultimate goals of robust and transparent decision-making.&lt;/p&gt;

&lt;p&gt;This review builds upon the foundational work of Gelman et al. (2020). As science increasingly relies on interdisciplinary collaboration and complex data, frameworks like the one described by Gelman et al. (2020) are indispensable for ensuring methodological rigor, fostering reproducibility, and advancing discovery.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-is-a-bayesian-workflow&quot;&gt;What is a Bayesian Workflow?&lt;/h2&gt;

&lt;p&gt;A Bayesian Workflow provides a structured approach to managing the dynamic and iterative nature of applied Bayesian Statistics. To better understand it, it’s helpful to differentiate three closely related concepts:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bayesian Inference:&lt;/strong&gt;&lt;br /&gt;
Whose primary goal is to compute the conditional probabilities or posterior distributions.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bayesian Data Analysis:&lt;/strong&gt;&lt;br /&gt;
Which refers to the application of Bayesian inference to specific datasets as described in Gelman et al. (2017)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Bayesian Workflow:&lt;/strong&gt;&lt;br /&gt;
A broader framework that includes:&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;Model building&lt;/li&gt;
      &lt;li&gt;Inference&lt;/li&gt;
      &lt;li&gt;Model checking and improvement&lt;/li&gt;
      &lt;li&gt;Model comparison (not limited to selection or averaging)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The workflow emphasizes the value of analyzing models that may initially seem flawed or suboptimal, as they often provide important insights to understand the model and potential extensions.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;why-is-a-bayesian-workflow-important&quot;&gt;Why Is a Bayesian Workflow Important?&lt;/h2&gt;

&lt;p&gt;A well-defined Bayesian Workflow addresses several challenges in statistical modeling:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Organized Model Understanding:&lt;/strong&gt;&lt;br /&gt;
It alleviates computational burdens by structuring model evaluation and refinement into manageable steps.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Better Decision-Making:&lt;/strong&gt;&lt;br /&gt;
It helps practitioners identify which assumptions to relax and which to retain, enabling more thoughtful model selection.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Model-Data Relationships:&lt;/strong&gt;&lt;br /&gt;
Understanding how models fit the data, even when models reflect poor performance, can provide useful insights.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Diverse Conclusions:&lt;/strong&gt;&lt;br /&gt;
Different models often lead to different conclusions; A Bayesian Workflow encourages practitioners to explore and understand these variations.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;the-big-picture&quot;&gt;The Big Picture&lt;/h2&gt;

&lt;p&gt;% ### ToDo: Include Diagram&lt;/p&gt;

&lt;h3 id=&quot;integrating-statistical-innovations&quot;&gt;Integrating Statistical Innovations&lt;/h3&gt;
&lt;p&gt;Many statistical methodologies began as informal techniques or “hacks” and have since been formalized within Bayesian frameworks in recent years. Key examples include:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Multilevel Modeling:&lt;/strong&gt;&lt;br /&gt;
Extends empirical Bayes methods by incorporating prior inference directly into Bayesian models.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Exploratory Data Analysis (EDA):&lt;/strong&gt;&lt;br /&gt;
Functions as a form of predictive model checking.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Regularization Techniques:&lt;/strong&gt;&lt;br /&gt;
Replace ad hoc variable selection methods in regression, offering more robust solutions.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Non-parametric Models:&lt;/strong&gt;&lt;br /&gt;
They serve as Bayesian replacements for techniques like kernel smoothing and broadening their application.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These methods have expanded statistical frameworks, making them more modular and adaptable while retaining their core principles.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;statistics-and-uncertainty&quot;&gt;Statistics and Uncertainty&lt;/h2&gt;

&lt;p&gt;At its heart, statistics is about &lt;em&gt;managing uncertainty&lt;/em&gt;. A Bayesian Workflow recognizes and aims to address uncertainty in several forms:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Data and Model Parameters:&lt;/strong&gt;&lt;br /&gt;
Variability and imprecision are inherent in the data and parameters.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Model Fitting:&lt;/strong&gt;&lt;br /&gt;
Challenges in determining whether a model is appropriately specified.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Model Setup and Expansion:&lt;/strong&gt;&lt;br /&gt;
Difficulty in deciding how to structure and extend models to capture key dynamics.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Interpretation:&lt;/strong&gt;&lt;br /&gt;
Ambiguity in translating statistical results into meaningful conclusions.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Workflows often become disorderly when moving beyond predefined designs and analyses. Practical constraints—such as limited time, computational resources, and the consequences of incorrect decisions—frequently necessitate shortcuts. A structured workflow mitigates these challenges by offering a systematic approach to balancing rigor with practicality.&lt;/p&gt;

&lt;p&gt;A Bayesian Workflow provides a comprehensive framework for organizing applied Bayesian Statistics. It embraces the iterative nature of statistical modeling, acknowledges the importance of learning from flawed models, and prioritizes the exploration of uncertainty. By following these structured principles, practitioners can make informed, defensible decisions while navigating the complexities of statistical analysis.&lt;/p&gt;

&lt;p&gt;For those interested in exploring this further, I would recommend you review Gelman et al. (2020) and consider how these principles can be applied in your work.&lt;/p&gt;

</content>
  </entry>
  
</feed>
