Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Part 2: Statistical Tools and Concepts

How Nature Computes | Statistical Thinking Module 1 | ASTR 596

San Diego State University

Learning Outcomes

By the end of Part 2, you will be able to:


2.1 Correlation and Independence: When Variables Connect

Priority: 🔴 Essential

Physical intuition: Watch a flock of starlings move through the sky. When one bird turns, nearby birds turn too. Their velocities aren’t independent — they’re correlated. The same thing happens in stellar streams, where stars that were stripped from the same dwarf galaxy move together through space with correlated velocities.

So far, we’ve assumed particle velocities are independent. But what if they’re not? Understanding correlation is crucial for everything from gas dynamics to Gaussian processes.

Physical examples of correlation:

  1. Ideal gas: Particle velocities are independent

    • Pressure tensor is diagonal: Pij=PδijP_{ij} = P\delta_{ij}

    • No shear stress, no viscosity

  2. Stellar streams: Velocities are correlated

    • Stars moving together have correlated velocities

    • Off-diagonal pressure terms represent streaming motion

  3. Turbulence: Strong velocity correlations

    • Eddies create correlated motion

    • Kolmogorov spectrum from correlation functions

Why correlation matters for your projects:

Project 2 (N-body): Initially uncorrelated velocities become correlated through gravity

Project 4 (MCMC): Autocorrelation determines effective sample size

Project 5 (Gaussian Processes): Entire method based on correlation!

Correlation and Velocity Ellipsoids: How Stellar Dynamics Shape Observable Distributions. This comprehensive demonstration shows how correlation fundamentally shapes velocity distributions in stellar systems, directly connecting statistical concepts to observable astrophysics. Top row: Stellar velocity scatter plots across different dynamical environments, from isotropic spherical halos (ρ=0.0) through increasingly correlated systems representing thick disk (ρ=0.5), thin disk (ρ=0.8), and tidal stream populations (ρ=0.95). Each panel shows 1,500 synthetic stars with speeds color-coded (darker = faster) and confidence ellipsoids (1σ, 2σ, 3σ) revealing the characteristic elliptical structure that emerges from correlation. Bottom row: Principal component analysis of the same systems shows the underlying elliptical geometry explicitly, with major and minor axes proportional to the eigenvalues of the covariance matrix. As correlation increases, the axis ratio grows from 1.33 (nearly circular) to 6.52 (highly elongated), while the orientation encodes the preferred direction of streaming motion. The progression from ρ=0 → 0.95 represents the evolution from relaxed systems (globular clusters, stellar halos) to dynamically young or disturbed populations (stellar streams, spiral arm features). This figure illustrates why velocity ellipsoids are fundamental tools in galactic archaeology - the shape directly encodes the dynamical history and current state of stellar populations, making correlation a powerful diagnostic of astrophysical processes.

Figure 1:Correlation and Velocity Ellipsoids: How Stellar Dynamics Shape Observable Distributions. This comprehensive demonstration shows how correlation fundamentally shapes velocity distributions in stellar systems, directly connecting statistical concepts to observable astrophysics. Top row: Stellar velocity scatter plots across different dynamical environments, from isotropic spherical halos (ρ=0.0) through increasingly correlated systems representing thick disk (ρ=0.5), thin disk (ρ=0.8), and tidal stream populations (ρ=0.95). Each panel shows 1,500 synthetic stars with speeds color-coded (darker = faster) and confidence ellipsoids (1σ, 2σ, 3σ) revealing the characteristic elliptical structure that emerges from correlation. Bottom row: Principal component analysis of the same systems shows the underlying elliptical geometry explicitly, with major and minor axes proportional to the eigenvalues of the covariance matrix. As correlation increases, the axis ratio grows from 1.33 (nearly circular) to 6.52 (highly elongated), while the orientation encodes the preferred direction of streaming motion. The progression from ρ=0 → 0.95 represents the evolution from relaxed systems (globular clusters, stellar halos) to dynamically young or disturbed populations (stellar streams, spiral arm features). This figure illustrates why velocity ellipsoids are fundamental tools in galactic archaeology - the shape directly encodes the dynamical history and current state of stellar populations, making correlation a powerful diagnostic of astrophysical processes.

