Type at least 2 letters. Enter opens the first result, Esc closes.

    Quick recap

    The key takeaways of every lesson on one page. Read it in ten minutes to refresh the whole track; open a lesson when a point feels unclear.

    01 Probability and Bayes' rule

    • With equally likely outcomes, P(A)=∣A∣/∣Ω∣P(A) = |A|/|\Omega|; count with the multiplication rule, n!/(n−k)!n!/(n-k)! ordered lists and (nk)\binom{n}{k} subsets. Often it is easier to compute the complement.
    • The axioms (P≥0P \ge 0, P(Ω)=1P(\Omega) = 1, countable additivity) imply the complement rule, inclusion–exclusion P(A∪B)=P(A)+P(B)−P(A∩B)P(A \cup B) = P(A) + P(B) - P(A \cap B) and the union bound P(⋃Ai)≤∑P(Ai)P(\bigcup A_i) \le \sum P(A_i).
    • Conditioning on BB keeps only the outcomes in BB and rescales: P(A∣B)=P(A∩B)/P(B)P(A \mid B) = P(A \cap B)/P(B). Law of total probability: P(A)=∑iP(A∣Bi)P(Bi)P(A) = \sum_i P(A \mid B_i)P(B_i) for a partition B1,…,BnB_1, \dots, B_n.
    • Bayes' rule: posterior = likelihood × prior / evidence, P(H∣E)=P(E∣H)P(H)/P(E)P(H \mid E) = P(E \mid H)P(H)/P(E). With a small prior, a good test can still give mostly false positives (base-rate effect).
    • Odds form: posterior odds = prior odds × likelihood ratio P(E∣H)/P(E∣Hc)P(E \mid H)/P(E \mid H^c). Conditionally independent pieces of evidence multiply their likelihood ratios; dependent ones do not.
    • Independence: P(A∩B)=P(A)P(B)P(A \cap B) = P(A)P(B). Disjoint events with positive probabilities are dependent. Pairwise independence does not imply mutual independence (XOR).
    • Conditional independence and independence do not imply each other: a common cause makes conditionally independent events dependent, and a common effect (collider) makes independent events dependent (explaining away, selection bias).
    • Monty Hall: switching wins with probability 2/3 because the host's choice depends on the car. Simpson's paradox: pooled rates are weighted averages, and different weights can reverse a comparison.

    02 Random variables and expectation

    • A random variable is a function X:Ω→RX : \Omega \to \mathbb{R}. Its CDF FX(x)=P(X≤x)F_X(x) = P(X \le x) describes its distribution, and P(a<X≤b)=FX(b)−FX(a)P(a < X \le b) = F_X(b) - F_X(a).
    • A PMF gives probabilities of single values (bars); a PDF gives probability per unit length (areas are probabilities, heights can exceed 1, and P(X=x)=0P(X = x) = 0).
    • The expectation is the balance point: E[X]=∑xx p(x)\mathbb{E}[X] = \sum_x x\,p(x) or ∫x p(x) dx\int x\,p(x)\,dx. LOTUS: E[g(X)]=∑xg(x) p(x)\mathbb{E}[g(X)] = \sum_x g(x)\,p(x), without the distribution of g(X)g(X).
    • Linearity E[aX+bY+c]=aE[X]+bE[Y]+c\mathbb{E}[aX + bY + c] = a\mathbb{E}[X] + b\mathbb{E}[Y] + c needs no independence; with indicators (E[IA]=P(A)\mathbb{E}[I_A] = P(A)) it gives the mean of any count.
    • Var⁡(X)=E[(X−μ)2]=E[X2]−μ2\operatorname{Var}(X) = \mathbb{E}[(X - \mu)^2] = \mathbb{E}[X^2] - \mu^2 and Var⁡(aX+b)=a2Var⁡(X)\operatorname{Var}(aX + b) = a^2\operatorname{Var}(X); in general E[g(X)]≠g(E[X])\mathbb{E}[g(X)] \ne g(\mathbb{E}[X]).
    • For a strictly monotone gg, Y=g(X)Y = g(X) has density pY(y)=pX(g−1(y)) ∣dg−1(y)/dy∣p_Y(y) = p_X(g^{-1}(y))\,|dg^{-1}(y)/dy| (probability is conserved); for a non-monotone gg, use the CDF method.
    • Inverse-CDF sampling: F−1(U)F^{-1}(U) with U∼U(0,1)U \sim U(0, 1) has CDF FF (with the generalised inverse also for discrete FF). PIT: F(X)∼U(0,1)F(X) \sim U(0, 1) for a continuous FF, so PIT histograms check calibration (U-shape = too narrow).

    03 Common distributions

    • Bernoulli → binomial (successes in nn trials), geometric (trials to the first success) and categorical (KK classes); binomial with large nn, small pp and np=λnp = \lambda → Poisson, with mean = variance = λ\lambda.
    • Le Cam: a sum of independent Bernoulli(pi)\text{Bernoulli}(p_i) is within total variation distance ∑ipi2\sum_i p_i^2 of Poisson(∑ipi)\text{Poisson}(\sum_i p_i); for Bin(n,p)\text{Bin}(n, p) the bound is np2np^2.
    • Exp(λ)\text{Exp}(\lambda) (rate λ\lambda, mean 1/λ1/\lambda) is memoryless: P(X>s+t∣X>s)=P(X>t)P(X > s + t \mid X > s) = P(X > t). It and the geometric are the only memoryless distributions. The minimum of independent exponentials is exponential with the sum of the rates.
    • The MGF MX(t)=E[etX]M_X(t) = \mathbb{E}[e^{tX}] gives moments (M(n)(0)=E[Xn]M^{(n)}(0) = \mathbb{E}[X^n]), multiplies for independent sums, and determines the distribution when it is finite near 0.
    • A sum of nn i.i.d. Exp(λ)\text{Exp}(\lambda) is Gamma(n,λ)\text{Gamma}(n, \lambda); gammas with the same rate add their shapes.
    • X/(X+Y)X/(X + Y) with independent Gamma(a,1)\text{Gamma}(a, 1) and Gamma(b,1)\text{Gamma}(b, 1) is Beta(a,b)\text{Beta}(a, b); normalised independent gammas give a Dirichlet, whose marginals are Beta(αi,α0−αi)\text{Beta}(\alpha_i, \alpha_0 - \alpha_i).
    • Poisson process with rate λ\lambda: i.i.d. Exp(λ)\text{Exp}(\lambda) gaps, or independent Poisson(λt)\text{Poisson}(\lambda t) counts in disjoint windows. Thinning with probability qq gives rate qλq\lambda; superposition adds rates.

    04 Joint distributions and covariance

    • From a joint PMF or PDF: the marginal is a sum (or integral) over the other variable; the conditional is p(x∣y)=p(x,y)/pY(y)p(x \mid y) = p(x, y)/p_Y(y); and p(x,y)=p(x∣y) pY(y)p(x, y) = p(x \mid y)\,p_Y(y).
    • XX and YY are independent when p(x,y)=pX(x) pY(y)p(x, y) = p_X(x)\,p_Y(y) everywhere, including where it is 0; a joint table is independent exactly when it has rank 1.
    • E[X∣Y]\mathbb{E}[X \mid Y] is a random variable (a function of YY); the tower rule says E[E[X∣Y]]=E[X]\mathbb{E}[\mathbb{E}[X \mid Y]] = \mathbb{E}[X].
    • Law of total variance: Var⁡(X)=E[Var⁡(X∣Y)]+Var⁡(E[X∣Y])\operatorname{Var}(X) = \mathbb{E}[\operatorname{Var}(X \mid Y)] + \operatorname{Var}(\mathbb{E}[X \mid Y]), within plus between.
    • Cov⁡(X,Y)=E[XY]−E[X] E[Y]\operatorname{Cov}(X, Y) = \mathbb{E}[XY] - \mathbb{E}[X]\,\mathbb{E}[Y] and ∣ρ∣≤1|\rho| \le 1; independent implies uncorrelated, but not the reverse (XX and X2X^2).
    • Var⁡(∑iXi)=∑iVar⁡(Xi)+2∑i<jCov⁡(Xi,Xj)\operatorname{Var}(\sum_i X_i) = \sum_i \operatorname{Var}(X_i) + 2\sum_{i<j}\operatorname{Cov}(X_i, X_j), and Cov⁡(AX+b)=AΣA⊤\operatorname{Cov}(AX + b) = A\Sigma A^\top.
    • Every covariance matrix is symmetric PSD, because a⊤Σa=Var⁡(a⊤X)≥0a^\top\Sigma a = \operatorname{Var}(a^\top X) \ge 0; its eigenvectors are the PCA directions and its eigenvalues the variances along them.
    • The sample variance with 1/(n−1)1/(n - 1) is unbiased, because E∑i(Xi−Xˉ)2=(n−1)σ2\mathbb{E}\sum_i (X_i - \bar X)^2 = (n - 1)\sigma^2.

    05 The multivariate Gaussian

    • Change of variables: pY(y)=pX(g−1(y)) ∣det⁡Jg−1(y)∣=pX(x)/∣det⁡Jg(x)∣p_Y(y) = p_X(g^{-1}(y))\,|\det J_{g^{-1}}(y)| = p_X(x)/|\det J_g(x)|; mass is kept, so where the map stretches area the density drops.
    • Box–Muller: in polar coordinates two i.i.d. N(0,1)\mathcal N(0, 1) give an independent uniform angle and R2∼Exp(1/2)R^2 \sim \text{Exp}(1/2); run backwards, −2log⁡(1−U1) (cos⁡2πU2,sin⁡2πU2)\sqrt{-2\log(1 - U_1)}\,(\cos 2\pi U_2, \sin 2\pi U_2) gives two normals.
    • x=μ+Lzx = \mu + Lz with z∼N(0,I)z \sim \mathcal N(0, I) and LL⊤=ΣLL^\top = \Sigma has the density (2π)−d/2(det⁡Σ)−1/2exp⁡(−12(x−μ)⊤Σ−1(x−μ))(2\pi)^{-d/2}(\det\Sigma)^{-1/2}\exp(-\tfrac12 (x - \mu)^\top\Sigma^{-1}(x - \mu)); its contours are ellipses of constant Mahalanobis distance.
    • Affine maps of a Gaussian are Gaussian: Ax+b∼N(Aμ+b,AΣA⊤)Ax + b \sim \mathcal N(A\mu + b, A\Sigma A^\top); a marginal keeps the matching blocks of μ\mu and Σ\Sigma.
    • Uncorrelated jointly Gaussian variables are independent; Gaussian marginals alone are not enough (Y=WXY = WX with a random sign WW).
    • With Cholesky Σ=LL⊤\Sigma = LL^\top: sample μ+Lz\mu + Lz, log⁡det⁡Σ=2∑ilog⁡Lii\log\det\Sigma = 2\sum_i \log L_{ii}, and the quadratic form is ∥L−1(x−μ)∥2\|L^{-1}(x - \mu)\|^2; add jitter if the factorisation fails.
    • Gaussian conditioning: xa∣xb∼N(μa+ΣabΣbb−1(xb−μb), Σaa−ΣabΣbb−1Σba)x_a \mid x_b \sim \mathcal N\big(\mu_a + \Sigma_{ab}\Sigma_{bb}^{-1}(x_b - \mu_b),\ \Sigma_{aa} - \Sigma_{ab}\Sigma_{bb}^{-1}\Sigma_{ba}\big), or in precision form covariance Λaa−1\Lambda_{aa}^{-1}; the conditional covariance does not depend on the observed xbx_b.

    06 LLN, CLT and confidence intervals

    • The sample mean Xˉn\bar X_n is a random variable with E[Xˉn]=μ\mathbb{E}[\bar X_n] = \mu and standard error σ/n\sigma/\sqrt n (for uncorrelated data).
    • Markov: P(X≥a)≤E[X]/aP(X \ge a) \le \mathbb{E}[X]/a for X≥0X \ge 0. Chebyshev: P(∣X−μ∣≥ε)≤σ2/ε2P(|X - \mu| \ge \varepsilon) \le \sigma^2/\varepsilon^2.
    • Weak law of large numbers: Xˉn→μ\bar X_n \to \mu in probability, proved by Chebyshev with Var⁡(Xˉn)=σ2/n\operatorname{Var}(\bar X_n) = \sigma^2/n; without a mean (Cauchy) there is no LLN.
    • Central limit theorem: for i.i.d. data with finite variance, n(Xˉn−μ)/σ→N(0,1)\sqrt n(\bar X_n - \mu)/\sigma \to \mathcal N(0, 1) in distribution; the error of this approximation is O(1/n)O(1/\sqrt n) (Berry–Esseen).
    • A 95% confidence interval for a mean is xˉ±1.96 σ/n\bar x \pm 1.96\,\sigma/\sqrt n (known σ\sigma) or xˉ±tn−1, 0.975 s/n\bar x \pm t_{n-1,\,0.975}\,s/\sqrt n (unknown σ\sigma); "95%" is the coverage of the procedure over repeated experiments.
    • The Wald interval for a proportion fails for small nn or rare events (n=50n = 50, p=0.02p = 0.02: coverage 0.635); the Wilson interval fixes this.
    • A Monte Carlo estimate has the error bar 1.96 sf/n1.96\,s_f/\sqrt n in any dimension; the delta method gives SE⁡(g(Xˉ))≈∣g′(μ)∣ σ/n\operatorname{SE}(g(\bar X)) \approx |g'(\mu)|\,\sigma/\sqrt n.

    07 Concentration inequalities

    • Chernoff bound: P(S≥t)≤inf⁡λ>0e−λt E[eλS]P(S \ge t) \le \inf_{\lambda > 0} e^{-\lambda t}\,\mathbb{E}[e^{\lambda S}], from Markov applied to eλSe^{\lambda S}; for i.i.d. sums it decays exponentially in nn.
    • For Gaussian data the Chernoff bound is e−nt2/(2σ2)e^{-nt^2/(2\sigma^2)}; for Bernoulli(pp) it is e−n KL(p+t ∥ p)e^{-n\,\mathrm{KL}(p + t \,\|\, p)}.
    • Hoeffding's inequality: for independent Xi∈[a,b]X_i \in [a, b], the mean satisfies P(∣Xˉn−μ∣≥ε)≤2e−2nε2/(b−a)2P(|\bar X_n - \mu| \ge \varepsilon) \le 2e^{-2n\varepsilon^2/(b - a)^2}.
    • A variable is sub-Gaussian with proxy σ2\sigma^2 if Eeλ(X−μ)≤eλ2σ2/2\mathbb{E}e^{\lambda(X - \mu)} \le e^{\lambda^2\sigma^2/2} for all λ\lambda; bounded and Gaussian variables are, exponential variables are not.
    • For values in [0,1][0, 1], Hoeffding guarantees error <ε< \varepsilon with probability ≥1−δ\ge 1 - \delta once n≥ln⁡(2/δ)/(2ε2)n \ge \ln(2/\delta)/(2\varepsilon^2); nn grows like ln⁡(1/δ)\ln(1/\delta), Chebyshev's like 1/δ1/\delta.
    • Union bound: P(∪jAj)≤∑jP(Aj)P(\cup_j A_j) \le \sum_j P(A_j); for kk models at once Hoeffding needs only ln⁡(2k/δ)\ln(2k/\delta) instead of ln⁡(2/δ)\ln(2/\delta).
    • Finite-class generalisation bound: with probability ≥1−δ\ge 1 - \delta, ∣R(h)−R^(h)∣≤ln⁡(2k/δ)/(2n)|R(h) - \hat R(h)| \le \sqrt{\ln(2k/\delta)/(2n)} for all kk models; choosing the best of kk on one test set inflates its score by up to this amount.

    08 Maximum likelihood

    • The likelihood L(θ)=∏ip(xi∣θ)L(\theta) = \prod_i p(x_i \mid \theta) is the probability of the observed data as a function of θ\theta; it is not a density over θ\theta. Work with the log-likelihood ℓ(θ)=∑ilog⁡p(xi∣θ)\ell(\theta) = \sum_i \log p(x_i \mid \theta).
    • MLEs: Bernoulli p^=xˉ\hat p = \bar x; Poisson λ^=xˉ\hat\lambda = \bar x; exponential λ^=1/xˉ\hat\lambda = 1/\bar x; Gaussian μ^=xˉ\hat\mu = \bar x, σ^2=1n∑i(xi−xˉ)2\hat\sigma^2 = \frac1n\sum_i (x_i - \bar x)^2.
    • Invariance: the MLE of g(θ)g(\theta) is g(θ^)g(\hat\theta) for any one-to-one gg.
    • An estimator is a random variable: MSE=bias2+variance\text{MSE} = \text{bias}^2 + \text{variance}. Unbiased is not the same as best; D/nD/n and D/(n+1)D/(n+1) beat S2=D/(n−1)S^2 = D/(n-1) in MSE for Gaussian data.
    • The 1/n1/n variance estimate has mean n−1nσ2\frac{n-1}{n}\sigma^2; 1/xˉ1/\bar x for an exponential rate has mean nn−1λ\frac{n}{n-1}\lambda.
    • Consistency: θ^n→θ\hat\theta_n \to \theta in probability; MSE→0\text{MSE} \to 0 is enough. The MLE is consistent under regularity conditions.
    • Maximum likelihood minimises KL(pdata ∥ pθ)\mathrm{KL}(p_{\text{data}} \,\|\, p_\theta), the cross-entropy; mean squared error and cross-entropy losses are Gaussian and Bernoulli/categorical NLLs.
    • Exponential family h(x)exp⁡(η⊤T(x)−A(η))h(x)\exp(\eta^\top T(x) - A(\eta)): ∇A=E[T]\nabla A = \mathbb{E}[T], ∇2A=Cov⁡[T]\nabla^2 A = \operatorname{Cov}[T], the log-likelihood is concave in η\eta, and the MLE matches Eη^[T]\mathbb{E}_{\hat\eta}[T] to the sample average of TT.

    09 Fisher information

    • The score s(θ;x)=∂θlog⁡p(x∣θ)s(\theta; x) = \partial_\theta \log p(x \mid \theta) has mean 0 at the true θ\theta (under regularity conditions).
    • Fisher information: I(θ)=E[s2]=Var⁡(s)=−E[∂θ2log⁡p]I(\theta) = \mathbb{E}[s^2] = \operatorname{Var}(s) = -\mathbb{E}[\partial_\theta^2 \log p], the expected curvature of the log-likelihood; nn i.i.d. observations carry nI(θ)nI(\theta).
    • Examples: Bernoulli 1/(p(1−p))1/(p(1-p)), Poisson 1/λ1/\lambda, exponential rate 1/λ21/\lambda^2, Gaussian mean 1/σ21/\sigma^2.
    • Cramér–Rao: an unbiased TT has Var⁡(T)≥1/(nI(θ))\operatorname{Var}(T) \ge 1/(nI(\theta)); proof by Cov⁡(T,sn)=1\operatorname{Cov}(T, s_n) = 1 and Cauchy–Schwarz. Biased estimators can go below it.
    • The MLE is asymptotically normal and efficient: n(θ^−θ)→N(0,I(θ)−1)\sqrt n(\hat\theta - \theta) \to \mathcal N(0, I(\theta)^{-1}).
    • Wald interval: θ^±1.96/nI(θ^)\hat\theta \pm 1.96/\sqrt{nI(\hat\theta)}, or with the observed information −ℓn′′(θ^)-\ell_n''(\hat\theta); for several parameters use [H−1]kk\sqrt{[H^{-1}]_{kk}}.
    • The theory needs a support that does not depend on θ\theta, an interior θ\theta and a large enough nn; Uniform(0,θ0, \theta) has error of order 1/n1/n, and Wald intervals fail near p=0p = 0.

    10 Bayesian inference

    • Bayes' rule for a parameter: posterior ∝\propto likelihood ×\times prior, p(θ∣D)=p(D∣θ) p(θ)/p(D)p(\theta \mid \mathcal D) = p(\mathcal D \mid \theta)\,p(\theta)/p(\mathcal D); the evidence p(D)p(\mathcal D) only normalises.
    • Beta–Bernoulli: prior Beta(a,ba, b) and kk successes in nn trials give Beta(a+k,b+n−ka + k, b + n - k); the prior acts as a+ba + b pseudo-observations, and sequential updates equal one batch update.
    • Gaussian–Gaussian (known σ2\sigma^2): precisions add, 1/τn2=1/τ02+n/σ21/\tau_n^2 = 1/\tau_0^2 + n/\sigma^2, and the posterior mean is the precision-weighted average of μ0\mu_0 and xˉ\bar x.
    • MAP = regularised MLE: arg⁡min⁡[−ℓ(θ)−log⁡p(θ)]\arg\min[-\ell(\theta) - \log p(\theta)]; an L2 penalty is a Gaussian prior (λ=σ2/σw2\lambda = \sigma^2/\sigma_w^2), an L1 penalty a Laplace prior. The MAP is not invariant under reparametrisation.
    • Shrinkage trades bias for variance: the Gaussian posterior mean beats xˉ\bar x in MSE exactly when (μ−μ0)2<σ2/n+2τ02(\mu - \mu_0)^2 < \sigma^2/n + 2\tau_0^2.
    • Every exponential family has a conjugate prior; Gamma(a,ba, b) with Poisson counts gives Gamma(a+∑xi,b+na + \sum x_i, b + n).
    • The posterior predictive ∫p(x∗∣θ) p(θ∣D) dθ\int p(x^* \mid \theta)\,p(\theta \mid \mathcal D)\,d\theta adds parameter uncertainty to the noise, so it is wider than a plug-in; Gaussian: N(μn,σ2+τn2)\mathcal N(\mu_n, \sigma^2 + \tau_n^2).
    • A credible interval is a probability statement about θ\theta given the data and the prior; a confidence interval is a statement about the procedure. For large nn in regular models they agree (Bernstein–von Mises).

    11 Hypothesis testing

    • A test fixes a null hypothesis H0H_0, a statistic TT and a level α\alpha; it rejects when the p-value p=PH0(T at least as extreme as observed)p = P_{H_0}(T \text{ at least as extreme as observed}) is at most α\alpha.
    • Type I error = rejecting a true H0H_0 (probability at most α\alpha); type II error = missing a real effect (probability βII\beta_{\text{II}}); power =1−βII= 1 - \beta_{\text{II}}.
    • For a z-test, power =Φ(n δ/σ−z1−α)= \Phi(\sqrt n\,\delta/\sigma - z_{1-\alpha}) (one-sided): it depends only on λ=n δ/σ\lambda = \sqrt n\,\delta/\sigma, so twice the effect needs a quarter of the data.
    • Under a continuous H0H_0 the p-value is Uniform(0, 1); it is not P(H0∣data)P(H_0 \mid \text{data}) and not an effect size.
    • The t statistic (Xˉn−μ0)/(S/n)(\bar X_n - \mu_0)/(S/\sqrt n) has the tn−1t_{n-1} distribution for Gaussian data; use a paired test for paired data and Welch's test for two independent groups.
    • For a 2×22 \times 2 table, Pearson's X2X^2 equals the square of the pooled two-proportion zz.
    • Duality: a (1−α)(1 - \alpha) confidence interval is the set of null values that the level-α\alpha test does not reject.
    • For mm tests, Bonferroni (pi≤α/mp_i \le \alpha/m) controls the FWER under any dependence; Benjamini–Hochberg (largest kk with p(k)≤kq/mp_{(k)} \le kq/m) controls the FDR at q m0/mq\,m_0/m for independent tests.

    12 Bootstrap and A/B tests

    • A permutation test shuffles the group labels; under exchangeability it is exact, and the Monte Carlo p-value (1+C)/(1+B)(1 + C)/(1 + B) satisfies P(p≤α)≤αP(p \le \alpha) \le \alpha for every BB.
    • The bootstrap resamples the data with replacement to approximate the sampling distribution of a statistic; a resample contains about 1−1/e=63%1 - 1/e = 63\% of the distinct points.
    • The bootstrap standard error is the SD of the replicates, and the percentile interval uses their α/2\alpha/2 and 1−α/21 - \alpha/2 quantiles; check coverage by simulation.
    • The bootstrap fails for extremes (the maximum: coverage 0), heavy tails, dependent data (use a block or cluster bootstrap) and very small nn.
    • Users per arm of an A/B test: n=2σ2(z1−α/2+z1−βII)2/δ2≈16σ2/δ2n = 2\sigma^2(z_{1-\alpha/2} + z_{1-\beta_{\text{II}}})^2/\delta^2 \approx 16\sigma^2/\delta^2 for α=0.05\alpha = 0.05 and power 0.8.
    • Peeking at the p-value and stopping at the first p<0.05p < 0.05 inflates the type I error (about 0.25 with 20 looks); fix nn in advance or use a sequential design.
    • A sample-ratio mismatch (a χ² test of the assignment counts) signals a bug; do not trust the result until it is explained.
    • CUPED, Y−θ(X−Xˉ)Y - \theta(X - \bar X) with a pre-experiment covariate XX, reduces the variance by the factor 1−ρ21 - \rho^2 and stays unbiased; a covariate that the treatment can change biases it.

    13 Regression: the statistics view

    • The linear model is y=Xβ+εy = X\beta + \varepsilon; OLS gives β^=(X⊤X)−1X⊤y\hat\beta = (X^\top X)^{-1}X^\top y (compute it with QR), and it is the Gaussian MLE.
    • β^\hat\beta is random: E[β^]=β\mathbb{E}[\hat\beta] = \beta and Cov⁡(β^)=σ2(X⊤X)−1\operatorname{Cov}(\hat\beta) = \sigma^2(X^\top X)^{-1}; in simple regression Var⁡(β^1)=σ2/Sxx\operatorname{Var}(\hat\beta_1) = \sigma^2/S_{xx}, so spread-out xx values give precise slopes.
    • s2=RSS/(n−p)s^2 = \text{RSS}/(n - p) is unbiased for σ2\sigma^2, because tr⁡(I−H)=n−p\operatorname{tr}(I - H) = n - p; with Gaussian errors (β^j−βj)/SE⁡j∼tn−p(\hat\beta_j - \beta_j)/\operatorname{SE}_j \sim t_{n-p}.
    • The confidence interval for the mean response at x0x_0 uses sh0s\sqrt{h_0} and shrinks to 0 with more data; the prediction interval for a new yy uses s1+h0s\sqrt{1 + h_0} and tends to ±1.96σ\pm 1.96\sigma.
    • R2=1−RSS/TSSR^2 = 1 - \text{RSS}/\text{TSS} never decreases when features are added; nested models are compared with the FF-test, and F=t2F = t^2 for one coefficient.
    • Gauss–Markov: under uncorrelated, equal-variance errors, OLS has the smallest covariance among linear unbiased estimators (BLUE).
    • Residual plots check the assumptions: curvature biases β^\hat\beta, heteroscedastic or correlated errors make the classical standard errors wrong, and high-leverage points can hide in the residuals.
    • Bayesian linear regression with prior N(0,α−1I)\mathcal N(0, \alpha^{-1}I) has posterior N(mN,SN)\mathcal N(m_N, S_N) with SN−1=αI+X⊤X/σ2S_N^{-1} = \alpha I + X^\top X/\sigma^2; mNm_N is ridge with λ=ασ2\lambda = \alpha\sigma^2, and the predictive variance is σ2+x0⊤SNx0\sigma^2 + x_0^\top S_N x_0.

    14 Monte Carlo and importance sampling

    • Monte Carlo estimates μ=Ep[f(X)]\mu = \mathbb{E}_p[f(X)] by 1n∑if(Xi)\frac1n\sum_i f(X_i), with standard error σf/n\sigma_f/\sqrt n in any dimension; report μ^±2sf/n\hat\mu \pm 2s_f/\sqrt n.
    • For a rare event of probability μ\mu, the relative error is about 1/nμ1/\sqrt{n\mu}: you need about 100/μ100/\mu draws for 10% accuracy.
    • Rejection sampling with an envelope p~≤Mq\tilde p \le Mq gives exact draws from p=p~/Zp = \tilde p/Z with acceptance rate Z/MZ/M; it needs a proposal with tails at least as heavy as the target, and fails in high dimension.
    • Importance sampling: μ=Eq[f p/q]\mu = \mathbb{E}_q[f\,p/q]; the estimator is unbiased, its variance is 1n(∫f2p2/q−μ2)\frac1n\big(\int f^2p^2/q - \mu^2\big), and the best proposal is q∝∣f∣pq \propto |f|p.
    • A proposal lighter-tailed than the target gives infinite-variance weights: unbiased, but with no valid error bar, and the failure is silent.
    • Self-normalised IS divides by ∑iwi\sum_i w_i, needs pp only up to a constant, is biased by O(1/n)O(1/n) but consistent; 1n∑iwi\frac1n\sum_i w_i is an unbiased estimate of ZZ. Compute it with log-weights.
    • The effective sample size (∑iwi)2/∑iwi2(\sum_i w_i)^2/\sum_i w_i^2 diagnoses weight collapse; a small value proves trouble, a large value does not prove success.
    • A control variate gg with known mean reduces the variance by the factor 1−ρ21 - \rho^2 at β∗=Cov⁡(f,g)/Var⁡(g)\beta^* = \operatorname{Cov}(f, g)/\operatorname{Var}(g); antithetic pairs give the factor 1+ρ(h(U),h(1−U))1 + \rho(h(U), h(1 - U)) and help for monotone hh.

    15 Markov chains and MCMC

    • A finite Markov chain evolves as μt+1=μtP\mu_{t+1} = \mu_t P; a stationary distribution solves πP=π\pi P = \pi, ∑iπi=1\sum_i \pi_i = 1 (a left eigenvector of PP for eigenvalue 1).
    • If the chain is irreducible and aperiodic, μ0Pt→π\mu_0 P^t \to \pi from any start, with error roughly ∣λ2∣t|\lambda_2|^t; irreducibility alone gives the ergodic theorem, 1n∑tf(Xt)→Eπ[f]\frac1n\sum_t f(X_t) \to \mathbb{E}_\pi[f].
    • Detailed balance πiPij=πjPji\pi_i P_{ij} = \pi_j P_{ji} implies πP=π\pi P = \pi; it is sufficient, not necessary.
    • Metropolis–Hastings accepts x′x' with probability min⁡(1,π~(x′) q(x∣x′)π~(x) q(x′∣x))\min\big(1, \frac{\tilde\pi(x')\,q(x \mid x')}{\tilde\pi(x)\,q(x' \mid x)}\big) and records xx again on a rejection; it satisfies detailed balance and needs only ratios of π~\tilde\pi, so the normalising constant is never needed.
    • Gibbs sampling draws each coordinate from its full conditional; it is Metropolis–Hastings with acceptance 1, and for a bivariate Gaussian with correlation ρ\rho each coordinate is AR(1) with coefficient ρ2\rho^2.
    • HMC adds a momentum p∼N(0,I)p \sim \mathcal N(0, I), follows H=−log⁡π~(x)+12∥p∥2H = -\log\tilde\pi(x) + \tfrac12\|p\|^2 with leapfrog steps (volume preserving, reversible, energy error O(ε2)O(\varepsilon^2)), and accepts with probability min⁡(1,e−ΔH)\min(1, e^{-\Delta H}).
    • ESS =n/τ= n/\tau with τ=1+2∑t≥1ρt\tau = 1 + 2\sum_{t \ge 1}\rho_t; for AR(1) with coefficient φ\varphi, ESS/n=(1−φ)/(1+φ)\text{ESS}/n = (1 - \varphi)/(1 + \varphi).
    • Split-R^\hat R compares between-half-chain and within-half-chain variance over at least 4 chains; trust results only with R^<1.01\hat R < 1.01, total ESS above 400 and no divergences, and remember that chains stuck in the same mode still agree.