Module contents
Lesson 9 of 24Review 85 min

A catalogue of distributions and their generative stories

A dense review of distributions recurring throughout the map, organized by their generative stories: Bernoulli trials, rare-event counts, waiting times, proportions, sums and heavy tails. Study their relationships as limits, sums and ratios, which moments exist, and how to avoid scipy.stats parameterization errors.

After this lesson you can

  • Associate each distribution with a generative process and choose an appropriate model for a phenomenon.
  • Derive the Poisson law as a limit of binomials and the memorylessness of exponential and geometric laws.
  • Relate gamma, chi-squared, beta and Dirichlet laws through sums and ratios of independent gamma variables.
  • Distinguish light, exponential and heavy tails and determine which moments exist.
  • Use scipy.stats without confusing parameterizations (loc, scale, shape, rate versus scale).

Before you start

Motivation: choosing a distribution means choosing a story and a loss

A security service receives an average of 0.50.5 critical alerts per day. You want a model for daily alert counts and the first idea is the default in many libraries: a normal with the same mean and variance (for a Poisson count, variance is also 0.50.5). The model assigns probability P(X<0)=0.240\Pr(X < 0) = 0.240 to fewer than zero alerts. This visible symptom reflects a deeper error: the normal tells one story (a sum of many small contributions of both signs, unbounded), not the phenomenon’s story (rare independent events accumulating in a counter). The right story, Poisson, gives P(X=0)=e−0.5=0.607\Pr(X = 0) = e^{-0.5} = 0.607 and no negative mass.

In machine learning the cost of the wrong choice is double, because a distribution does more than describe data: it fixes the loss function. If you model y∣xy \given \vb{x} with family pθp_\theta and train by maximum likelihood, you minimize −log⁡pθ(y∣x)-\log p_\theta(y \given \vb{x}), and each family yields a different loss:

Generative storyLaw of y∣xy \given \vb{x}Loss −log⁡p-\log p (up to constants)
Real value with light symmetric noisenormal N(μθ,σ2)\Normal(\mu_\theta, \sigma^2)squared error (y−μθ)2/2σ2(y - \mu_\theta)^2/2\sigma^2
The same with outliersLaplace (μθ,b)(\mu_\theta, b)absolute error ∣y−μθ∣/b\abs{y - \mu_\theta}/b
Yes or noBernoulli (σ(zθ))(\sigma(z_\theta))binary cross-entropy
One class among KKcategorical (softmax⁡(zθ))(\softmax(\vb{z}_\theta))cross-entropy −log⁡softmax⁡(zθ)y-\log \softmax(\vb{z}_\theta)_y
A rare-event countPoisson (λθ)(\lambda_\theta)λθ−ylog⁡λθ\lambda_\theta - y\log\lambda_\theta (Poisson deviance)
A real value with heavy tailsStudent ttν+12log⁡(1+(y−μθ)2/(νσ2))\frac{\nu+1}{2}\log\big(1 + (y - \mu_\theta)^2/(\nu\sigma^2)\big)

Each row follows in one line and will recur in regression, classification and network modules. This review therefore does more than catalog formulas: it organizes distributions by their generative story (Bernoulli trials, rare events, waiting times, proportions, sums and heavy tails), which lets you choose the right law and derive its properties. The map outlines the lesson. Each arrow is a construction: a sum, limit, ratio or transformation. Choose one and vary its parameters to watch the starting law become the target law.

InteractiveMap of relationships between distributions
sum of nN → ∞n → ∞, np = λn → ∞sum of rcontinuous timesum of ksum of Z²X/(X+Y)normalizeone componentE₁ − E₂exp(·)Z/√(χ²/ν)Z₁/Z₂exp(E/α)count arrivalsBernoulliBinomialHypergeometricGeometricNegative binomialPoissonExponentialGammaLaplaceBetaDirichletNormalChi-squaredStudent's tCauchyLog-normalPareto
  • Bernoulli trials
  • counts and waiting times
  • proportions
  • normal and derived laws
  • heavy tails
Exponential → Gamma: simulated sum (bars) versus Gamma(1, 1) exact (curve)
01234567
1 / 8
E1+⋯+Ek∼Gam⁡(k,1),Ei∼iidExp⁡(1)E_1 + \cdots + E_k \sim \operatorname{Gam}(k, 1), \quad E_i \iid \operatorname{Exp}(1)
Current parameter: k=1k = 1
Mean: simulated and exact0.968 and 1.000
Variance: simulated and exact0.932 and 1.000
Wait for the kk-th arrival in a process with independent exponential waits: the sum of kk exponentials is gamma (Erlang) with shape kk. For large kk it begins to look like a bell: the central limit theorem in action.
Each arrow is a construction. When selected, bars show the law resulting from the operation (sometimes a simulation of 40004000 samples, sometimes the exact law) and the curve or circles show the exact target law. Start with exponential to gamma: vary kk from 11 to 2020. At what kk does gamma resemble a bell, and why? Try binomial to Poisson with n=3n = 3 and n=1000n = 1000, and hypergeometric to binomial: how large must the urn become? Look at normal to Student tt with ν=1\nu = 1 and then ν=30\nu = 30. For gamma to beta, what happens to the shape when aa and bb are below 11? The figure fixes each demonstration's parameters; we justify them throughout the lesson.

Nearly everything that follows reduces to three moves. Add independent variables (Bernoulli to binomial, exponential to gamma, squared normal to chi-squared). Take limits as a parameter becomes extreme (binomial to Poisson, geometric to exponential, hypergeometric to binomial). Divide one variable by another or by a sum (a gamma divided by a gamma sum gives beta). Once seen, the catalog becomes a network of consequences to reconstruct rather than a list to memorize.

Bernoulli trials: binomial, geometric and relatives

The simplest story is an experiment with two outcomes repeated under the same conditions. We work with discrete random variables as in the random variables lesson: their laws are determined by a mass function p(k)=P(X=k)p(k) = \Pr(X = k).

The binomial is a sum of nn trials, the geometric waits for the first success. The counting arguments behind the formulas are worth seeing once, as a way to reconstruct them without memorization.

Proof

For the binomial, the event “kk specified successes and n−kn - k failures” has probability pkqn−kp^kq^{n-k} by independence, and (nk)\binom{n}{k} ways choose which trials succeed (the binomial theorem confirms masses sum to (p+q)n=1(p + q)^n = 1). Since SnS_n is the sum of nn independent variables with mean pp and variance pqpq, its mean is npnp and by Bienaymé’s variance identity its variance is npqnpq. For geometric, P(G≥k)=qk\Pr(G \ge k) = q^k (the first kk trials fail), and since G≥0G \ge 0 is integer-valued, E[G]=∑k≥1P(G≥k)=∑k≥1qk=q/p\E[G] = \sum_{k \ge 1}\Pr(G \ge k) = \sum_{k \ge 1}q^k = q/p; for variance, E[G(G−1)]=∑k≥2k(k−1)qkp=2q2/p2\E[G(G - 1)] = \sum_{k \ge 2}k(k-1)q^kp = 2q^2/p^2, giving Var⁡(G)=2q2/p2+q/p−q2/p2=q/p2\Var(G) = 2q^2/p^2 + q/p - q^2/p^2 = q/p^2. Count the negative binomial by choosing slots for failures: the rr-th success occurs after exactly kk failures if and only if trial k+rk + r succeeds and the preceding k+r−1k + r - 1 trials contain r−1r - 1 successes and kk failures in any order. There are (k+r−1k)\binom{k + r - 1}{k} orders, each with probability pr−1qk⋅pp^{r-1}q^k \cdot p. This also counts distributing kk failures among rr slots before each success, i.e. nonnegative integer solutions of g1+⋯+gr=kg_1 + \cdots + g_r = k counted by stars and bars. Another reading follows: Fr=G1+⋯+GrF_r = G_1 + \cdots + G_r, the sum of rr independent geometric variables (failures before each success), so its mean is rq/prq/p and variance rq/p2rq/p^2. In the multinomial, NiN_i is binomial Bin⁡(n,pi)\Bin(n, p_i) (each trial is “ii or not”), and for i≠ji \ne j, Ni=∑t1[Yt=i]N_i = \sum_t \ind[Y_t = i], Nj=∑t1[Yt=j]N_j = \sum_t \ind[Y_t = j] with Cov⁡(1[Yt=i],1[Yt=j])=0−pipj\Cov(\ind[Y_t = i], \ind[Y_t = j]) = 0 - p_ip_j (the events are incompatible), and covariance zero across different trials, giving Cov⁡(Ni,Nj)=−npipj\Cov(N_i, N_j) = -np_ip_j.

∎

The multinomial’s negative signs matter: if NiN_i rises, the rest must fall because the sum is fixed at nn. This occurs in token counts in a corpus or class-specific successes in an evaluation set, and is why simultaneous confidence intervals for category proportions cannot be built as if they were independent. The categorical law also describes a language model’s output at each step: sampling the next token is a categorical draw with p=softmax⁡(z)\vb{p} = \softmax(\vb{z}), and training with cross-entropy is categorical maximum likelihood.

Sampling without replacement: the hypergeometric

The binomial assumes independent trials: after each draw, the urn returns to its initial state. Drawing nn balls without replacement from an urn of NN balls, KK of them red, makes trials dependent: drawing red reduces the remaining red fraction. This describes a minibatch drawn from a dataset within one training epoch, or an audit sample from a finite population.

The formula counts favorable over possible cases: choose kk red balls among KK and the remaining n−kn - k among N−KN - K non-red balls, divided by all subsets of size nn. Mean and variance follow from writing H=∑i=1nIiH = \sum_{i=1}^n I_i with IiI_i the indicator that draw ii is red. Each IiI_i is Bern⁡(p)\Bern(p) with p=K/Np = K/N (by symmetry: draws are exchangeable), so E[H]=np\E[H] = np. For variance use covariance between two distinct draws, Cov⁡(Ii,Ij)=K(K−1)N(N−1)−p2=−p(1−p)N−1\Cov(I_i, I_j) = \frac{K(K-1)}{N(N-1)} - p^2 = -\frac{p(1-p)}{N-1}, the negative correlation ρ=−1/(N−1)\rho = -1/(N-1) seen in the moments lesson for sampling without replacement. This gives