The key insight: Independence makes problems tractable (can multiply probabilities). Correlation makes problems realistic (real systems have relationships). Understanding when to assume independence and when to model correlation is crucial for both physics and ML.

2.2 Marginalization: The Art of Ignoring

Priority: 🔴 Essential

Physical intuition: Imagine a 3D sculpture casting a shadow on a wall. The 2D shadow is a marginalization of the 3D object—you’ve integrated out the depth dimension. Similarly, when we observe stellar velocities along the line of sight, we’re seeing a marginalization of the full 3D velocity distribution.

We have velocities in 3D but often need just speeds. We know positions and velocities but only care about energy. How do we extract what matters? Through marginalization—integrating out unwanted variables.

The mathematical operation:

P(x)=P(x,y)dyP(x) = \int P(x,y) dy

“Sum over all possible values of what you don’t care about.”

Example: From 3D velocities to 1D speeds

Starting with Maxwell-Boltzmann in 3D:

f(v)=n(m2πkBT)3/2emv2/2kBTf(\vec{v}) = n \left(\frac{m}{2\pi k_B T}\right)^{3/2} e^{-m|\vec{v}|^2/2k_B T}

To get speed distribution, integrate over all directions:

Marginalization appears everywhere:

ContextMarginalizing OverTo Get
Bayesian inferenceNuisance parametersPosterior of interest
Gaussian ProcessesUnobserved pointsPredictions at test points
Statistical mechanicsMicroscopic detailsMacroscopic observables
Neural networksHidden layersOutput predictions
Image processingNoise dimensionsClean signal

The profound pattern: Complex high-dimensional problem → Marginalize → Simple low-dimensional answer

This is how we go from 1057 particle coordinates to 4 stellar structure equations!

Marginalization: The Art of Extracting 1D Information from Multi-dimensional Reality. This comprehensive demonstration reveals how we extract observable quantities from complex multi-dimensional distributions using integration. Center-left: Joint stellar velocity distribution P(v_x, v_y) shows correlated velocities (ρ = 0.41) representing streaming motion in a stellar system, with contours indicating probability density levels and realistic velocity scales (km/s). Top: Radial velocity marginal P(v_x) = \int P(v_x, v_y) dv_y (blue) shows the distribution we’d observe through spectroscopy - extracting line-of-sight velocities by integrating over unobservable perpendicular components, with mean 15.0 km/s and dispersion 11.0 km/s. Right: Tangential velocity marginal P(v_y) = \int P(v_x, v_y) dv_x (rose) represents proper motion measurements, showing different statistics (mean 25.0 km/s, dispersion 13.4 km/s) due to the correlation structure. Far-right: Observational reality shows 500 synthetic stellar measurements where only line-of-sight velocities are observable (teal histogram), perfectly matching the theoretical marginal (dark curve), demonstrating that what we measure is mathematically the marginal of what actually exists. This illustrates the profound principle underlying all astrophysics: observations are marginalizations of higher-dimensional reality, and understanding the relationship between the full distribution and its marginals is essential for interpreting data correctly.

Figure 2:Marginalization: The Art of Extracting 1D Information from Multi-dimensional Reality. This comprehensive demonstration reveals how we extract observable quantities from complex multi-dimensional distributions using integration. Center-left: Joint stellar velocity distribution P(vx,vy)P(v_x, v_y) shows correlated velocities (ρ = 0.41) representing streaming motion in a stellar system, with contours indicating probability density levels and realistic velocity scales (km/s). Top: Radial velocity marginal P(vx)=P(vx,vy)dvyP(v_x) = \int P(v_x, v_y) dv_y (blue) shows the distribution we’d observe through spectroscopy - extracting line-of-sight velocities by integrating over unobservable perpendicular components, with mean 15.0 km/s and dispersion 11.0 km/s. Right: Tangential velocity marginal P(vy)=P(vx,vy)dvxP(v_y) = \int P(v_x, v_y) dv_x (rose) represents proper motion measurements, showing different statistics (mean 25.0 km/s, dispersion 13.4 km/s) due to the correlation structure. Far-right: Observational reality shows 500 synthetic stellar measurements where only line-of-sight velocities are observable (teal histogram), perfectly matching the theoretical marginal (dark curve), demonstrating that what we measure is mathematically the marginal of what actually exists. This illustrates the profound principle underlying all astrophysics: observations are marginalizations of higher-dimensional reality, and understanding the relationship between the full distribution and its marginals is essential for interpreting data correctly.

