Math for Causal Inference
SIMULATION LAB

See the mathematics move

One interactive simulator for every day. Change a parameter, redraw the data and watch the theorem hold (or fail). Each simulator also appears at the end of its day's lesson. Everything runs in your browser.

PHASE 1Probability & Statistical Inference

DAY 1
Inclusion–Exclusion & Fréchet Bounds

Set P(A), P(B) and their overlap; watch the union, the complement and the feasible range of the joint move.

DAY 2
Bayes' Theorem Calculator

A probability tree and a 1,000-person grid: see how prevalence drives the meaning of a positive test.

DAY 3
Linearity of Expectation & Variance Scaling

Transform X into aX + b and watch the mean shift and the spread scale by |a|.

DAY 4
Distribution Explorer & DGP Sampler

Seven distributions, their exact shape, moments, and a histogram of simulated draws.

DAY 5
Bivariate Normal in 3D

Drag to rotate the joint density; change the correlation and see the contours and the regression line.

DAY 6
Conditional Expectation & Total Variance

Two groups, their means and spreads: split total variance into within and between parts.

DAY 7
Central Limit Theorem Simulator

Draw thousands of sample means from skewed or bimodal parents and watch the normal shape appear.

DAY 8
Estimator Race: Bias, Variance & MSE

Mean, median and a shrinkage estimator compete across repeated samples.

DAY 9
Confidence-Interval Coverage

One hundred intervals from one hundred samples: count how many catch the true mean.

DAY 10
Statistical Power Visualiser

The null and alternative sampling distributions, the rejection region, α, β and power.

DAY 11
Log-Likelihood Explorer

Move the parameter along a Bernoulli log-likelihood; see the peak, its curvature and the LR test.

DAY 12
Delta Method vs Simulation

Push a normal estimate through ln, √, 1/x or x² and compare the delta-method normal with the truth.

DAY 13
Beta–Binomial Updating

Prior × likelihood = posterior. Change prior strength and data and watch the posterior move.

DAY 14
Missing-Data Mechanisms

MCAR, MAR and MNAR on an education–wage scatter: complete-case bias, IPW repair and slope attenuation.

DAY 15
Simpson's Paradox Lab

Change who gets which treatment and watch the pooled comparison reverse the stratified one.

PHASE 2Linear Algebra & Optimization

DAY 16
Vector Playground

Drag two vectors and watch the dot product, the angle and the projection; the geometry behind correlation and slopes.

DAY 17
A Matrix as a Transformation

Edit a 2×2 matrix and see the plane stretch, rotate, shear or collapse; the determinant is the area of the image square.

DAY 18
Collinearity & Rank

Raise the correlation between two regressors and watch the cloud of coefficient estimates stretch along a line.

DAY 19
Solving Ax = b

Two equations as two lines: as the determinant shrinks, the solution becomes fragile and then disappears.

DAY 20
Least Squares: Residuals & Orthogonality

Move a candidate line; only the OLS line makes the residuals orthogonal to the regressors and the SSR minimal.

DAY 21
Eigenvectors & Quadratic Forms

A symmetric matrix turns the unit circle into an ellipse whose axes are its eigenvectors.

DAY 22
Covariance Ellipses & a′Σa

Correlated draws built with a Cholesky factor, their covariance ellipses, and the variance of any linear combination.

DAY 23
Taylor Approximations

Approximate eˣ, ln(1+x), sin x or the logistic function by polynomials of order 1–4 around any point.

DAY 24
The Gradient of the Sum of Squares

Click anywhere on the SSR surface to see −∇S = 2X′(y − Xβ) point downhill toward the OLS estimate.

DAY 25
Gradient Descent vs Newton

Race the two algorithms on an ill-conditioned bowl and on a curved valley; tune the step size until it breaks.

DAY 26
Constrained Optimum: Budget & Indifference

Utility maximisation on a budget line: tangency, the Lagrange multiplier and the cost of a non-optimal bundle.

DAY 27
OLS by Matrices

Simulated data with X′X, (X′X)⁻¹, β̂, s² and standard errors computed live from the matrix formulas.

DAY 28
Partialling Out (FWL)

A confounded scatter beside its added-variable plot: the residual-on-residual slope equals the multiple-regression coefficient.

DAY 29
Heteroskedasticity & Robust Standard Errors

Fan-shaped errors make classical intervals under-cover; robust (sandwich) intervals restore 95%.

DAY 30
GMM with Two Moments

Estimate a Poisson rate from two moments, compare identity and optimal weighting, and watch the J test catch overdispersion.

PHASE 3The Potential Outcomes Framework

DAY 31
The Science Table

Twelve workers with both potential outcomes: hide the missing half, randomise, and watch estimates centre on the ATE.

DAY 32
Spillovers & Saturation

Direct and spillover effects of deworming-style treatment; why within-village comparisons miss the total effect.

DAY 33
ATE, ATT, ATC & CATE

A heterogeneous effect τ(x) averaged over three different populations — and when they coincide.

DAY 34
The Roy Model of Self-Selection

Workers enrol when their gain beats the cost: decompose the naive gap into ATE, selection bias and heterogeneity bias.

DAY 35
Randomisation Balances Covariates

Thousands of re-assignments: baseline imbalance and estimates under complete, Bernoulli and self-selected assignment.

DAY 36
Neyman's Conservative Variance

The true design variance versus the Neyman estimator as effect heterogeneity grows; coverage of the 95% interval.

DAY 37
Fisher's Exact Randomisation Test

Enumerate every possible assignment under the sharp null and read off an exact p-value — for means or ranks.

DAY 38
Blocking on Districts

Complete versus within-district randomisation of a schooling programme: the variance gain from blocking.

DAY 39
Raw, ANCOVA & Lin Adjustment

Re-randomise a training experiment and compare the spread of three estimators when slopes differ by arm.

DAY 40
Cluster Designs & Power

Minimum detectable effect against the number of schools for any ICC, cluster size and baseline R².

DAY 41
Non-Compliance: ITT & CACE

An insurance lottery with compliers, always-takers and never-takers: only the Wald ratio recovers the CACE.

DAY 42
Overlap & Trimming

Mirrored propensity-score histograms, extreme weights, effective sample size and what trimming costs.

DAY 43
Balancing on the Propensity Score

Stratify on the estimated score: covariate imbalance vanishes within strata and the bias with it.

DAY 44
Horvitz–Thompson vs Hájek

Monte Carlo of two IPW estimators; shift the outcome level and only the normalised (Hájek) version stays stable.

DAY 45
Double Robustness (AIPW)

Switch the outcome and propensity models between right and wrong: AIPW survives as long as one is right.