Var⁡(H)=np(1−p)+n(n−1)( ⁣−p(1−p)N−1)=np(1−p) N−nN−1.\Var(H) = np(1-p) + n(n-1)\Big(\!-\frac{p(1-p)}{N-1}\Big) = np(1-p)\,\frac{N-n}{N-1}.

Factor (N−n)/(N−1)(N - n)/(N - 1) is the finite-population correction: it equals 11 when n=1n = 1, decreases with nn and vanishes at n=Nn = N, when the whole urn is drawn and the red count is KK without uncertainty. With N=50N = 50, K=20K = 20 and n=10n = 10, variance is 1.9591.959 versus 2.42.4 for a binomial with the same p=0.4p = 0.4.

Proof

Using falling-factorial notation (a)m=a(a−1)⋯(a−m+1)(a)_m = a(a-1)\cdots(a-m+1), (Kk)(N−Kn−k)/(Nn)=(nk) (K)k (N−K)n−k(N)n\binom{K}{k}\binom{N-K}{n-k}/\binom{N}{n} = \binom{n}{k}\,\dfrac{(K)_k\,(N-K)_{n-k}}{(N)_n}: the same case count, but ordering the draws. If aN/N→c≥0a_N/N \to c \ge 0 and mm is fixed, (aN)m/Nm=∏j=0m−1(aN−j)/N→cm(a_N)_m/N^m = \prod_{j=0}^{m-1}(a_N - j)/N \to c^m, because each of mm factors tends to cc. Applied to KN/N→pK_N/N \to p, (N−KN)/N→1−p(N - K_N)/N \to 1 - p and N/N=1N/N = 1, ratio (K)kNk⋅(N−K)n−kNn−k⋅Nn(N)n\dfrac{(K)_k}{N^k}\cdot\dfrac{(N-K)_{n-k}}{N^{n-k}}\cdot\dfrac{N^n}{(N)_n} tends to pk(1−p)n−kp^k(1-p)^{n-k}, including boundary cases p=0p = 0 and p=1p = 1.

∎

In words: if the urn is enormous relative to the sample, replacement makes no difference. The proof also specifies how enormous: nn fixed and N→∞N \to \infty. With N=50N = 50 and n=10n = 10, the binomial is still wrong in the second decimal place of P(H=4)\Pr(H = 4) (0.28010.2801 exact versus 0.25080.2508); the map’s hypergeometric-to-binomial transition ranges from N=10N = 10 (where the hypergeometric is a point mass) to N=3000N = 3000.

Rare events: the Poisson law

A service receives calls, a server suffers failures, a social network receives incoming links: in each case there are many opportunities for an event, each with tiny probability independent of the others, and the observed quantity is the total count. A binomial describes this story, but with enormous nn and tiny pp. Poisson is the limiting law, with only one quantity that matters: the expected count λ=np\lambda = np.

The masses sum to 11 by the expansion of eλe^\lambda, which also gives moments: E[X]=∑k≥1k e−λλk/k!=λ∑k≥1e−λλk−1/(k−1)!=λ\E[X] = \sum_{k\ge1} k\,e^{-\lambda}\lambda^k/k! = \lambda\sum_{k\ge1}e^{-\lambda}\lambda^{k-1}/(k-1)! = \lambda; similarly E[X(X−1)]=λ2\E[X(X-1)] = \lambda^2, so Var⁡(X)=λ2+λ−λ2=λ\Var(X) = \lambda^2 + \lambda - \lambda^2 = \lambda. Mean and variance agree: Poisson’s signature and a common diagnostic (if count data have variance much greater than mean, the Poisson story is wrong and a more flexible one, such as negative binomial, is needed).

Proof

Fix kk. For n≥kn \ge k,

P(Xn=k)=n(n−1)⋯(n−k+1)k!(λn)k(1−λn)n−k=λkk!  ∏j=0k−1(1−jn)⏟→ 1  (1−λn)−k⏟→ 1  (1−λn)n.\Pr(X_n = k) = \frac{n(n-1)\cdots(n-k+1)}{k!}\Big(\frac{\lambda}{n}\Big)^k\Big(1 - \frac{\lambda}{n}\Big)^{n-k} = \frac{\lambda^k}{k!}\;\underbrace{\prod_{j=0}^{k-1}\Big(1 - \frac{j}{n}\Big)}_{\to\,1}\;\underbrace{\Big(1 - \frac{\lambda}{n}\Big)^{-k}}_{\to\,1}\;\Big(1 - \frac{\lambda}{n}\Big)^{n}.

The first product has kk factors, each with limit 11, and since kk is fixed its limit is 11; the second factor’s base tends to 11 and its exponent is fixed. The final factor remains: by the Taylor expansion log⁡(1−u)=−u+O(u2)\log(1 - u) = -u + \bigO(u^2),

nlog⁡(1−λn)=−λ+O(1/n)⟶−λ,n\log\Big(1 - \frac{\lambda}{n}\Big) = -\lambda + \bigO(1/n) \longrightarrow -\lambda,

and by continuity of the exponential (1−λ/n)n→e−λ(1 - \lambda/n)^n \to e^{-\lambda} (a sequence limit worth knowing how to prove, not just cite). Multiplying the limits gives the result.

∎

Pointwise convergence of masses is true, but a model calculates probabilities of sets of values, not just individual values. The appropriate notion is total variation distance between two discrete laws, TV⁡(P,Q)=sup⁡A∣P(A)−Q(A)∣=12∑k∣P(k)−Q(k)∣\operatorname{TV}(P, Q) = \sup_A\abs{P(A) - Q(A)} = \tfrac12\sum_k\abs{P(k) - Q(k)}. If PnP_n and QQ are laws on the integers and Pn(k)→Q(k)P_n(k) \to Q(k) for every kk, then TV⁡(Pn,Q)→0\operatorname{TV}(P_n, Q) \to 0 (Scheffé’s lemma): since ∑k(Q(k)−Pn(k))=0\sum_k(Q(k) - P_n(k)) = 0, the distance is ∑k(Q(k)−Pn(k))+\sum_k(Q(k) - P_n(k))^+, a sum of terms tending to 00 dominated by Q(k)Q(k), which is summable; dominated convergence for series gives the limit. The next figure measures it.

InteractiveFrom binomial to Poisson
Binomial(n,λ/n)(n, \lambda/n) (bars) versus Poisson(λ)(\lambda) (circles)
01234567891011121314
  • binomial P(X=k)\Pr(X = k)
  • Poisson e−λλk/k!e^{-\lambda}\lambda^k/k!
Total variation distance versus nn (log-log)
10100100010000110⁻¹10⁻²10⁻³10⁻⁴10⁻⁵
  • Exact TV
  • bound λ2/n\lambda^2/n
3.0
n = 3
nn and p=λ/np = \lambda/n3 and 1.0000
Exact total variation distance0.7760
Le Cam bound λ2/n\lambda^2/n1.0000
Refined bound λ(1−e−λ/n)\lambda(1 - e^{-\lambda/n})1.0000
Exact / bound λ2/n\lambda^2/n0.776
P(X=0)\Pr(X = 0): binomial and Poisson0.0000 and 0.0498
With n≈λn \approx \lambda the success probability p=λ/np = \lambda/n is nearly 11: this is not the rare-event regime and the approximation is poor.
Left: the pmfs of Binomial(n,λ/n)(n, \lambda/n) and Poisson(λ)(\lambda). Right: exact total variation distance versus nn (log–log), with Le Cam's λ2/n\lambda^2/n bound. Press play and watch the bars approach the circles. With λ=3\lambda = 3, from what nn do they look identical? What is the distance then? The exact curve is parallel to the bound (slope −1-1): the bound has the right order in nn, but how wrong is its constant? Raise λ\lambda to 1212: does the exact-to-bound ratio improve or worsen?

Two readings. First, error decays as 1/n1/n and no faster, explaining why the approximation is good with n=100n = 100 trials but not n=10n = 10. Second, Le Cam’s bound, proved now, has the right order but a pessimistic constant.

Proof

Three pieces. (i) For one summand, TV⁡(Bern⁡(p),Pois⁡(p))=p(1−e−p)\operatorname{TV}(\Bern(p), \Pois(p)) = p(1 - e^{-p}). Indeed Pois⁡(p)\Pois(p) assigns e−pe^{-p} to 00 (more than 1−p1 - p because e−p≥1−pe^{-p} \ge 1 - p), pe−ppe^{-p} to 11 (less than pp), and 1−e−p−pe−p1 - e^{-p} - pe^{-p} to the remaining integers, where Bern⁡(p)\Bern(p) has no mass. Distance is the sum of positive differences of Pois⁡(p)\Pois(p) over Bern⁡(p)\Bern(p): (e−p−1+p)+(1−e−p−pe−p)=p−pe−p(e^{-p} - 1 + p) + (1 - e^{-p} - pe^{-p}) = p - pe^{-p}. (ii) Total variation is subadditive for sums of independent variables: TV⁡(P1∗P2,Q1∗Q2)≤TV⁡(P1,Q1)+TV⁡(P2,Q2)\operatorname{TV}(P_1 * P_2, Q_1 * Q_2) \le \operatorname{TV}(P_1, Q_1) + \operatorname{TV}(P_2, Q_2), where ∗* is convolution. Pass through intermediate Q1∗P2Q_1 * P_2 and use that convolution with a law RR cannot increase distance: ∑x∣∑y(P−Q)(x−y)R(y)∣≤∑yR(y)∑x∣(P−Q)(x−y)∣=2TV⁡(P,Q)\sum_x\abs{\sum_y(P - Q)(x - y)R(y)} \le \sum_yR(y)\sum_x\abs{(P - Q)(x - y)} = 2\operatorname{TV}(P, Q). (iii) A sum of independent Poisson variables is Poisson: by the binomial theorem, ∑je−aajj!e−bbm−j(m−j)!=e−(a+b)m!∑j(mj)ajbm−j=e−(a+b)(a+b)mm!\sum_{j}\frac{e^{-a}a^j}{j!}\frac{e^{-b}b^{m-j}}{(m-j)!} = \frac{e^{-(a+b)}}{m!}\sum_j\binom{m}{j}a^jb^{m-j} = \frac{e^{-(a+b)}(a+b)^m}{m!}. Then Pois⁡(λ)=Pois⁡(p1)∗⋯∗Pois⁡(pn)\Pois(\lambda) = \Pois(p_1) * \cdots * \Pois(p_n) and applying (ii) nn times with (i) gives the first inequality. The second follows from 1−e−p≤p1 - e^{-p} \le p.