2.3 Ergodicity: When Time Equals Ensemble

Priority: 🔴 Essential

Physical intuition: Drop a blob of cream into your coffee. At first, it stays localized. But as you stir (or just wait), the cream explores the entire cup. Eventually, any small region has the same cream concentration as the time-average. This is ergodicity—one particle’s journey through time tells you about all possible states.

You measure the pressure of a gas over time. You also calculate the ensemble average over all possible microstates. Remarkably, these give the same answer. This is ergodicity — one of the deepest principles in statistical mechanics.

Why ergodicity matters:

For physics: We can’t measure ensemble averages directly (need all possible microstates). But we can measure time averages! Ergodicity says they’re the same.

For MCMC (Project 4): Your Markov chain explores parameter space over “time” (iterations). Ergodicity guarantees:

For molecular dynamics: Simulate one system over time instead of many systems at once

When ergodicity fails:

The profound connection: Ergodicity links:

All give the same answer for ergodic systems!

When Can We Assume Ergodicity?

Key diagnostic questions:

  1. Mixing time vs. observation time: Is τ_mix << τ_obs?

  2. Phase space connectivity: Can the system reach all allowed states?

  3. Energy barriers: Are there insurmountable barriers between regions?

Practical examples:

The MCMC connection (crucial for Project 4): Your Markov chain starts non-ergodic (stuck near initial guess) and becomes ergodic after burn-in. The autocorrelation time τ tells you how many steps needed between independent samples. This is why we:

  1. Discard burn-in samples (pre-ergodic)

  2. Thin chains by τ (ensure independence)

  3. Run multiple chains (test ergodicity via R̂ statistic)

2.4 The Law of Large Numbers: Why Statistics Works

Priority: 🔴 Essential

All these statistical principles work because of a mathematical miracle: as NN \to \infty, randomness vanishes.

The Law of Large Numbers (LLN): For NN independent random variables, the relative fluctuation scales as:

σX1N\frac{\sigma}{\langle X \rangle} \sim \frac{1}{\sqrt{N}}

**What this means**:

- $N = 100$: ~10% fluctuations
- $N = 10^6$: ~0.1% fluctuations
- $N = 10^{23}$: ~$10^{-11}$% fluctuations
- $N = 10^{57}$ (Sun): ~$10^{-28}$% fluctuations

At stellar scales, fluctuations are smaller than quantum uncertainty!

**This is why**:

- Pressure is steady despite chaotic collisions
- Stars shine steadily despite random fusion events
- Thermodynamics works despite molecular chaos
- Monte Carlo methods converge despite using random numbers

This $\sqrt{N}$ scaling has profound implications for how errors propagate through calculations, which we'll explore next.

(error-propagation)=
## 2.5 Error Propagation: The Universal $\sqrt{N}$ Scaling

**Priority: 🟡 Standard Path**

:::{margin}
**Effective sample size** ($N_{\text{eff}}$): The equivalent number of independent samples when dealing with correlated data. For MCMC: $N_{\text{eff}} = N/(1 + 2\tau)$ where τ is the autocorrelation time.

Every measurement has uncertainty. Every calculation propagates these uncertainties. Understanding error propagation is crucial for both physics and computation. The Law of Large Numbers tells us fluctuations scale as 1/N1/\sqrt{N}—now let’s see how this propagates through calculations.

Monte Carlo error scaling:

For NN samples, the error in the mean scales as:

σxˉ=σN\sigma_{\bar{x}} = \frac{\sigma}{\sqrt{N}}

This 1/N1/\sqrt{N} scaling is universal:

Application to your projects:

Project 2: Energy conservation error accumulates as Nsteps\sqrt{N_{\text{steps}}}