∎

For λ=3\lambda = 3, exact numbers (cell below) are TV⁡=0.0864\operatorname{TV} = 0.0864 with n=10n = 10 versus bound 0.90.9, and TV⁡=0.00075\operatorname{TV} = 0.00075 with n=1000n = 1000 versus 0.0090.009: the bound is about twelve times reality and the ratio stabilizes because true distance behaves as 0.75/n0.75/n. The Chen–Stein refinement (Barbour and Hall, 1984) reduces the bound to (1−e−λ)λ/n(1 - e^{-\lambda})\lambda/n, only four times larger. Beyond constants, the rule of thumb is Poisson approximation is reasonable when ∑ipi2\sum_ip_i^2 is small, even if pip_i differ, as in actual failure or click counts.

Waiting times: exponential, gamma and chi-squared

Now view the same story in time. If Poisson events occur at rate λ\lambda per unit time, how long until the first? Divide time into nn pieces of length 1/n1/n with a trial of probability λ/n\lambda/n each: the wait in pieces is geometric. As the mesh refines, this rescaled geometric tends to the continuous-time waiting law.

Memorylessness

The exponential has a property characterizing it among continuous laws. If you have already waited ss with nothing happening, the remaining wait has exactly the same law as at the start.

Proof

For the exponential, S(s+t)=e−λ(s+t)=e−λse−λtS(s + t) = e^{-\lambda(s+t)} = e^{-\lambda s}e^{-\lambda t}; for the failure-counting geometric, P(G≥s+t)=qs+t=qsqt\Pr(G \ge s + t) = q^{s+t} = q^sq^t. Uniqueness is proved at the end (first proof exercise): solve Cauchy’s functional equation S(s+t)=S(s)S(t)S(s + t) = S(s)S(t) with monotone SS.

∎

Memorylessness formalizes absence of wear or burn-in: instantaneous event risk h(t)=f(t)/S(t)h(t) = f(t)/S(t) is constant. A gamma with shape k≠1k \neq 1 does not have this: risk increases with k>1k > 1 (something that wears, like a mechanical component) and decreases with k<1k < 1 (something sturdy if it survives the start, like infant failures of a chip). The next figure shows it.

InteractiveMemorylessness and residual life
Survival from zero and survival conditional on T>sT > s
0246800.51
  • P(T>t)\Pr(T > t)
  • P(T>s+t∣T>s)\Pr(T > s + t \mid T > s)
  • simulation
Hazard h(t) E[T]h(t)\,\mathbb{E}[T] and residual life m(t)/E[T]m(t)/\mathbb{E}[T] (both 11 for the exponential)
024680123
  • riesgo h(t)=f(t)/S(t)h(t) = f(t)/S(t)
  • vida residual media m(t)m(t)
2.00
1.5
1.5
P(T>t)\Pr(T > t) (from zero)0.5578
P(T>s+t∣T>s)\Pr(T > s + t \mid T > s)0.3570
Difference (conditional − unconditional)−0.2008
Simulation: P(T−s>t∣T>s)\Pr(T - s > t \mid T > s) with 2258 survivors0.3454
Mean residual life E[T−s∣T>s]\mathbb{E}[T - s \mid T > s]1.400
Mean from zero E[T]=k\mathbb{E}[T] = k2.000
With k>1k > 1 the hazard increases (wear): someone who has waited has less time left than a newcomer (the conditional curve is below).
A waiting time T∼Gam⁡(k,1)T \sim \operatorname{Gam}(k, 1). Left: survival from zero (dashed) and conditional survival after already waiting ss (solid), with points from 40004000 simulated waits (retaining those above ss). Right: hazard h(t)h(t) and mean residual life m(t)=E[T−t∣T>t]m(t) = \E[T - t \given T > t], both normalized by E[T]=k\E[T] = k. Start with k=2k = 2 and move ss: which way does conditional survival change? Set kk to 11: curves overlap and those on the right flatten at 11. Now k=0.5k = 0.5: who has longer to wait, someone already waiting five units or a newcomer?

This warns against simplistic failure-time and latency models. If data show those waiting longer will wait still longer (decreasing hazard), the exponential predicts an overoptimistic residual time and a gamma with k<1k < 1 or a heavier-tailed law is needed (see the heavy-tail section).

Sums and ratios of gamma variables

A key calculation using change of variables gives three results at once: a sum of gammas is gamma, the proportion is beta, and the two are independent.

Proof

The joint density of (X,Y)(X, Y) is βa+bΓ(a)Γ(b)xa−1yb−1e−β(x+y)\dfrac{\beta^{a+b}}{\Gamma(a)\Gamma(b)}x^{a-1}y^{b-1}e^{-\beta(x+y)} on x,y>0x, y > 0. Change variables x=sux = su, y=s(1−u)y = s(1 - u), with s>0s > 0 and 0<u<10 < u < 1, a bijection with Jacobian ∂(x,y)/∂(s,u)=∣us1−u−s∣\partial(x, y)/\partial(s, u) = \begin{vmatrix} u & s \\ 1 - u & -s \end{vmatrix} of absolute value ss. By the density change-of-variables formula, the joint density of (S,U)(S, U) is

βa+bΓ(a)Γ(b) (su)a−1(s(1−u))b−1e−βs⋅s=[βa+bΓ(a+b)sa+b−1e−βs]⋅[Γ(a+b)Γ(a)Γ(b)ua−1(1−u)b−1].\frac{\beta^{a+b}}{\Gamma(a)\Gamma(b)}\,(su)^{a-1}\big(s(1-u)\big)^{b-1}e^{-\beta s}\cdot s = \Big[\frac{\beta^{a+b}}{\Gamma(a+b)}s^{a+b-1}e^{-\beta s}\Big]\cdot\Big[\frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)}u^{a-1}(1-u)^{b-1}\Big].

This is a product of a function of ss and one of uu on a rectangle: by the density characterization of independence, S⊥ ⁣ ⁣ ⁣⊥US \indep U, and each bracket, normalized, is a marginal density. The first is that of Gam⁡(a+b,β)\operatorname{Gam}(a + b, \beta) and the second a beta. Since both are densities, the second integrates to 11, also proving ∫01ua−1(1−u)b−1 ⁣du=Γ(a)Γ(b)/Γ(a+b)\int_0^1u^{a-1}(1-u)^{b-1}\dd u = \Gamma(a)\Gamma(b)/\Gamma(a + b).

∎

Three frequently used consequences. First, a sum of independent gammas with the same rate is gamma, and by induction the sum of kk exponentials of rate β\beta is Gam⁡(k,β)\operatorname{Gam}(k, \beta), seen in the exponential-to-gamma map. Second, beta is a normalized gamma, a ratio of form X/(X+Y)X/(X + Y). Third, waiting time until arrival number kk in a process with exponential waits is gamma, connected to Poisson counts through a duality proved by differentiation.

Proof

Equality of events defines NtN_t. For equality of probabilities, differentiate the right side with respect to tt. With m=λtm = \lambda t,  ⁣d ⁣dm(e−mmjj!)=e−m(mj−1(j−1)!−mjj!)\frac{\dd}{\dd m}\big(e^{-m}\frac{m^j}{j!}\big) = e^{-m}\big(\frac{m^{j-1}}{(j-1)!} - \frac{m^j}{j!}\big), and summing for j≥kj \ge k terms cancel in a telescoping sum, leaving e−mmk−1(k−1)!e^{-m}\frac{m^{k-1}}{(k-1)!}. Multiplied by  ⁣dm/ ⁣dt=λ\dd m/\dd t = \lambda, this is density Gam⁡(k,λ)\operatorname{Gam}(k, \lambda) of TkT_k. Both sides equal 00 at t=0t = 0 and have the same derivative, so agree.

∎

This links the stories: exponential waits, Poisson counts. With three alerts per day on average, the probability the third arrives before 2424 hours is P(Pois⁡(3)≥3)=1−8.5 e−3=0.5768\Pr(\Pois(3) \ge 3) = 1 - 8.5\,e^{-3} = 0.5768. The map’s exponential-to-Poisson edge simulates this: count arrivals with exponential waits in one unit of time and compare with the Poisson pmf.

Chi-squared

We must justify that χk2=Gam⁡(k/2,1/2)\chi^2_k = \operatorname{Gam}(k/2, 1/2) is what its name says: a sum of squares of independent standard normals. For k=1k = 1, if Z∼N(0,1)Z \sim \Normal(0, 1), the distribution function of Z2Z^2 is P(Z2≤y)=P(−y≤Z≤y)\Pr(Z^2 \le y) = \Pr(-\sqrt{y} \le Z \le \sqrt{y}), which differentiated with respect to yy gives 22πe−y/212y=12πy−1/2e−y/2\dfrac{2}{\sqrt{2\pi}}e^{-y/2}\dfrac{1}{2\sqrt{y}} = \dfrac{1}{\sqrt{2\pi}}y^{-1/2}e^{-y/2}, density Gam⁡(1/2,1/2)\operatorname{Gam}(1/2, 1/2), since Γ(1/2)=π\Gamma(1/2) = \sqrt{\pi} and (1/2)1/2/π=1/2π(1/2)^{1/2}/\sqrt{\pi} = 1/\sqrt{2\pi}. The remainder is a sum of gammas: Z12+⋯+Zk2∼Gam⁡(k/2,1/2)Z_1^2 + \cdots + Z_k^2 \sim \operatorname{Gam}(k/2, 1/2).

Laplace: the difference of two exponentials

An exponential lives only on t≥0t \ge 0. Subtract two independent exponentials with the same rate to obtain a symmetric variable with exponential tails on both sides: the double exponential or Laplace law.

If E1,E2∼iidExp⁡(1/b)E_1, E_2 \iid \operatorname{Exp}(1/b), then E1−E2∼Lap⁡(0,b)E_1 - E_2 \sim \operatorname{Lap}(0, b). For x>0x > 0, its density is ∫0∞1be−(x+y)/b 1be−y/b ⁣dy=1b2e−x/b⋅b2=12be−x/b\int_0^\infty\frac1be^{-(x+y)/b}\,\frac1be^{-y/b}\dd y = \frac{1}{b^2}e^{-x/b}\cdot\frac b2 = \frac{1}{2b}e^{-x/b}, and by symmetry the same for x<0x < 0. Thus mean μ\mu, variance 2b22b^2, skewness 00 and kurtosis 66 (from the moments table): heavier tails than normal, though still exponential, with all moments.

Its statistical importance is absolute value. A sample x1,…,xnx_1, \dots, x_n has log likelihood, up to constants, −1b∑i∣xi−μ∣-\frac1b\sum_i\abs{x_i - \mu}, and function μ↦∑i∣xi−μ∣\mu \mapsto \sum_i\abs{x_i - \mu} is convex and piecewise linear with derivative #{xi<μ}−#{xi>μ}\#\{x_i < \mu\} - \#\{x_i > \mu\} where it exists. That derivative changes sign as μ\mu crosses half the observations, so the maximum-likelihood estimator of Laplace location is the sample median, just as for normal it is the mean. The scale estimator evaluated at the median is mean absolute deviation b^=1n∑i∣xi−mediana∣\hat b = \frac1n\sum_i\abs{x_i - \text{mediana}}.

InteractiveLaplace and the median
Data and maximum-likelihood fitted densities
−4048
  • fitted normal (center: mean)
  • fitted Laplace (center: median)
  • data
Mean error when summarizing the data by a number cc
−40480246
  • root mean squared error (minimum: mean)
  • mean absolute error (minimum: median)
Data set
Mean (normal MLE)0.800
Median (Laplace MLE)0.000
Normal σ^\hat\sigma and Laplace b^\hat b2.944 and 1.943
Normal log-likelihood−17.49
Laplace log-likelihood−16.50
The mean shifts toward the distant point but the median barely moves; Laplace explains the data better than normal (higher log-likelihood).
Seven draggable observations. Left: two maximum-likelihood fitted densities: normal with data mean and standard deviation, and Laplace with median and mean absolute deviation. Right: error of summarizing the data with one number cc: root mean squared error (minimized by the mean) and mean absolute error (minimized by the median). Drag the most extreme point rightward: which summary follows it? Compare log likelihoods: which model better explains data with an outlier? With Two groups, drag a point from one group to the other and see whether the median moves continuously.

This law appears in machine learning for two reasons. First, a Laplace prior on regression weights, p(wj)∝e−∣wj∣/bp(w_j) \propto e^{-\abs{w_j}/b}, makes the maximum-a-posteriori estimator minimize squared error plus penalty ℓ1\ell_1: lasso, with the density’s sharp peak at 00 generating exactly zero weights. Second is differential privacy. If query ff changes by at most Δ\Delta when one record changes, the mechanism responding f(D)+Lap⁡(0,b)f(D) + \operatorname{Lap}(0, b) with b=Δ/εb = \Delta/\varepsilon has response density ratio yy for neighboring databases D,D′D, D'