Project 3: Monte Carlo photon error decreases as 1/Nphotons1/\sqrt{N_{\text{photons}}}

Project 4: MCMC error includes autocorrelation:

σMCMC=σNeff where Neff=N1+2τ\sigma_{\text{MCMC}} = \frac{\sigma}{\sqrt{N_{\text{eff}}}} \text{ where } N_{\text{eff}} = \frac{N}{1 + 2\tau}

Here τ\tau is the autocorrelation time.

2.6 Variance and Standard Deviation: Measuring Spread

Priority: 🔴 Essential

While the mean tells us where a distribution is centered, variance and standard deviation tell us how spread out it is — crucial for understanding everything from temperature to measurement uncertainty.

Definitions: Variance: The average squared deviation from the mean

Var(X)=σ2=E[(Xμ)2]=E[X2](E[X])2\text{Var}(X) = \sigma^2 = E[(X - \mu)^2] = E[X^2] - (E[X])^2

Standard Deviation: The square root of variance

σ=Var(X)\sigma = \sqrt{\text{Var}(X)}

Why square root? It puts the measure back in the same units as the original data.

Physical Interpretation

Remember from Part 1: Temperature IS proportional to velocity variance

vx2vx2=σv2=kBTm\langle v_x^2 \rangle - \langle v_x \rangle^2 = \sigma_v^2 = \frac{k_B T}{m}

This isn’t an analogy—it’s an identity. Higher temperature literally means larger variance in molecular velocities.

Key Properties

  1. Variance of a sum (independent variables):

    Var(X+Y)=Var(X)+Var(Y)\text{Var}(X + Y) = \text{Var}(X) + \text{Var}(Y)
  2. Variance of a scaled variable:

    Var(cX)=c2Var(X)\text{Var}(cX) = c^2 \text{Var}(X)
  3. Standard error of the mean:

    σxˉ=σN\sigma_{\bar{x}} = \frac{\sigma}{\sqrt{N}}

    This is why averaging reduces uncertainty!

Why This Matters for Your Projects

The takeaway: Variance isn’t just a statistical concept — it’s often the physical quantity we’re measuring (temperature, pressure, velocity dispersion).

2.7 Bayesian Thinking: Learning from Data

Priority: 🔴 Essential Physical intuition: You observe a star with a reddish color. Is it red because it’s an intrinsically cool M-dwarf, or is it a hotter star reddened by interstellar dust? Your prior knowledge (most nearby stars aren’t heavily reddened) combines with the observation (the color) to give you a posterior belief about the star’s true nature. This is Bayesian inference—using prior knowledge plus new data to update beliefs.

Bayes’ Theorem: The Learning Equation

At its heart, Bayesian inference is about updating beliefs with data:

P(hypothesisdata)=P(datahypothesis)×P(hypothesis)P(data)\boxed{P(\text{hypothesis}|\text{data}) = \frac{P(\text{data}|\text{hypothesis}) \times P(\text{hypothesis})}{P(\text{data})}}

Or in the notation you’ll use constantly:

P(θD)=P(Dθ)×P(θ)P(D)P(\theta|D) = \frac{P(D|\theta) \times P(\theta)}{P(D)}

where:

The Power and Peril of Priors

The Power: Priors incorporate previous knowledge

The Peril: Priors can bias results

Best Practice:

  1. Use physically motivated priors when possible

  2. Test sensitivity to prior choice

  3. Report both prior and posterior

  4. Use uninformative priors when truly ignorant

Connection to Frequentist Statistics

Bayesian and frequentist approaches answer different questions:

ApproachQuestionAnswer
Frequentist“If I repeated this experiment many times, what would happen?”Confidence intervals, p-values
Bayesian“Given this data, what do I believe about the parameters?”Posterior distributions, credible intervals

Both are valid! Frequentist is about long-run frequencies. Bayesian is about updating beliefs with data.

Part 2 Synthesis: The Statistical Foundation


Bridge to Part 3: From Tools to Information Extraction

You now have the statistical tools. Next, we’ll see how to extract meaningful information from distributions using moments—the mathematical bridge between microscopic chaos and macroscopic order.