p(y∣D)p(y∣D′)=exp⁡(∣y−f(D′)∣−∣y−f(D)∣b)≤exp⁡(∣f(D)−f(D′)∣b)≤eε,\frac{p(y \given D)}{p(y \given D')} = \exp\Big(\frac{\abs{y - f(D')} - \abs{y - f(D)}}{b}\Big) \le \exp\Big(\frac{\abs{f(D) - f(D')}}{b}\Big) \le e^{\varepsilon},

by the triangle inequality. That uniform bound defines ε\varepsilon-differential privacy (Dwork, McSherry, Nissim and Smith, 2006): Laplace bounds the ratio for all outputs yy, unlike a Gaussian under this scheme. With sensitivity Δ=1\Delta = 1 and ε=0.5\varepsilon = 0.5, noise has scale b=2b = 2 and exceeds 33 in absolute value with probability e−3/2=0.223e^{-3/2} = 0.223.

Proportions: beta and Dirichlet

A proportion is a variable on [0,1][0, 1]: an advertisement’s click-through rate, an unknown coin probability, or a budget fraction. Its natural law is beta, already seen as the law of X/(X+Y)X/(X + Y) with X,YX, Y independent gammas of equal rate. For more than two categories, when allocation among them matters, Dirichlet generalizes it.

The best way to understand Dirichlet is to generate it. The proof repeats the gamma–beta theorem with a larger Jacobian.

Proof

Use substitution gi=sxig_i = sx_i for i<Ki < K and gK=s(1−∑i<Kxi)g_K = s(1 - \sum_{i<K}x_i), with s>0s > 0; its Jacobian has absolute value sK−1s^{K-1} (the matrix that was ss in the two-variable proof). With joint density ∏igiαi−1e−gi/Γ(αi)\prod_ig_i^{\alpha_i-1}e^{-g_i}/\Gamma(\alpha_i) and ∑igi=s\sum_ig_i = s, joint density of (s,x1,…,xK−1)(s, x_1, \dots, x_{K-1}) is sα0−Ke−s sK−1∏iΓ(αi)∏ixiαi−1=[sα0−1e−sΓ(α0)][Γ(α0)∏iΓ(αi)∏ixiαi−1]\dfrac{s^{\alpha_0 - K}e^{-s}\,s^{K-1}}{\prod_i\Gamma(\alpha_i)}\prod_ix_i^{\alpha_i-1} = \Big[\dfrac{s^{\alpha_0-1}e^{-s}}{\Gamma(\alpha_0)}\Big]\Big[\dfrac{\Gamma(\alpha_0)}{\prod_i\Gamma(\alpha_i)}\prod_ix_i^{\alpha_i-1}\Big], product of the density of Gam⁡(α0,1)\operatorname{Gam}(\alpha_0, 1) and the Dirichlet density. Consequences follow from Gi=SXiG_i = SX_i with S⊥ ⁣ ⁣ ⁣⊥XS \indep \vb{X}: E[Gi]=αi=E[S]E[Xi]=α0E[Xi]\E[G_i] = \alpha_i = \E[S]\E[X_i] = \alpha_0\E[X_i] gives the mean; E[Gi2]=αi(αi+1)=E[S2]E[Xi2]=α0(α0+1)E[Xi2]\E[G_i^2] = \alpha_i(\alpha_i + 1) = \E[S^2]\E[X_i^2] = \alpha_0(\alpha_0 + 1)\E[X_i^2] the second moment; E[GiGj]=αiαj=α0(α0+1)E[XiXj]\E[G_iG_j] = \alpha_i\alpha_j = \alpha_0(\alpha_0 + 1)\E[X_iX_j] covariance. Parts (ii) and (iii) apply the previous theorem to GiG_i versus ∑j≠iGj\sum_{j \ne i}G_j (gamma with α0−αi\alpha_0 - \alpha_i by gamma addition), and similarly for groups.

∎

Negative covariance parallels the multinomial: components sum to 11. The figure interprets the parameters.

InteractiveDirichlet in the triangle
Dirichlet(α1,α2,α3)(\alpha_1, \alpha_2, \alpha_3) density and samples on the simplex
x₁ = 1x₂ = 1x₃ = 1
One sample: Gi∼Gam⁡(αi,1)G_i \sim \operatorname{Gam}(\alpha_i, 1) and Xi=Gi/∑jGjX_i = G_i / \sum_j G_j (the large filled point in the triangle)
G1 = 0.422G2 = 0.003G3 = 0.828sum 1.253 ⇒ divide by the sum0.340.66
Marginal of X1X_1 in 700 samples versus Beta(α1,α0−α1)(\alpha_1, \alpha_0 - \alpha_1) = Beta(0.50,1.00)(0.50, 1.00)
00.51
  • histogram of X1X_1
  • exact Beta density
Typical cases
0.50
0.50
0.50
Concentration α0=∑iαi\alpha_0 = \sum_i \alpha_i1.50
Mean αi/α0\alpha_i/\alpha_00.333 0.333 0.333
Mean of 700 samples0.328 0.319 0.352
P(max⁡iXi>0.9)\Pr(\max_i X_i > 0.9): exact and sample0.154 and 0.154
Modeno interior mode
Selected point (x1,x2,x3)(x_1, x_2, x_3)0.50 0.30 0.20
Density at the point (with respect to dx1dx2\mathrm{d}x_1\mathrm{d}x_2)0.919
With every αi<1\alpha_i < 1, density diverges near each edge (where some xi=0x_i = 0), and even more at the vertices. Mass accumulates at corners and edges: samples place almost all weight on one or two categories (sparse distributions).
A three-component Dirichlet density on the simplex, drawn as a triangle (vertex xi=1x_i = 1 allocates everything to category ii), with 700700 samples colored by dominant component. Right: one sample built from normalized gammas and the marginal of X1X_1 versus the beta predicted by the theorem. Start with α=0.5\alpha = 0.5 for all three: mass clings to vertices and edges. Raise them to 88: density concentrates in the center. Set α=(6,2,2)\alpha = (6, 2, 2) and watch the mean move. Click the triangle to read density at a point. What happens to the marginal of X1X_1 when α1<1\alpha_1 < 1?

Two qualitative regimes. With αi<1\alpha_i < 1, density diverges near face xi=0x_i = 0 and mass clusters at corners and edges: allocations are sparse, with nearly all mass on few categories. This is desirable in topic modeling, where each document covers few topics: the Dirichlet prior in latent Dirichlet allocation (Blei, Ng and Jordan, 2003) has small α\alpha. With αi>1\alpha_i > 1 there is an interior mode at (αi−1)/(α0−K)(\alpha_i - 1)/(\alpha_0 - K) and, the larger α0\alpha_0, the more tightly allocations concentrate around the mean. α0\alpha_0 acts as the prior’s sample size, visible in conjugacy.

Proof

By Bayes’ rule the posterior density is proportional to likelihood times prior: pk(1−p)n−k⋅pa−1(1−p)b−1=pa+k−1(1−p)b+n−k−1p^k(1-p)^{n-k}\cdot p^{a-1}(1-p)^{b-1} = p^{a+k-1}(1-p)^{b+n-k-1}, the kernel of Beta⁡(a+k,b+n−k)\operatorname{Beta}(a + k, b + n - k); the normalizing constant follows. The multinomial is identical with ∏ipiki+αi−1\prod_ip_i^{k_i + \alpha_i - 1}.

∎

Thus with uniform prior Beta⁡(1,1)\operatorname{Beta}(1, 1) and seven successes in ten trials, the posterior is Beta⁡(8,4)\operatorname{Beta}(8, 4) with mean 2/32/3 and central 95 %95\,\% interval approximately [0.39,0.89][0.39, 0.89]. Parameters a,ba, b are interpreted as pseudo-successes and pseudo-failures. This conjugacy, with aa and bb accumulating data, is the thread of conjugate priors in statistics. Outside inference, beta appears in mixup data augmentation, mixing two examples with weight λ∼Beta⁡(α,α)\lambda \sim \operatorname{Beta}(\alpha, \alpha) (Zhang et al., 2018): with α<1\alpha < 1, weight is usually near 00 or 11 (examples hardly mix), while for large α\alpha it is near 1/21/2.

The univariate normal and standardization

The normal needs no introduction, but its uses and proofs deserve review.

The constant follows from the Gaussian integral ∫−∞∞e−x2/2 ⁣dx=2π\int_{-\infty}^\infty e^{-x^2/2}\dd x = \sqrt{2\pi} (Gaussian integral). Standardization observes that all normal laws are the same up to location and scale: if X∼N(μ,σ2)X \sim \Normal(\mu, \sigma^2) then Z=(X−μ)/σ∼N(0,1)Z = (X - \mu)/\sigma \sim \Normal(0, 1) because P(Z≤z)=P(X≤μ+σz)=∫−∞μ+σzf\Pr(Z \le z) = \Pr(X \le \mu + \sigma z) = \int_{-\infty}^{\mu + \sigma z}f, and substitution x=μ+σux = \mu + \sigma u turns that integral into ∫−∞zφ\int_{-\infty}^z\varphi. Conversely X=μ+σZX = \mu + \sigma Z: any normal is an affine transform of the standard one, a sampling recipe and the basis of reparameterization in generative models. Every normal probability reduces to Φ\Phi.

Even moments follow from the gamma function: with u=z2/2u = z^2/2,

E[Z2k]=22π∫0∞z2ke−z2/2 ⁣dz=2k Γ(k+12)π=(2k−1)!!=1⋅3⋯(2k−1),\E[Z^{2k}] = \frac{2}{\sqrt{2\pi}}\int_0^\infty z^{2k}e^{-z^2/2}\dd z = \frac{2^k\,\Gamma(k + \frac12)}{\sqrt{\pi}} = (2k - 1)!! = 1 \cdot 3 \cdots (2k - 1),

and odd moments are 00 by symmetry. Thus E[Z2]=1\E[Z^2] = 1 and E[Z4]=3\E[Z^4] = 3, the reference kurtosis (skewness and kurtosis). All normal moments exist and depend only on variance; this is special, explaining why many results for a normal do not survive other laws.

The normal tail is particularly useful. Since Φ\Phi has no closed form, we need bounds that do.

Proof

Upper bound: for x≥tx \ge t, 1≤x/t1 \le x/t, hence ∫t∞φ(x) ⁣dx≤∫t∞xtφ(x) ⁣dx=φ(t)t\int_t^\infty\varphi(x)\dd x \le \int_t^\infty\frac xt\varphi(x)\dd x = \frac{\varphi(t)}{t} because φ′(x)=−xφ(x)\varphi'(x) = -x\varphi(x). Lower bound:  ⁣d ⁣dx(−φ(x)/x)=φ(x)(1+x−2)\frac{\dd}{\dd x}\big(-\varphi(x)/x\big) = \varphi(x)(1 + x^{-2}), so φ(t)/t=∫t∞(1+x−2)φ(x) ⁣dx≤(1+t−2)(1−Φ(t))\varphi(t)/t = \int_t^\infty(1 + x^{-2})\varphi(x)\dd x \le (1 + t^{-2})(1 - \Phi(t)); rearrange to obtain the result.

∎

The bounds converge as tt grows: the Gaussian tail decays as e−t2/2e^{-t^2/2} (with correction 1/t1/t). At t=3t = 3 the tail is 0.001350.00135, between 0.001330.00133 and 0.001480.00148. Probabilities beyond kk standard deviations are 0.31730.3173 for k=1k = 1, 0.04550.0455 for k=2k = 2 and 0.00270.0027 for k=3k = 3, and the quantile leaving 5 %5\,\% split between both tails is 1.961.96. Compare earlier and later laws: an exponential exceeds 33 standard deviations above its mean with probability e−4=0.018e^{-4} = 0.018, about fourteen times normal tail 0.001350.00135. This difference in tail decay rate classifies laws, as studied next.

Three reasons explain why normals appear everywhere, proved in later lessons: they are limits of normalized sums with finite variance (central limit theorem), closed under affine transformations and independent sums, and standard multivariate normals are rotationally invariant (rotational invariance), yielding all geometric results about the multivariate Gaussian.

Heavy tails: Cauchy, Student tt, Pareto and log-normal

Normal, exponential and Laplace tails decay exponentially or faster. Some laws have much heavier tails, so heavy that moments may not exist. Examples include financial losses, file sizes, API response times under load, or follower counts.

Cauchy, tt and Pareto are power laws: their tails decay as a power of xx, S(x)∼x−αS(x) \sim x^{-\alpha} with α=1\alpha = 1 for Cauchy and α=ν\alpha = \nu for tνt_\nu. The log-normal decays faster than any power but slower than any exponential. A formula turns the question of existing moments into a tail integral.

Proof

The formula: E[Xp]=E[∫0Xpxp−1 ⁣dx]=∫0∞pxp−1P(X>x) ⁣dx\E[X^p] = \E\big[\int_0^Xpx^{p-1}\dd x\big] = \int_0^\infty px^{p-1}\Pr(X > x)\dd x, exchanging expectation and integral by Tonelli (nonnegative integrand). (1) S(x)=1S(x) = 1 for x<xmx < x_m and (xm/x)α(x_m/x)^\alpha afterward, so E[Xp]=xmp+∫xm∞pxp−1−αxmα ⁣dx\E[X^p] = x_m^p + \int_{x_m}^\infty px^{p-1-\alpha}x_m^\alpha\dd x, converging if and only if p<αp < \alpha and then equal to xmp+p xmpα−p=αxmpα−px_m^p + \dfrac{p\,x_m^p}{\alpha - p} = \dfrac{\alpha x_m^p}{\alpha - p}. (2) Density of tνt_\nu behaves as c∣x∣−(ν+1)c\abs{x}^{-(\nu+1)} as ∣x∣→∞\abs{x} \to \infty, so ∫∣x∣p∣x∣−ν−1 ⁣dx\int\abs{x}^p\abs{x}^{-\nu-1}\dd x converges at infinity if and only if p<νp < \nu; variance ν/(ν−2)\nu/(\nu - 2) and kurtosis 3+6/(ν−4)3 + 6/(\nu - 4) follow by calculating moments using representation Z/V/νZ/\sqrt{V/\nu}. (3) E∣X∣=2π∫0∞x1+x2 ⁣dx=1π[ln⁡(1+x2)]0∞=∞\E\abs{X} = \dfrac{2}{\pi}\int_0^\infty\dfrac{x}{1 + x^2}\dd x = \dfrac{1}{\pi}\big[\ln(1 + x^2)\big]_0^\infty = \infty. (4) Moments are those of eμ+σZe^{\mu + \sigma Z}, namely E[epσZ]epμ=epμ+p2σ2/2\E[e^{p\sigma Z}]e^{p\mu} = e^{p\mu + p^2\sigma^2/2} (complete the square). But etxe^{tx} grows faster than e(ln⁡x)2/2σ2e^{(\ln x)^2/2\sigma^2} decays as x→∞x \to \infty, because tx−(ln⁡x)2/2σ2→∞tx - (\ln x)^2/2\sigma^2 \to \infty, so the integral defining E[etX]\E[e^{tX}] diverges.

∎

One relationship organizes the picture: Pareto is the exponential of an exponential. If E∼Exp⁡(1)E \sim \operatorname{Exp}(1) then xmeE/α∼Pareto⁡(α,xm)x_me^{E/\alpha} \sim \operatorname{Pareto}(\alpha, x_m) because P(xmeE/α>x)=P(E>αln⁡(x/xm))=(xm/x)α\Pr(x_me^{E/\alpha} > x) = \Pr(E > \alpha\ln(x/x_m)) = (x_m/x)^\alpha, just as log-normal is the exponential of a normal. This is the same mechanism backward: logarithms turn a heavy tail into a light tail, explaining why prices and times are often modeled on a log scale.

InteractiveA zoo of tails on logarithmic scales
log⁡10S(x)\log_{10} S(x) versus xx (log-linear)
024681012110⁻³10⁻⁶10⁻⁹10⁻¹²
log⁡10S(x)\log_{10} S(x) versus log⁡10x\log_{10} x (log-log)
1101001000110⁻³10⁻⁶10⁻⁹10⁻¹²
  • Normal
  • Exponencial
  • Log-normal
  • Pareto
  • t de Student
View
Focused law
5.01
1.00
1.20
1.50
3.0
S(x)S(x) for Pareto0.0891
Ratio S(x+1)/S(x)S(x + 1)/S(x)0.7612
Ratio S(2x)/S(x)S(2x)/S(x)0.3536
Log-linear slope−0.130
Log-log slope−1.500
Pareto: log⁡S=−αlog⁡x\log S = -\alpha\log x is a straight line of slope −α=−1.50-\alpha = −1.50 on log-log axes, and S(2x)/S(x)=2−α=0.354S(2x)/S(x) = 2^{-\alpha} = 0.354 does not depend on xx.
Three views. In Tails, survival S(x)=P(X>x)S(x) = \Pr(X > x) of five laws on log-linear (left) and log–log (right) axes. An exponential is straight on log-linear axes; Pareto is straight on log–log axes. Focus each law and read ratios S(x+1)/S(x)S(x+1)/S(x) and S(2x)/S(x)S(2x)/S(x): which is constant for exponential and which for Pareto? Decrease and increase log-normal σ\sigma: when does it look straight on log–log axes? In Guess the law, a sample of 40004000 points from a hidden law: identify it from shape alone. In Running mean, try Cauchy and Pareto with α=0.8\alpha = 0.8 and compare with normal: what fraction of the sum comes from the largest term?

What breaks when a moment does not exist

Statistics’ great theorems have moment assumptions, which fail with heavy tails in three progressive ways.

  1. No mean (Cauchy, Pareto with α≤1\alpha \le 1): the average of nn observations does not stabilize. Cauchy is worst: the average of nn independent copies has the same law as one observation (proved using the characteristic function, e−∣t∣e^{-\abs{t}}, unchanged by averaging), so more data do not help. For Pareto with α<1\alpha < 1, the mean grows without bound in jumps, as n1/α−1n^{1/\alpha - 1} (and as ln⁡n\ln n in boundary case α=1\alpha = 1).
  2. Mean but no variance (1<α≤21 < \alpha \le 2 for Pareto, 1<ν≤21 < \nu \le 2 for tt): the law of large numbers still holds (sample mean converges to the mean), but error no longer decays as n−1/2n^{-1/2} and Gaussian confidence intervals are invalid.
  3. Variance but no fourth moment (2<α≤42 < \alpha \le 4 for Pareto, 2<ν≤42 < \nu \le 4 for tt): the mean works and sample variance converges, but fluctuates enormously because its own variance involves the fourth moment. The cell below shows t3t_3 with n=104n = 10^4: sample variance swings between 2.52.5 and 4.84.8 (true value 33), while a normal’s stays between 0.960.96 and 1.041.04.

The common feature is the big-jump principle: in a sum of heavy-tailed variables, a single term can contribute a non-negligible fraction of the total. This is measured by the right panel of Running mean and the final column of the cell below: with Pareto 0.80.8 and 10510^5 observations, the largest absolute term exceeds half the sum of absolute values; with a normal, roughly five hundred-thousandths.

Relationship map and library parameterizations

The opening map summarizes relationships, with some more lacking their own figure: sums of independent normals are normal; the square of tνt_\nu is Snedecor F1,νF_{1, \nu}; geometric and exponential are the only memoryless laws; negative binomial is a Poisson mixture with gamma intensity (the mixtures lesson proves this and explains overdispersed counts). For code, every library parameterizes each law differently and errors are silent. The table gives verified conventions: SciPy and NumPy in cells below, PyTorch against those.

Law (lesson convention)scipy.statsnumpy.random.Generatortorch.distributions
Exp⁡(λ)\operatorname{Exp}(\lambda)expon(scale=1/lam)exponential(scale=1/lam)Exponential(rate=lam)
Gam⁡(α,β)\operatorname{Gam}(\alpha, \beta)gamma(a=alpha, scale=1/beta)gamma(shape=alpha, scale=1/beta)Gamma(concentration=alpha, rate=beta)
χk2\chi^2_kchi2(df=k)chisquare(k)Chi2(df=k)
Beta⁡(a,b)\operatorname{Beta}(a, b)beta(a, b)beta(a, b)Beta(a, b)
Dir⁡(α)\operatorname{Dir}(\vb{\alpha})dirichlet(alpha)dirichlet(alpha)Dirichlet(alpha)
Bin⁡(n,p)\Bin(n, p)binom(n, p)binomial(n, p)Binomial(n, probs=p)
Pois⁡(λ)\Pois(\lambda)poisson(mu=lam)poisson(lam=lam)Poisson(rate=lam)
Geometric, trials (from 11)geom(p)geometric(p)unavailable
Geometric, failures (from 00)geom(p, loc=-1)geometric(p) - 1Geometric(probs=p)
NB⁡(r,p)\operatorname{NB}(r, p), failuresnbinom(n=r, p=p)negative_binomial(r, p)NegativeBinomial(total_count=r, probs=1-p)
Hyp⁡(N,K,n)\operatorname{Hyp}(N, K, n)hypergeom(M=N, n=K, N=n)hypergeometric(ngood=K, nbad=N-K, nsample=n)unavailable
Lap⁡(μ,b)\operatorname{Lap}(\mu, b)laplace(loc=mu, scale=b)laplace(mu, b)Laplace(mu, b)
N(μ,σ2)\Normal(\mu, \sigma^2)norm(loc=mu, scale=sigma)normal(mu, sigma)Normal(mu, sigma)
Log-normal (μ,σ2)(\mu, \sigma^2)lognorm(s=sigma, scale=exp(mu))lognormal(mean=mu, sigma=sigma)LogNormal(mu, sigma)
tνt_\nut(df=nu)standard_t(nu)StudentT(df=nu)
Cauchy (μ,s)(\mu, s)cauchy(loc=mu, scale=s)standard_cauchy()Cauchy(mu, s)
Pareto⁡(α,xm)\operatorname{Pareto}(\alpha, x_m)pareto(b=alpha, scale=xm)xm * (1 + pareto(alpha))Pareto(scale=xm, alpha=alpha)

Four cases are especially dangerous. In hypergeom the first argument is population, second the number of successes in the urn, third the number of draws (in that order, unlike the usual formula). scipy.stats.lognorm asks for s=σs = \sigma and scale eμe^\mu, not μ\mu. NumPy’s pareto is the Lomax law, starting at 00 (add 11 and multiply by xmx_m). PyTorch’s negative binomial counts successes before total_count failures, with probs the success probability: to count failures before rr successes, pass 1−p1 - p.

Implementation from scratch

First the generators. All start from uniforms and follow the relevant story: inversion of the distribution function for exponential, geometric, Cauchy and Pareto (the probability integral transform with quantile function), sums for binomial and integer-shape gamma, differences for Laplace, and normalized gammas for beta and Dirichlet. Real-shape gamma uses Marsaglia and Tsang’s method, accepting or rejecting a transformed normal (also obtained here by inversion). They are checked against scipy.stats with Kolmogorov–Smirnov distance, chi-squared tests for discrete laws and QQ plots.

[ ]Generators from uniform variablesBrowser
import numpy as np
from scipy import stats
from scipy.special import ndtri          # inversa de la función de distribución normal
import matplotlib.pyplot as plt

rng = np.random.default_rng(7)

def U(size):
    """Uniformes en el intervalo abierto (0, 1): nunca 0 ni 1, así que log y ndtri son seguros."""
    return rng.integers(1, 2**53, size=size) / 2.0**53

# 1) por inversión: X = F^{-1}(U)
def exponencial(lam, size):
    return -np.log(U(size)) / lam

def geometrica(p, size):
    """Fracasos antes del primer éxito (soporte 0, 1, 2, ...): P(G = k) = p (1 - p)^k."""
    return np.floor(np.log(U(size)) / np.log1p(-p)).astype(int)

def cauchy(size):
    return np.tan(np.pi * (U(size) - 0.5))

def pareto(alpha, size, xm=1.0):
    return xm * U(size) ** (-1 / alpha)

# 2) por sumas y diferencias
def binomial(n, p, size):
    return (U((size, n)) < p).sum(axis=1)

def gamma_entera(k, size, lam=1.0):
    return exponencial(lam, (size, k)).sum(axis=1)

def laplace(b, size):
    return exponencial(1 / b, size) - exponencial(1 / b, size)

# 3) gamma de forma cualquiera (Marsaglia-Tsang con rechazo, vectorizado) y, con ella, beta y Dirichlet
def gamma(a, size):
    if a < 1:                                   # G(a) = G(a + 1) U^{1/a}
        return gamma(a + 1, size) * U(size) ** (1 / a)
    d = a - 1 / 3
    c = 1 / np.sqrt(9 * d)
    out = np.empty(size)
    pend = np.arange(size)
    while pend.size:
        x = ndtri(U(pend.size))                 # normal por inversión
        v = (1 + c * x) ** 3
        u = U(pend.size)
        ok = v > 0
        acc = ok & (np.log(u) < 0.5 * x**2 + d * (1 - v + np.log(np.where(ok, v, 1.0))))
        out[pend[acc]] = d * v[acc]
        pend = pend[~acc]
    return out

def beta(a, b, size):
    x, y = gamma(a, size), gamma(b, size)
    return x / (x + y)

def dirichlet(alpha, size):
    g = np.stack([gamma(a, size) for a in alpha], axis=1)
    return g / g.sum(axis=1, keepdims=True)

# verificación: distancia de Kolmogorov-Smirnov contra scipy.stats (continuas) y chi-cuadrado (discretas)
n = 20_000
casos = [
    ("exponencial(2)",   exponencial(2.0, n),       stats.expon(scale=1 / 2.0)),
    ("Cauchy",           cauchy(n),                 stats.cauchy()),
    ("Pareto(1.5)",      pareto(1.5, n),            stats.pareto(1.5)),
    ("Laplace(b=1.5)",   laplace(1.5, n),           stats.laplace(scale=1.5)),
    ("gamma(k=4)",       gamma_entera(4, n),        stats.gamma(4)),
    ("gamma(a=0.4)",     gamma(0.4, n),             stats.gamma(0.4)),
    ("gamma(a=3.7)",     gamma(3.7, n),             stats.gamma(3.7)),
    ("beta(2, 5)",       beta(2, 5, n),             stats.beta(2, 5)),
]
for nombre, x, ley in casos:
    ks = stats.kstest(x, ley.cdf)
    print(f"{nombre:16s} KS = {ks.statistic:.4f}   p = {ks.pvalue:.2f}")

for nombre, x, ley in [("binomial(20, 0.3)", binomial(20, 0.3, n), stats.binom(20, 0.3)),
                       ("geométrica(0.3)", geometrica(0.3, n), stats.geom(0.3, loc=-1))]:
    obs = np.bincount(x, minlength=40)[:40]
    esp = n * ley.pmf(np.arange(40))
    m = esp > 5                                   # solo celdas con frecuencia esperada > 5
    chi2 = ((obs[m] - esp[m]) ** 2 / esp[m]).sum()
    print(f"{nombre:16s} chi2 = {chi2:6.1f} con {m.sum() - 1} g.l.   p = {stats.chi2.sf(chi2, m.sum() - 1):.2f}")

# gráficos QQ: cuantiles de la muestra frente a los de la ley, entre los percentiles 1 y 99
q = np.linspace(0.01, 0.99, 99)
fig, axs = plt.subplots(2, 4, figsize=(8.6, 4.2))
for ax, (nombre, x, ley) in zip(axs.ravel(), casos):
    ax.plot(ley.ppf(q), np.quantile(x, q), ".", ms=3)
    lim = [ley.ppf(0.01), ley.ppf(0.99)]
    ax.plot(lim, lim, "k--", lw=0.8)
    ax.set_title(nombre, fontsize=8)
    ax.tick_params(labelsize=6)
fig.tight_layout()
plt.show()

Kolmogorov–Smirnov distances lie between 0.0040.004 and 0.0080.008, with pp values that do not reject, and both discrete laws pass chi-squared tests: the generators reproduce laws of scipy.stats. QQ plots follow the diagonal, including Cauchy and Pareto between percentiles 11 and 9999 (beyond that the tail is a lottery, studied next). Note the requirements: one line for inversion laws, a sum for derived laws and a rejection loop for real-shape gamma.

The second cell measures total variation between binomial and Poisson and verifies gamma duality. Pmfs are computed on a log scale using math.lgamma to avoid overflow for large nn.

[ ]Poisson: total variation, Le Cam's bound and gamma dualityBrowser
import math
import numpy as np

def logpmf_binom(n, p, k):
    return math.lgamma(n + 1) - math.lgamma(k + 1) - math.lgamma(n - k + 1) + k * math.log(p) + (n - k) * math.log1p(-p)

def logpmf_pois(lam, k):
    return -lam + k * math.log(lam) - math.lgamma(k + 1)

def tv_binom_pois(n, lam, kmax=200):
    """Distancia de variación total (1/2) sum_k |Bin(n, lam/n)(k) - Pois(lam)(k)|, sumando hasta kmax."""
    p = lam / n
    s = 0.0
    for k in range(kmax + 1):
        b = math.exp(logpmf_binom(n, p, k)) if k <= n else 0.0
        s += abs(b - math.exp(logpmf_pois(lam, k)))
    return s / 2

lam = 3.0
print(f"{'n':>7s} {'TV exacta':>10s} {'cota lam^2/n':>13s} {'cota afinada':>13s} {'n * TV':>8s}")
for n in [10, 30, 100, 1000, 10_000]:
    tv = tv_binom_pois(n, lam)
    print(f"{n:7d} {tv:10.6f} {min(1, lam**2 / n):13.4f} {lam * (1 - math.exp(-lam / n)):13.4f} {n * tv:8.4f}")

# dualidad Poisson-gamma: Pr(Gamma(k, lam) <= t) = Pr(Pois(lam t) >= k)
def pois_sf(mu, k):
    return 1 - sum(math.exp(logpmf_pois(mu, j)) for j in range(k))

def gamma_cdf_entera(k, lam, t):
    """Pr(Gamma(k, lam) <= t): regla de Simpson sobre la densidad lam^k x^(k-1) e^(-lam x)/(k-1)!."""
    xs = np.linspace(0, t, 2001)
    f = lam**k * xs ** (k - 1) * np.exp(-lam * xs) / math.factorial(k - 1)
    h = xs[1] - xs[0]
    return h / 3 * (f[0] + f[-1] + 4 * f[1:-1:2].sum() + 2 * f[2:-1:2].sum())

print("\nPr(la 3.ª alerta llega antes de 1 día), con tasa 3 al día:")
print("  integral de la densidad gamma :", round(gamma_cdf_entera(3, 3.0, 1.0), 6))
print("  Pr(Poisson(3) >= 3)           :", round(pois_sf(3.0, 3), 6))
print("  1 - 8.5 e^{-3}                :", round(1 - 8.5 * math.exp(-3), 6))

Column n⋅TV⁡n\cdot\operatorname{TV} stabilizes at 0.750.75: error decays exactly as 1/n1/n, and bound λ2/n\lambda^2/n remains about twelve times larger. The final three lines agree: the density integral of Gam⁡(3,3)\operatorname{Gam}(3, 3) to 11, the Poisson tail with mean 33 and the closed-form calculation equal 0.5768100.576810.

The third cell runs the heavy-tail experiment with NumPy’s generator: running means, fraction contributed by the largest term and sample-variance instability.

[ ]Heavy tails: running means and sample varianceBrowser
import numpy as np

rng = np.random.default_rng(3)
N = 200_000
ks = np.array([10, 100, 1_000, 10_000, 100_000])

def resumen(nombre, x):
    media = np.cumsum(x) / np.arange(1, len(x) + 1)
    mayor = np.maximum.accumulate(np.abs(x)) / np.cumsum(np.abs(x))      # fracción de la suma que aporta el mayor sumando
    print(f"{nombre:11s}" + "".join(f"{media[k - 1]:10.3f}" for k in ks) + f"{mayor[ks[-1] - 1]:12.3f}")

print(f"{'media en k =':11s}" + "".join(f"{k:10d}" for k in ks) + "   mayor/suma")
resumen("normal", rng.standard_normal(N))
resumen("t (3 g.l.)", rng.standard_t(3, N))
resumen("Cauchy", rng.standard_cauchy(N))
resumen("Pareto 3", 1 + rng.pareto(3.0, N))            # numpy.pareto es Lomax: sumar 1 da la Pareto con x_m = 1
resumen("Pareto 1.5", 1 + rng.pareto(1.5, N))
resumen("Pareto 0.8", 1 + rng.pareto(0.8, N))
print("\nmedias teóricas: Pareto(3) = 1.5, Pareto(1.5) = 3, Pareto(0.8) = infinita; t3 = 0; Cauchy no existe")

# la varianza muestral de una ley con cuarto momento infinito converge, pero con fluctuaciones enormes
v_n = [rng.standard_normal(10_000).var(ddof=1) for _ in range(200)]
v_t = [rng.standard_t(3, 10_000).var(ddof=1) for _ in range(200)]
print("\nvarianza muestral con 10^4 datos, 200 repeticiones (teórica 1 y 3):")
print(f"  normal : media {np.mean(v_n):.3f}   rango [{min(v_n):.3f}, {max(v_n):.3f}]")
print(f"  t_3    : media {np.mean(v_t):.3f}   rango [{min(v_t):.3f}, {max(v_t):.3f}]")

Read rows with the three-breakdown traffic light. Normal and t3t_3 converge to 00 (the latter more slowly). Pareto means with α=3\alpha = 3 and α=1.5\alpha = 1.5 approach 1.51.5 and 33, though α=1.5\alpha = 1.5 does so in jumps. Cauchy’s mean still jumps with 10510^5 observations, while Pareto 0.80.8 converges nowhere: it jumps between 1010 and 430430 without settling, and the largest term exceeds half the total. Exact values change with the seed; behavior does not.

The professional version

In real use there is no need to program the above: numpy.random.Generator and scipy.stats supply it, leaving the table’s conventions as the difficulty. The first cell samples a Dirichlet via normalized NumPy gammas and verifies the theorem’s formulas: means, covariances, marginals, aggregation and the sparse regime.

[ ]Dirichlet from normalized gammas and its momentsBrowser
import numpy as np
from scipy import stats

def dirichlet_gammas(alpha, n, rng):
    """n muestras de Dirichlet(alpha) como gammas independientes normalizadas."""
    g = rng.gamma(shape=np.asarray(alpha, dtype=float), size=(n, len(alpha)))
    return g / g.sum(axis=1, keepdims=True)

rng = np.random.default_rng(11)
alpha = np.array([2.0, 3.0, 5.0])
a0 = alpha.sum()
X = dirichlet_gammas(alpha, 200_000, rng)

media_t = alpha / a0
cov_t = (np.diag(alpha * a0) - np.outer(alpha, alpha)) / (a0**2 * (a0 + 1))
print("media muestral :", np.round(X.mean(axis=0), 4), "  teórica:", media_t)
print("covarianza muestral:\n", np.round(np.cov(X.T), 5))
print("covarianza teórica :\n", np.round(cov_t, 5))
print("las filas suman 1 (error máximo):", np.abs(X.sum(axis=1) - 1).max())

# agregación: X1 + X2 ~ Beta(a1 + a2, a3);  marginal: X1 ~ Beta(a1, a0 - a1)
print("KS de X1 + X2 contra Beta(5, 5):", round(stats.kstest(X[:, 0] + X[:, 1], stats.beta(5, 5).cdf).statistic, 4))
print("KS de X1 contra Beta(2, 8)     :", round(stats.kstest(X[:, 0], stats.beta(2, 8).cdf).statistic, 4))

# independencia entre la suma de las gammas y la proporción (la base del resultado): correlación ~ 0
g = rng.gamma(shape=[2.0, 3.0], size=(100_000, 2))
print("corr(G1 + G2, G1/(G1 + G2)) =", round(np.corrcoef(g.sum(axis=1), g[:, 0] / g.sum(axis=1))[0, 1], 4))

# régimen disperso: con alpha pequeño casi toda la masa se concentra en una componente
for a in (0.05, 0.3, 1.0, 10.0):
    Y = dirichlet_gammas([a] * 5, 50_000, rng)
    print(f"alpha = {a:5.2f} en 5 componentes:  Pr(max > 0.9) = {np.mean(Y.max(axis=1) > 0.9):.3f}   media del mayor = {Y.max(axis=1).mean():.3f}")

Sample covariances agree with −αiαj/(α02(α0+1))-\alpha_i\alpha_j/(\alpha_0^2(\alpha_0 + 1)) to the third digit (with α=(2,3,5)\vb{\alpha} = (2, 3, 5), Cov⁡(X1,X2)=−0.00545\Cov(X_1, X_2) = -0.00545); Kolmogorov–Smirnov distances for marginals and aggregation are of order 10−310^{-3} and correlation between sum and proportion is virtually zero, confirming the theorem’s independence. The final lines show the sparse regime: with five components and α=0.05\alpha = 0.05, 65 %65\,\% of samples have one component above 0.90.9.

Conventions of scipy.stats and NumPy are checked by pointwise comparison asserts against lesson formulas.

[ ]scipy.stats and NumPy conventionsBrowser
import numpy as np
from scipy import stats

x = np.linspace(0.3, 6, 7)
lam, forma, tasa = 0.5, 3.0, 2.0         # tasa de la exponencial; forma y tasa de la gamma

# (densidad en la convención de la lección, densidad de scipy.stats): deben coincidir punto a punto
pares = {
    "exponencial(tasa 0.5)":         (lam * np.exp(-lam * x),                                    stats.expon(scale=1 / lam).pdf(x)),
    "gamma(forma 3, tasa 2)":        (tasa**forma * x**(forma - 1) * np.exp(-tasa * x) / 2.0,    stats.gamma(forma, scale=1 / tasa).pdf(x)),
    "Pareto(alpha 1.5, x_m 2)":      (1.5 * 2.0**1.5 / x**2.5 * (x >= 2.0),                      stats.pareto(1.5, scale=2.0).pdf(x)),
    "log-normal(mu 0.3, sigma 0.8)": (np.exp(-0.5 * ((np.log(x) - 0.3) / 0.8) ** 2) / (x * 0.8 * np.sqrt(2 * np.pi)),
                                      stats.lognorm(s=0.8, scale=np.exp(0.3)).pdf(x)),
    "Laplace(mu 1, b 2)":            (np.exp(-np.abs(x - 1) / 2) / 4,                            stats.laplace(loc=1, scale=2).pdf(x)),
}
for nombre, (a, b) in pares.items():
    print(f"{nombre:31s} diferencia máxima: {np.abs(a - b).max():.1e}")

# las discretas: soporte y significado de cada argumento
p = 0.3
print("\nstats.geom cuenta ENSAYOS (soporte 1, 2, ...):   pmf(1) =", stats.geom(p).pmf(1), "  pmf(0) =", stats.geom(p).pmf(0))
print("para contar FRACASOS, loc=-1 (soporte 0, 1, ...): pmf(0) =", stats.geom(p, loc=-1).pmf(0))
print("stats.nbinom(r, p) cuenta FRACASOS antes del r-ésimo éxito: media =", stats.nbinom(3, 0.4).mean(), " = r (1 - p)/p =", 3 * 0.6 / 0.4)
print("stats.hypergeom(M=N, n=K, N=extracciones): P(4 éxitos) =", round(stats.hypergeom(50, 20, 10).pmf(4), 5), "  (urna de 50, 20 éxitos, 10 extracciones)")
print("stats.poisson(mu=lambda): P(0) con lambda = 3 =", round(stats.poisson(3).pmf(0), 5))

# NumPy: exponential y gamma piden la ESCALA (1/tasa); geometric cuenta ensayos; pareto es Lomax
rng = np.random.default_rng(0)
print("\nmedia de rng.exponential(scale=2):", round(rng.exponential(scale=2, size=200_000).mean(), 3), "  (tasa 0.5, media 2)")
print("media de rng.gamma(3, scale=0.5): ", round(rng.gamma(3, scale=0.5, size=200_000).mean(), 3), "  (forma 3, tasa 2, media 1.5)")
print("mínimo de rng.geometric(0.3):     ", rng.geometric(0.3, size=1000).min(), "  (cuenta ensayos: empieza en 1)")
print("mínimo de rng.pareto(1.5):        ", round(rng.pareto(1.5, size=1000).min(), 4), "  (Lomax: empieza en 0; la Pareto es 1 + Lomax)")

In PyTorch the same laws live in torch.distributions, with rsample for differentiable sampling (reparameterization: N(μ,σ2)\Normal(\mu, \sigma^2) is simulated as μ+σZ\mu + \sigma Z, and gradients pass through μ\mu and σ\sigma). With the table above, these two lines are equivalent to SciPy’s:

import torch
from torch import distributions as D

espera = D.Exponential(rate=torch.tensor(0.5))                     # media 2, tasa 0.5 (scipy: expon(scale=2))
gam = D.Gamma(concentration=torch.tensor(3.0), rate=torch.tensor(2.0))   # media 1.5
prop = D.Dirichlet(torch.tensor([2.0, 3.0, 5.0])).rsample((1000,)) # filas en el símplex, con gradiente

Common mistakes

Exercises

ProofThe binomial converges to Poisson
Prove: Let λ>0\lambda > 0 be fixed and Xn∼Bin⁡(n,λ/n)X_n \sim \Bin(n, \lambda/n). Prove that for each k∈{0,1,2,… }k \in \{0, 1, 2, \dots\}, P(Xn=k)→e−λλk/k!\Pr(X_n = k) \to e^{-\lambda}\lambda^k/k! as n→∞n \to \infty, and explain why pointwise convergence suffices for total variation distance to tend to 00.
0
Factor the binomial mass into three pieces with known limits, compute the only nontrivial limit, and pass from masses to sets.

Step 1 of 4. How is P(Xn=k)\Pr(X_n = k) rewritten to take limits with kk fixed?

ProofThe exponential is the unique continuous memoryless law
Prove: Let T>0T > 0 be a random variable with survival function S(t)=P(T>t)S(t) = \Pr(T > t) satisfying S(s+t)=S(s)S(t)S(s + t) = S(s)S(t) for every s,t≥0s, t \ge 0 and P(T>0)=1\Pr(T > 0) = 1. Prove there is λ>0\lambda > 0 with S(t)=e−λtS(t) = e^{-\lambda t} for every t≥0t \ge 0.
0
Use that SS is nonincreasing and right-continuous, solve on rationals, then extend to reals by monotonicity.

Step 1 of 4. What follows from the equation at 1/n1/n and m/nm/n?

NumericA day without alerts
A service receives an average of 33 critical alerts per day under a Poisson model. What is the probability of no alerts on a given day?
NumericWaiting for the third alert
Alerts in the previous exercise arrive as a Poisson process with rate 33 per day (independent exponential waits). What is the probability the third alert arrives before one day passes?
NumericLe Cam's bound
Approximate the number of failures among n=500n = 500 independent components, each with failure probability p=0.004p = 0.004, by Poisson with mean npnp. What total variation bound does Le Cam's inequality ∑ipi2\sum_ip_i^2 give?
NumericCovariance of a Dirichlet
Let X∼Dir⁡(2,3,5)\vb{X} \sim \operatorname{Dir}(2, 3, 5). What is Cov⁡(X1,X2)\Cov(X_1, X_2)?
NumericVariance without replacement
An urn has N=50N = 50 balls, K=20K = 20 red. Draw n=10n = 10 without replacement. What is the variance of the red count?
QuizDo the mean and variance exist?
A variable XX follows Pareto with index α=1.5\alpha = 1.5. Which statement is true?
QuizRate, scale and support
You want to simulate 10510^5 exponential waits with mean 44 minutes (rate 0.250.25 per minute) and separately the number of failures before the first success of trials with p=0.25p = 0.25. Which calls are correct?

More than one answer may be correct.

QuizCounts with too much variance
The number of errors per project module has mean 33 and variance 66. Which lesson model is most reasonable?
CodeSample a Dirichlet without underflow
Implement sample_dirichlet(alpha, n, rng), returning an array of shape (n, K) with n samples from Dir⁡(α)\operatorname{Dir}(\vb{\alpha}) (each row sums to 11), using normalized gammas. It must work with very small parameters: with αi=0.001\alpha_i = 0.001 NumPy gammas underflow toward 00 (almost all are exactly 00), and normalization gives nan. To avoid this, work with logarithms: for a<1a < 1, log⁡G(a)=log⁡G(a+1)+log⁡(U)/a\log G(a) = \log G(a + 1) + \log(U)/a, with uniform UU, and normalize by subtracting the maximum before exponentiating. Verify means are αi/α0\alpha_i/\alpha_0 and covariances match the theorem.
import numpy as np

def sample_dirichlet(alpha, n, rng):
  """n muestras de Dirichlet(alpha) como gammas independientes normalizadas."""
  alpha = np.asarray(alpha, dtype=float)
  g = rng.gamma(shape=alpha, size=(n, alpha.size))
  # esta versión ingenua falla con alpha pequeño: reescríbela con logaritmos
  return g / g.sum(axis=1, keepdims=True)
Shift+Enter to run

Summary

Key idea
Each distribution in the catalog tells a generative story: summing Bernoulli trials, taking rare-event limits, waiting with exponentials, normalizing gammas, taking exponentials of normals. These stories connect through sums, ratios and limits, while tail decay determines which moments exist and therefore which theorems (law of large numbers, central limit theorem) remain valid.
  • Bernoulli, binomial, geometric, negative binomial and multinomial count outcomes of independent trials; hypergeometric is the no-replacement version, with variance reduced by (N−n)/(N−1)(N - n)/(N - 1) and a binomial limit as N→∞N \to \infty.
  • Bin⁡(n,λ/n)→Pois⁡(λ)\Bin(n, \lambda/n) \to \Pois(\lambda), with total-variation error at most ∑ipi2\sum_ip_i^2 (Le Cam); Poisson has equal mean and variance, and overdispersed counts (variance exceeding mean) are modeled by negative binomial.
  • The exponential is the unique continuous memoryless law (constant hazard); sums of gammas with the same rate are gamma, and ratio X/(X+Y)X/(X + Y) is beta independent of the sum. Thus χk2=Gam⁡(k/2,1/2)\chi^2_k = \operatorname{Gam}(k/2, 1/2), Dirichlet is a normalized gamma vector, and duality P(Tk≤t)=P(Pois⁡(λt)≥k)\Pr(T_k \le t) = \Pr(\Pois(\lambda t) \ge k) links waiting times and counts.
  • Laplace is the difference of two exponentials; its likelihood leads to absolute value: the median estimates location, and lasso and the differential-privacy Laplace mechanism follow.
  • All normals are standard up to location and scale (standardization, X=μ+σZX = \mu + \sigma Z); normal has all moments and tail ≈e−t2/2/t\approx e^{-t^2/2}/t. Rate versus scale, failure-counting versus trial-counting geometrics, and arguments of hypergeom, lognorm and pareto are the most frequent code errors.
  • In heavy tails, moment of order pp exists if and only if ∫xp−1S(x) ⁣dx<∞\int x^{p-1}S(x)\dd x < \infty: Pareto with index α\alpha, p<αp < \alpha; tνt_\nu, p<νp < \nu; Cauchy, only p<1p < 1, hence no mean. Without a mean, the average does not converge; and because log-normal with large σ\sigma mimics a straight log–log line, a line does not prove a power law.