Point estimation — step-by-step proofs with the campus station, the log-likelihood and the second derivative (and the uniform derivative that never hit zero)

In a practice exam in class I applied the maximum likelihood recipe to a uniform(0, θ) without thinking and was left staring at a −n/θ = 0 that has no solution. Log, derivative, set to zero… and nothing. I spent five minutes convinced I had differentiated wrong. I had not: the derivative was right. What failed was the idea that the maximum is always where the derivative is zero. In the uniform it is at an edge, and to see it you have to draw the likelihood before differentiating anything.

In the point estimation theory you saw the two methods (moments and maximum likelihood) and a table with what each gives. Here is where every row of that table comes from: seven proofs with the weather station on the Tafira rooftop (wind, gusts, rainy days, rain and upload delay), each step with the rule that justifies it and checked in R. These are the derivations asked for in the EC2, usually in the first part of an exercise, and everything else depends on them.

Table of Contents

Before you start: the rules we will use

The proofs cite these rules by number (“by rule 2”):

  1. Log of a product. log⁡∏i=1nai=∑i=1nlog⁡ai \log \prod_{i=1}^n a_i = \sum_{i=1}^n \log a_i .
  2. Log of a power and of the exponential. log⁡ab=blog⁡a \log a^b = b\log a and log⁡ec=c \log e^{c} = c .
  3. Product of powers. ∏i=1naxi=a∑xi \prod_{i=1}^n a^{x_i} = a^{\sum x_i} and ∏i=1neci=e∑ci \prod_{i=1}^n e^{c_i} = e^{\sum c_i} .
  4. Derivatives that always turn up. (log⁡θ)′=1/θ (\log\theta)' = 1/\theta , (1/θ)′=−1/θ2 (1/\theta)' = -1/\theta^2 , (1/θ2)′=−2/θ3 (1/\theta^2)' = -2/\theta^3 , (log⁡(1−θ))′=−1/(1−θ) (\log(1-\theta))' = -1/(1-\theta) .
  5. Maximum criterion. If ℓ′(θ^)=0 \ell'(\hat\theta) = 0 and ℓ′′(θ^)<0 \ell''(\hat\theta) < 0 , there is a maximum at θ^ \hat\theta . If moreover ℓ′′<0 \ell'' < 0 on the whole domain, it is the only one.
  6. The log is increasing. Maximising L L and maximising ℓ=log⁡L \ell = \log L give the same θ^ \hat\theta .
  7. Gamma integral. ∫0∞ta−1e−bt dt=Γ(a)/ba \int_0^\infty t^{a-1} e^{-bt}\,dt = \Gamma(a)/b^a for a,b>0 a, b > 0 , with Γ(n)=(n−1)! \Gamma(n) = (n-1)! and Γ(3/2)=π/2 \Gamma(3/2) = \sqrt\pi/2 .
  8. Moments of the known distributions:
DistributionE(X) E(X) Var(X) \text{Var}(X)
Bernoulli(p)p p p(1−p) p(1-p)
Poisson(λ)λ \lambda λ \lambda
exp(λ)1/λ 1/\lambda 1/λ2 1/\lambda^2
gamma(α, β)α/β \alpha/\beta α/β2 \alpha/\beta^2
uniform(a, b)(a+b)/2 (a+b)/2 (b−a)2/12 (b-a)^2/12
normal(μ, σ)μ \mu σ2 \sigma^2

And the notation: Xˉ \bar X is the sample mean, S′2=1n∑(Xi−Xˉ)2 S'^2 = \frac1n\sum(X_i – \bar X)^2 the second central moment (divides by n), θ~ \tilde\theta the moments estimator and θ^ \hat\theta the maximum likelihood one. When a sum keeps coming up, we call it s=∑xi s = \sum x_i or T=∑xi2 T = \sum x_i^2 .

These are the station data used in the “Check it in R” sections:

wind  <- c(7.9, 12.2, 11.5, 11.8, 7.0, 11.7, 4.6, 20.3, 9.4, 10.6,
           12.9, 3.1, 9.2, 27.3, 12.3, 5.5, 14.2, 14.2, 7.4, 21.1,
           14.6, 6.4, 25.4, 8.2, 14.8, 4.1, 7.1, 18.0, 5.6, 16.4,
           13.1, 19.7, 12.1, 11.0, 9.1, 20.8, 21.7, 18.6, 1.2, 4.5)
gusts <- c(2, 6, 4, 4, 9, 4, 4, 1, 3, 3, 1, 4, 1, 1, 3, 2, 2, 3, 4, 3, 1, 4, 6, 2)
rains <- c(0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1)
rain  <- c(5.0, 8.8, 6.8, 6.1, 0.8, 8.7, 3.7, 10.0, 7.4, 1.6,
           7.1, 1.3, 7.5, 6.6, 12.0, 4.0, 7.2, 12.2, 14.8, 6.6)
delay <- c(1.34, 1.18, 2.95, 3.36, 3.51, 1.17, 3.42, 3.74, 1.62, 0.91, 0.05, 1.01, 3.35, 0.52, 1.37)
tnight <- c(12.7, 16.1, 14.4, 16.4, 9.3, 12.5, 10.8, 12.4, 16.2, 13.9, 14.6, 16.6, 15.8, 16.5, 12.5)
s2p <- function(x) mean((x - mean(x))^2)     # S'^2: divides by n

tnight is new: the minimum temperature on 15 nights, in °C, which we will use in proof 5 with a normal.

Proof 1: the mean of the Rayleigh and its moments estimator

What we want to prove

If X X is a Rayleigh with parameter α, with density f(x∣α)=xαe−x2/(2α) f(x \mid \alpha) = \frac{x}{\alpha}e^{-x^2/(2\alpha)} for x≥0 x \ge 0 , then

E(X)=απ2,E(X2)=2α,α~=2Xˉ2π E(X) = \sqrt{\frac{\alpha\pi}{2}}, \qquad E(X^2) = 2\alpha, \qquad \tilde\alpha = \frac{2\bar X^2}{\pi}

Why it matters. The wind is modelled with a Rayleigh, and its mean is not in the table of rule 8: you have to integrate. Without E(X) E(X) as a function of α there is nothing to match to Xˉ \bar X , and the method cannot even start.

Where we start

From the definition of expectation, E(X)=∫0∞xf(x) dx E(X) = \int_0^\infty x f(x)\,dx , and rule 7. The idea is to turn the integral into a gamma-type one with a change of variable.

Step 1: write the integral

E(X)=∫0∞x⋅xαe−x2/(2α) dx=1α∫0∞x2e−x2/(2α) dx E(X) = \int_0^\infty x \cdot \frac{x}{\alpha}e^{-x^2/(2\alpha)}\,dx = \frac{1}{\alpha}\int_0^\infty x^2 e^{-x^2/(2\alpha)}\,dx

The 1/α 1/\alpha comes outside because it does not depend on x.

Step 2: the change t = x²

With t=x2 t = x^2 : x=t x = \sqrt t , dx=dt2t dx = \frac{dt}{2\sqrt t} , and the limits are still 0 and ∞ (x ≥ 0). Substituting:

1α∫0∞t e−t/(2α)dt2t=12α∫0∞t1/2e−t/(2α) dt \frac{1}{\alpha}\int_0^\infty t\, e^{-t/(2\alpha)}\frac{dt}{2\sqrt t} = \frac{1}{2\alpha}\int_0^\infty t^{1/2} e^{-t/(2\alpha)}\,dt

because t/t=t1/2 t/\sqrt t = t^{1/2} .

What gets skipped: from t=x2 t = x^2 you get dt=2x dx dt = 2x\,dx , so dx=dt/(2t) dx = dt/(2\sqrt t) . Why this substitution? Because it turns e−x2/(2α) e^{-x^2/(2\alpha)} into e−t/(2α) e^{-t/(2\alpha)} , the e−bt e^{-bt} shape of rule 7.

Step 3: recognise the gamma

The integral is the one in rule 7 with a−1=1/2 a – 1 = 1/2 , that is a=3/2 a = 3/2 , and b=1/(2α) b = 1/(2\alpha) :

∫0∞t1/2e−t/(2α) dt=Γ(3/2)(1/(2α))3/2=π2(2α)3/2 \int_0^\infty t^{1/2}e^{-t/(2\alpha)}\,dt = \frac{\Gamma(3/2)}{(1/(2\alpha))^{3/2}} = \frac{\sqrt\pi}{2}(2\alpha)^{3/2}

Step 4: simplify

E(X)=12α⋅π2(2α)3/2=π2(2α)1/2=π2α2=π⋅2α4=απ2 E(X) = \frac{1}{2\alpha}\cdot\frac{\sqrt\pi}{2}(2\alpha)^{3/2} = \frac{\sqrt\pi}{2}(2\alpha)^{1/2} = \frac{\sqrt\pi\sqrt{2\alpha}}{2} = \sqrt{\frac{\pi\cdot 2\alpha}{4}} = \sqrt{\frac{\alpha\pi}{2}}

Equality by equality: dividing by (1/(2α))3/2 (1/(2\alpha))^{3/2} is multiplying by (2α)3/2 (2\alpha)^{3/2} ; dividing by 2α 2\alpha subtracts exponents (3/2−1=1/2 3/2 – 1 = 1/2 ); and the 2 at the bottom goes into the root as 4 \sqrt 4 .

For E(X2) E(X^2) , the same path with one more x: E(X2)=1α∫0∞x3e−x2/(2α)dx E(X^2) = \frac1\alpha\int_0^\infty x^3e^{-x^2/(2\alpha)}dx , and with t=x2 t = x^2 it becomes 12α∫0∞t e−t/(2α)dt=12α⋅Γ(2)(1/(2α))2=(2α)22α=2α \frac{1}{2\alpha}\int_0^\infty t\,e^{-t/(2\alpha)}dt = \frac{1}{2\alpha}\cdot\frac{\Gamma(2)}{(1/(2\alpha))^2} = \frac{(2\alpha)^2}{2\alpha} = 2\alpha . We will use it in proof 7.

Step 5: set equal and solve

One parameter, one equation: E(X)=Xˉ E(X) = \bar X .

απ2=Xˉ  ⟹  απ2=Xˉ2  ⟹  α~=2Xˉ2π \sqrt{\frac{\alpha\pi}{2}} = \bar X \;\Longrightarrow\; \frac{\alpha\pi}{2} = \bar X^2 \;\Longrightarrow\; \tilde\alpha = \frac{2\bar X^2}{\pi}

Squaring loses nothing: both sides are positive.

Forgetting the 1/(2t) 1/(2\sqrt t) of the dx dx in the change of variable, or the 1/α 1/\alpha outside. You get a mean that does not grow like α \sqrt\alpha and the estimator is off by a factor. Check the units: α is in km²/h², so E(X) E(X) has to go like α \sqrt\alpha .

Result for the cheat sheet. Rayleigh(α): E(X)=απ/2 E(X) = \sqrt{\alpha\pi/2} , E(X2)=2α E(X^2) = 2\alpha , α~=2Xˉ2/π \tilde\alpha = 2\bar X^2/\pi .

Check it in R

drayleigh <- function(x, alpha) x / alpha * exp(-x^2 / (2 * alpha))
a <- 2 * mean(wind)^2 / pi                                     # moments
c(alpha_mm = a,
  E_integral = integrate(function(x) x * drayleigh(x, a), 0, Inf)$value,
  E_formula = sqrt(a * pi / 2), mean = mean(wind),
  E2_integral = integrate(function(x) x^2 * drayleigh(x, a), 0, Inf)$value)

Output:

   alpha_mm  E_integral   E_formula        mean E2_integral 
   94.21159    12.16500    12.16500    12.16500   188.42319 

The mean integrated numerically with α~=94.21 \tilde\alpha = 94.21 gives exactly xˉ=12.165 \bar x = 12.165 : that is what the method asks for. And E(X2) E(X^2) gives 188.42, which is 2×94.21 2 \times 94.21 .

Check you’ve got it: if every wind reading were doubled, what would the moments estimator of α be?

376.85, four times 94.21. α~=2Xˉ2/π \tilde\alpha = 2\bar X^2/\pi goes with the square of the mean: if every data point doubles, Xˉ2 \bar X^2 is multiplied by 4. It matches the units in the error box: α is in km²/h².

Proof 2: moments with two parameters (and why it is not unique)

What we want to prove

For the gamma(α, β) and the uniform(a, b), with a simple random sample of size n:

α~=Xˉ2S′2,β~=XˉS′2;a~=Xˉ−3 S′,b~=Xˉ+3 S′ \tilde\alpha = \frac{\bar X^2}{S'^2}, \quad \tilde\beta = \frac{\bar X}{S'^2}; \qquad \tilde a = \bar X – \sqrt3\, S', \quad \tilde b = \bar X + \sqrt3\, S'

Why it matters. With two parameters you need a system, and it gives the 3.768 and 0.545 of the rain gamma from the theory. And step 3 shows something awkward: the method can give two answers for the same parameter.

Where we start

With two parameters you need two equations. Matching E(X2) E(X^2) to m2 m_2 is the same as matching the variance to S′2 S'^2 , because Var(X)=E(X2)−E(X)2 \text{Var}(X) = E(X^2) – E(X)^2 and S′2=m2−Xˉ2 S'^2 = m_2 – \bar X^2 . We use the mean and variance from rule 8.

Step 1: the gamma

αβ=Xˉ(1),αβ2=S′2(2) \frac{\alpha}{\beta} = \bar X \quad (1), \qquad \frac{\alpha}{\beta^2} = S'^2 \quad (2)

Divide (1) by (2): α/βα/β2=β=XˉS′2 \frac{\alpha/\beta}{\alpha/\beta^2} = \beta = \frac{\bar X}{S'^2} . Substitute in (1): α=βXˉ=Xˉ2S′2 \alpha = \beta\bar X = \frac{\bar X^2}{S'^2} .

Why divide: α multiplies in both equations, so dividing makes it vanish and leaves β alone. Then you substitute to get α.

Step 2: the uniform(a, b)

a+b2=Xˉ(1),(b−a)212=S′2(2) \frac{a+b}{2} = \bar X \quad (1), \qquad \frac{(b-a)^2}{12} = S'^2 \quad (2)

From (2), (b−a)2=12S′2 (b-a)^2 = 12S'^2 . Since b>a b > a , the positive root: b−a=12 S′=23 S′ b – a = \sqrt{12}\,S' = 2\sqrt3\,S' . From (1), a+b=2Xˉ a + b = 2\bar X . Adding and subtracting the two:

2b=2Xˉ+23S′⇒b~=Xˉ+3S′,2a=2Xˉ−23S′⇒a~=Xˉ−3S′ 2b = 2\bar X + 2\sqrt3 S' \Rightarrow \tilde b = \bar X + \sqrt3 S', \qquad 2a = 2\bar X – 2\sqrt3 S' \Rightarrow \tilde a = \bar X – \sqrt3 S'

The estimated interval is centred on the mean and has 3S′≈1.73 S′ \sqrt3 S' \approx 1.73\,S' on each side.

The root is taken positive because b>a b > a . And adding and subtracting works because (1) gives a+b a + b and (2) gives b−a b – a : adding them, a goes away; subtracting them, b does.

Step 3: why it is not unique

In the Poisson, E(X)=λ E(X) = \lambda and also Var(X)=λ \text{Var}(X) = \lambda . If you match the mean, λ~1=Xˉ \tilde\lambda_1 = \bar X ; if you match the variance, λ~2=S′2 \tilde\lambda_2 = S'^2 . Both are method of moments estimators, and with the gusts they give 3.21 and 3.50. The method does not say which to choose; by convention the lowest-order moments (the mean) are used, and the next topic gives the criterion for comparing.

Using S2 S^2 (the one from var()) instead of S′2 S'^2 . The method matches moments, and the central moment of the sample divides by n. In the exam, write the definition of S′2 S'^2 before using it.

Result for the cheat sheet. Gamma: α~=Xˉ2/S′2 \tilde\alpha = \bar X^2/S'^2 , β~=Xˉ/S′2 \tilde\beta = \bar X/S'^2 . Uniform(a, b): Xˉ∓3S′ \bar X \mp \sqrt3 S' . Poisson: λ~=Xˉ \tilde\lambda = \bar X (or S′2 S'^2 : not unique).

Check it in R

round(c(shape = mean(rain)^2 / s2p(rain), rate = mean(rain) / s2p(rain),
        a = mean(delay) - sqrt(3 * s2p(delay)), b = mean(delay) + sqrt(3 * s2p(delay)),
        lambda1 = mean(gusts), lambda2 = s2p(gusts)), 3)

Output:

  shape    rate       a       b lambda1 lambda2 
  3.768   0.545  -0.149   4.082   3.208   3.498 

The gamma of the rain by moments, 3.768 and 0.545, as in the theory. And a detail of the uniform(a, b) with the delays: b~=4.08 \tilde b = 4.08 is above the largest delay (3.74), fine, but a~=−0.15 \tilde a = -0.15 is negative: a delay cannot be. The method of moments does not know that the data have to fall inside the interval; if it happens in the exam, you take min⁡(a~,min⁡xi) \min(\tilde a, \min x_i) and max⁡(b~,max⁡xi) \max(\tilde b, \max x_i) , or use maximum likelihood.

Check you’ve got it: if in the Poisson the mean and the variance are both λ, why do the gusts give 3.21 and 3.50?

Because the equality holds for the population, not for the sample. Xˉ \bar X and S′2 S'^2 are random variables: with 24 hours, each one strays from λ on its own. If they came out very different (a variance three times the mean), that would be a hint that the Poisson does not fit.

Proof 3: MLE of the Bernoulli and the Poisson

What we want to prove

With a simple random sample of size n and s=∑xi s = \sum x_i :

Bernoulli: p^=sn=Xˉ;Poisson: λ^=sn=Xˉ \text{Bernoulli: } \hat p = \frac{s}{n} = \bar X; \qquad \text{Poisson: } \hat\lambda = \frac{s}{n} = \bar X

and that in both cases it is a maximum.

Why it matters. They are the template for the whole topic: L, logarithm, derivative, second derivative. And the result is reassuring: the MLE of p is the proportion you would guess by eye. With 9 rainy days out of 30, p^=0.30 \hat p = 0.30 .

Where we start

From the masses P(X=x)=px(1−p)1−x P(X = x) = p^x(1-p)^{1-x} for x∈{0,1} x \in \{0, 1\} and P(X=x)=e−λλx/x! P(X = x) = e^{-\lambda}\lambda^x/x! for x=0,1,2,… x = 0, 1, 2, \dots , and the four-step procedure from the theory.

Step 1: the Bernoulli likelihood

L(p)=∏i=1npxi(1−p)1−xi=p∑xi(1−p)∑(1−xi)=ps(1−p)n−s L(p) = \prod_{i=1}^n p^{x_i}(1-p)^{1-x_i} = p^{\sum x_i}(1-p)^{\sum(1-x_i)} = p^s(1-p)^{n-s}

by rule 3, because ∑(1−xi)=n−s \sum(1 – x_i) = n – s .

Why: each xi x_i is 0 or 1, so each factor is p (it rained) or 1−p 1 – p (it did not). There are s factors p and n−s n – s factors 1−p 1 – p .

Step 2: log, derivative and set to zero

By rules 1 and 2, ℓ(p)=slog⁡p+(n−s)log⁡(1−p) \ell(p) = s\log p + (n-s)\log(1-p) . By rule 4:

ℓ′(p)=sp−n−s1−p=s(1−p)−(n−s)pp(1−p)=s−npp(1−p) \ell'(p) = \frac{s}{p} – \frac{n-s}{1-p} = \frac{s(1-p) – (n-s)p}{p(1-p)} = \frac{s – np}{p(1-p)}

It is zero when the numerator is 0: s−np=0⇒p^=s/n s – np = 0 \Rightarrow \hat p = s/n .

What gets skipped: s(1−p)−(n−s)p=s−sp−np+sp s(1-p) – (n-s)p = s – sp – np + sp , and the two sp sp cancel. The denominator p(1−p) p(1-p) is positive on (0, 1): only the numerator counts.

Step 3: the second derivative

ℓ′′(p)=−sp2−n−s(1−p)2 \ell''(p) = -\frac{s}{p^2} – \frac{n-s}{(1-p)^2}

Both terms are negative (or zero) for any p in (0, 1), so ℓ′′<0 \ell'' < 0 on the whole interval: by rule 5, p^ \hat p is the only maximum.

Step 4: the Poisson

L(λ)=∏i=1ne−λλxixi!=e−nλλs∏xi! L(\lambda) = \prod_{i=1}^n \frac{e^{-\lambda}\lambda^{x_i}}{x_i!} = \frac{e^{-n\lambda}\lambda^{s}}{\prod x_i!}
ℓ(λ)=−nλ+slog⁡λ−∑i=1nlog⁡(xi!) \ell(\lambda) = -n\lambda + s\log\lambda – \sum_{i=1}^n \log(x_i!)

The last term does not depend on λ: it disappears when you differentiate. That is why in the exam you can write “+ constant”.

ℓ′(λ)=−n+sλ=0  ⟹  λ^=sn=Xˉ,ℓ′′(λ)=−sλ2<0 \ell'(\lambda) = -n + \frac{s}{\lambda} = 0 \;\Longrightarrow\; \hat\lambda = \frac{s}{n} = \bar X, \qquad \ell''(\lambda) = -\frac{s}{\lambda^2} < 0
The log-likelihood of the gustsCurve of the log-likelihood of the 24 hours of gusts for lambda between 1 and 7. It is a hill with its top at 3.21, where a horizontal coral tangent shows the derivative is zero. Two green tangents: on the left, at 1.8, with positive slope; on the right, at 5.6, with negative slope.−70−60−50−401234567λℓ(λ)λ̂ = x̄ = 3.21: ℓ' = 0ℓ' > 0: going upℓ' < 0: going down
ℓ'' < 0: the slope always decreases, so the point where it is 0 is the top.

In the picture, the gusts log-likelihood: a hill with its top at 3.21, where the tangent is horizontal (ℓ′=0 \ell' = 0 ). On the left the slope is positive and on the right negative: that is what ℓ′′<0 \ell'' < 0 says, that the slope always goes down.

The case s=0 s = 0 (no rainy days). Then L(p)=(1−p)n L(p) = (1-p)^n , which is largest at p=0 p = 0 , and the derivative is not zero anywhere in (0, 1). The MLE is still s/n=0 s/n = 0 , but you see it by drawing, not by differentiating. Same with s=n s = n .

Result for the cheat sheet. Bernoulli: p^=Xˉ \hat p = \bar X . Poisson: λ^=Xˉ \hat\lambda = \bar X . They coincide with the moments ones.

Check it in R

lb <- function(p) sum(dbinom(rains, 1, p, log = TRUE))     # Bernoulli = binom(1, p)
lp <- function(l) sum(dpois(gusts, l, log = TRUE))
c(p_formula = mean(rains), p_optimize = optimize(lb, c(0.001, 0.999), maximum = TRUE)$maximum,
  l_formula = mean(gusts), l_optimize = optimize(lp, c(0.1, 20), maximum = TRUE)$maximum)

Output:

 p_formula p_optimize  l_formula l_optimize 
 0.3000000  0.2999945  3.2083333  3.2083498 

optimize finds the same maxima as the formula, with a few decimals of difference that are the algorithm’s tolerance (by default, about four figures).

Check you’ve got it: in the Bernoulli, what would happen if you differentiated L(p) directly, without taking logarithms?

You would get the same thing with much more work. By the product rule, L′(p)=s ps−1(1−p)n−s−(n−s) ps(1−p)n−s−1 L'(p) = s\,p^{s-1}(1-p)^{n-s} – (n-s)\,p^s(1-p)^{n-s-1} ; taking out the common factor ps−1(1−p)n−s−1 p^{s-1}(1-p)^{n-s-1} leaves s−np s – np , which is zero at p=s/n p = s/n , the same point (rule 6). But the second derivative would be a mess. The logarithm turns the product into a sum, which you differentiate term by term.

Proof 4: MLE of the exponential and the Rayleigh

What we want to prove

exp(λ):λ^=1Xˉ;Rayleigh(α):α^=12n∑i=1nXi2 \text{exp}(\lambda): \hat\lambda = \frac{1}{\bar X}; \qquad \text{Rayleigh}(\alpha): \hat\alpha = \frac{1}{2n}\sum_{i=1}^n X_i^2

Why it matters. Here, for the first time, the two methods disagree: with the wind, moments gave 94.21 and maximum likelihood gives 93.14. And it is the first case where ℓ′′ \ell'' depends on the parameter. The exponential goes first as a warm-up.

Step 1: the exponential

L(λ)=∏i=1nλe−λxi=λne−λs,ℓ(λ)=nlog⁡λ−λs L(\lambda) = \prod_{i=1}^n \lambda e^{-\lambda x_i} = \lambda^n e^{-\lambda s}, \qquad \ell(\lambda) = n\log\lambda – \lambda s

Why: n factors λ give λn \lambda^n , and the n exponentials merge into e−λs e^{-\lambda s} (rule 3). Taking logarithms, rule 2 brings the n down and removes the e.

ℓ′(λ)=nλ−s=0  ⟹  λ^=ns=1Xˉ,ℓ′′(λ)=−nλ2<0 \ell'(\lambda) = \frac{n}{\lambda} – s = 0 \;\Longrightarrow\; \hat\lambda = \frac{n}{s} = \frac{1}{\bar X}, \qquad \ell''(\lambda) = -\frac{n}{\lambda^2} < 0

Step 2: the Rayleigh likelihood

With T=∑xi2 T = \sum x_i^2 :

L(α)=∏i=1nxiαe−xi2/(2α)=∏xiαn e−T/(2α) L(\alpha) = \prod_{i=1}^n \frac{x_i}{\alpha}e^{-x_i^2/(2\alpha)} = \frac{\prod x_i}{\alpha^n}\,e^{-T/(2\alpha)}

by rule 3: the n denominators α come together as αn \alpha^n and the n exponentials, as one with the sum of the exponents.

Step 3: log and derivative

ℓ(α)=∑i=1nlog⁡xi−nlog⁡α−T2α \ell(\alpha) = \sum_{i=1}^n\log x_i – n\log\alpha – \frac{T}{2\alpha}

The first term does not depend on α. By rule 4, (T/(2α))′=−T/(2α2) (T/(2\alpha))' = -T/(2\alpha^2) , so with the minus sign it turns positive:

ℓ′(α)=−nα+T2α2=−2nα+T2α2=0  ⟹  α^=T2n \ell'(\alpha) = -\frac{n}{\alpha} + \frac{T}{2\alpha^2} = \frac{-2n\alpha + T}{2\alpha^2} = 0 \;\Longrightarrow\; \hat\alpha = \frac{T}{2n}

To combine the fractions, −n/α=−2nα/(2α2) -n/\alpha = -2n\alpha/(2\alpha^2) . Since 2α2>0 2\alpha^2 > 0 , the derivative is 0 only when the numerator T−2nα T – 2n\alpha is 0.

Step 4: the second derivative

ℓ′′(α)=nα2−Tα3 \ell''(\alpha) = \frac{n}{\alpha^2} – \frac{T}{\alpha^3}

Where it comes from: (−n/α)′=n/α2 (-n/\alpha)' = n/\alpha^2 and, by rule 4, (T/(2α2))′=−T/α3 (T/(2\alpha^2))' = -T/\alpha^3 .

Here the sign is not negative on the whole domain: it depends on α. You evaluate it at α^ \hat\alpha , using T=2nα^ T = 2n\hat\alpha :

ℓ′′(α^)=nα^2−2nα^α^3=nα^2−2nα^2=−nα^2<0 \ell''(\hat\alpha) = \frac{n}{\hat\alpha^2} – \frac{2n\hat\alpha}{\hat\alpha^3} = \frac{n}{\hat\alpha^2} – \frac{2n}{\hat\alpha^2} = -\frac{n}{\hat\alpha^2} < 0

Maximum. And since ℓ′>0 \ell' > 0 for α<α^ \alpha < \hat\alpha and ℓ′<0 \ell' < 0 for α>α^ \alpha > \hat\alpha (look at the numerator T−2nα T – 2n\alpha ), it is the only one.

Writing T=(∑xi)2 T = (\sum x_i)^2 instead of ∑xi2 \sum x_i^2 . They are not the same: with the wind, ∑xi2=7451.54 \sum x_i^2 = 7451.54 and (∑xi)2=236,779.56 (\sum x_i)^2 = 236{,}779.56 . In R, sum(wind^2) against sum(wind)^2: the brackets change everything.

Result for the cheat sheet. exp(λ): λ^=1/Xˉ \hat\lambda = 1/\bar X . Rayleigh(α): α^=∑Xi2/(2n) \hat\alpha = \sum X_i^2/(2n) .

Check it in R

lr <- function(a) sum(log(wind / a) - wind^2 / (2 * a))   # l(alpha) with all its terms
c(formula = sum(wind^2) / (2 * length(wind)),
  optimize = optimize(lr, c(10, 500), maximum = TRUE)$maximum,
  second = -length(wind) / (sum(wind^2) / 80)^2)

Output:

     formula     optimize       second 
93.144250000 93.144245019 -0.004610499 

The function lr includes ∑log⁡xi \sum\log x_i (it is inside log(wind / a)), but since it does not depend on α it does not move the maximum: optimize gives 93.144 all the same. The second derivative at the maximum, −40/93.142=−0.0046 -40/93.14^2 = -0.0046 , is negative and small: the hill is wide, another way of saying that α is not very precise with 40 data points.

Check you’ve got it: in step 3, why does the term with the logarithms of the data vanish when differentiating?

Because you differentiate with respect to α. Once the sample is taken, ∑log⁡xi \sum\log x_i is a fixed number, like a 7: its derivative with respect to α is 0. That is why optimize gives 93.144 even though lr includes it. It changes the height of the hill, not where its top is.

Proof 5: MLE of the normal with μ and σ unknown

What we want to prove

If X1,…,Xn X_1, \dots, X_n is a simple random sample from an N(μ,σ) N(\mu, \sigma) with both parameters unknown:

μ^=Xˉ,σ^2=1n∑i=1n(Xi−Xˉ)2=S′2 \hat\mu = \bar X, \qquad \hat\sigma^2 = \frac1n\sum_{i=1}^n(X_i – \bar X)^2 = S'^2

And two cases with one parameter known: if σ is known, μ^=Xˉ \hat\mu = \bar X ; if μ = μ₀ is known, σ^2=1n∑(Xi−μ0)2 \hat\sigma^2 = \frac1n\sum(X_i – \mu_0)^2 .

Why it matters. It is the first one with two parameters at once, and the one that comes up most. It has a catch: σ^2 \hat\sigma^2 divides by n, not by n−1 n – 1 , so the MLE of σ is not sd().

Where we start

From the density f(x)=1σ2πe−(x−μ)2/(2σ2) f(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{-(x-\mu)^2/(2\sigma^2)} . With two parameters, you differentiate with respect to each, set to 0 and solve the system.

Step 1: the log-likelihood

L(μ,σ)=∏i=1n1σ2πe−(xi−μ)22σ2=σ−n(2π)−n/2exp⁡{−∑(xi−μ)22σ2} L(\mu, \sigma) = \prod_{i=1}^n \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x_i-\mu)^2}{2\sigma^2}} = \sigma^{-n}(2\pi)^{-n/2}\exp\Big\{-\frac{\sum(x_i-\mu)^2}{2\sigma^2}\Big\}
ℓ(μ,σ)=−nlog⁡σ−n2log⁡(2π)−12σ2∑i=1n(xi−μ)2 \ell(\mu, \sigma) = -n\log\sigma – \frac n2\log(2\pi) – \frac{1}{2\sigma^2}\sum_{i=1}^n(x_i-\mu)^2

From L to ℓ: σ−n \sigma^{-n} gives −nlog⁡σ -n\log\sigma , (2π)−n/2 (2\pi)^{-n/2} gives −n2log⁡(2π) -\frac n2\log(2\pi) (rule 2), and the logarithm leaves the exponent of the e as it is.

Step 2: the equation for μ

∂ℓ∂μ=−12σ2∑2(xi−μ)(−1)=1σ2∑i=1n(xi−μ)=0 \frac{\partial\ell}{\partial\mu} = -\frac{1}{2\sigma^2}\sum 2(x_i-\mu)(-1) = \frac{1}{\sigma^2}\sum_{i=1}^n(x_i – \mu) = 0

What gets skipped: the derivative of (xi−μ)2 (x_i – \mu)^2 is 2(xi−μ) 2(x_i – \mu) times −1 -1 , the derivative of the inside. The 2 cancels with the one in the denominator and the two minus signs cancel out.

Since σ2>0 \sigma^2 > 0 , the sum has to be 0: ∑xi−nμ=0⇒μ^=xˉ \sum x_i – n\mu = 0 \Rightarrow \hat\mu = \bar x . Notice it does not depend on σ: whatever σ is, the best μ is the mean.

Step 3: the equation for σ

∂ℓ∂σ=−nσ+1σ3∑i=1n(xi−μ)2=0 \frac{\partial\ell}{\partial\sigma} = -\frac{n}{\sigma} + \frac{1}{\sigma^3}\sum_{i=1}^n(x_i – \mu)^2 = 0

(the derivative of −12σ−2 -\frac{1}{2}\sigma^{-2} is σ−3 \sigma^{-3} ). Multiplying by σ3 \sigma^3 : −nσ2+∑(xi−μ)2=0 -n\sigma^2 + \sum(x_i – \mu)^2 = 0 .

The arithmetic: −12⋅(−2) σ−3=σ−3 -\frac12\cdot(-2)\,\sigma^{-3} = \sigma^{-3} . You can multiply by σ3 \sigma^3 because σ>0 \sigma > 0 : it neither adds nor removes solutions.

Step 4: solve the system

Substitute μ^=xˉ \hat\mu = \bar x in the second equation:

σ^2=1n∑i=1n(xi−xˉ)2=S′2,σ^=S′2 \hat\sigma^2 = \frac1n\sum_{i=1}^n(x_i – \bar x)^2 = S'^2, \qquad \hat\sigma = \sqrt{S'^2}

If μ = μ₀ is known, in step 3 there is nothing to substitute: σ^2=1n∑(xi−μ0)2 \hat\sigma^2 = \frac1n\sum(x_i – \mu_0)^2 .

Step 5: is it a maximum?

With two variables you argue in two stages. For each fixed σ, ℓ \ell is a downward parabola in μ (∂2ℓ/∂μ2=−n/σ2<0 \partial^2\ell/\partial\mu^2 = -n/\sigma^2 < 0 ), with its maximum at xˉ \bar x . Then at μ=xˉ \mu = \bar x , as a function of σ:

∂2ℓ∂σ2=nσ2−3σ4∑(xi−xˉ)2  →  σ=σ^    nσ^2−3nσ^2σ^4=−2nσ^2<0 \frac{\partial^2\ell}{\partial\sigma^2} = \frac{n}{\sigma^2} – \frac{3}{\sigma^4}\sum(x_i-\bar x)^2 \;\xrightarrow{\;\sigma = \hat\sigma\;}\; \frac{n}{\hat\sigma^2} – \frac{3n\hat\sigma^2}{\hat\sigma^4} = -\frac{2n}{\hat\sigma^2} < 0
Two slices of the normal log-likelihoodTwo panels with the log-likelihood of the 15 nights. On the left, as a function of mu with sigma fixed at 2.20: a parabola with its top at 14.05. On the right, as a function of sigma with mu at 14.05: a curve that rises very quickly from sigma equal to 1, peaks at 2.20 and falls slowly.−45−40−3511131517ℓ(μ) with σ = σ̂μ̂ = 14.05μ (°C)−45−40−3512345ℓ(σ) with μ = x̄σ̂ = 2.20σ (°C)
Each slice peaks at the MLE: x̄ for μ and the root of S'² for σ.

In the picture, the two slices of the log-likelihood with the 15 nights: on the left, ℓ(μ) \ell(\mu) with σ fixed at σ^ \hat\sigma , peaking at xˉ=14.05 \bar x = 14.05 °C; on the right, ℓ(σ) \ell(\sigma) with μ fixed at xˉ \bar x , peaking at σ^=2.20 \hat\sigma = 2.20 °C, steeper on the left (a small σ makes the far data impossible) than on the right.

Step 6: and the gamma, why not?

With the gamma(α, β) of the rain you do the same, but the system cannot be solved:

∂ℓ∂β=nαβ−s=0⇒β=αxˉ,∂ℓ∂α=nlog⁡β−nΓ′(α)Γ(α)+∑log⁡xi=0 \frac{\partial\ell}{\partial\beta} = \frac{n\alpha}{\beta} – s = 0 \Rightarrow \beta = \frac{\alpha}{\bar x}, \qquad \frac{\partial\ell}{\partial\alpha} = n\log\beta – n\frac{\Gamma'(\alpha)}{\Gamma(\alpha)} + \sum\log x_i = 0

Substituting the first into the second leaves nlog⁡(α/xˉ)−n ψ(α)+∑log⁡xi=0 n\log(\alpha/\bar x) – n\,\psi(\alpha) + \sum\log x_i = 0 , with ψ=Γ′/Γ \psi = \Gamma'/\Gamma (the digamma). There is no way to solve for α by hand: it is solved with optim or fitdist. What can be proved is that α^/β^=xˉ \hat\alpha/\hat\beta = \bar x : the gamma fitted by maximum likelihood has the same mean as the data.

Differentiating with respect to σ2 \sigma^2 in one place and to σ in another. Pick one variable and stick to it: if you differentiate with respect to v=σ2 v = \sigma^2 , ℓ=−n2log⁡v−12v∑(xi−μ)2+c \ell = -\frac n2\log v – \frac{1}{2v}\sum(x_i-\mu)^2 + c and you get v^=S′2 \hat v = S'^2 just the same (invariance guarantees σ^=v^ \hat\sigma = \sqrt{\hat v} ).

Result for the cheat sheet. Normal: μ^=Xˉ \hat\mu = \bar X , σ^2=S′2 \hat\sigma^2 = S'^2 (divides by n); with μ₀ known, 1n∑(Xi−μ0)2 \frac1n\sum(X_i-\mu_0)^2 . Gamma: no closed form, optim/fitdist, with α^/β^=Xˉ \hat\alpha/\hat\beta = \bar X .

Check it in R

ln <- function(par, x) sum(dnorm(x, mean = par[1], sd = par[2], log = TRUE))
o <- optim(c(10, 1), ln, x = tnight, method = "L-BFGS-B",
           lower = c(-Inf, 0.01), control = list(fnscale = -1))
round(c(mu_optim = o$par[1], sigma_optim = o$par[2],
        mu_formula = mean(tnight), sigma_formula = sqrt(s2p(tnight)),
        sd_from_R = sd(tnight)), 3)

Output:

     mu_optim   sigma_optim    mu_formula sigma_formula     sd_from_R 
       14.047         2.204        14.047         2.204         2.281 

optim, starting far away (μ = 10, σ = 1), reaches the formulas: μ^=14.047 \hat\mu = 14.047 and σ^=2.204 \hat\sigma = 2.204 . Look at the last column: sd() gives 2.281, because it divides by n − 1. The MLE of σ is not sd().

Check you’ve got it: if you knew the mean of the nights is 15 °C, would the MLE of σ be larger or smaller than 2.20?

Larger: 2.40 °C. With μ₀ known, σ^2=1n∑(xi−15)2 \hat\sigma^2 = \frac1n\sum(x_i – 15)^2 , and it always holds that 1n∑(xi−c)2=S′2+(xˉ−c)2 \frac1n\sum(x_i – c)^2 = S'^2 + (\bar x – c)^2 : 4.856+(14.047−15)2=4.856+0.909=5.76 4.856 + (14.047 – 15)^2 = 4.856 + 0.909 = 5.76 . Measuring from a center that is not the mean always gives more spread.

Proof 6: MLE of the uniform(0, θ), without differentiating

What we want to prove

If X1,…,Xn X_1, \dots, X_n is a simple random sample from a uniform(0, θ), then

θ^=max⁡(X1,…,Xn)=X(n) \hat\theta = \max(X_1, \dots, X_n) = X_{(n)}

Why it matters. It is the practice-exam case: the recipe fails with no arithmetic mistake at all. It happens whenever the support depends on the parameter, and in the exam it is set to see whether you think before differentiating.

Where we start

From the density f(x∣θ)=1/θ f(x \mid \theta) = 1/\theta if 0≤x≤θ 0 \le x \le \theta and 0 otherwise. The support depends on θ: that is the clue that the derivative will not help.

Step 1: the likelihood with its condition

Each factor is 1/θ 1/\theta if the data point falls in [0,θ] [0, \theta] and 0 if not. The product is 1/θn 1/\theta^n only if all fall inside, that is, if θ≥xi \theta \ge x_i for every i, which is the same as θ≥max⁡xi \theta \ge \max x_i :

L(θ)=1θn I{θ≥max⁡xi}(θ)=0if θ<max⁡xiθ−nif θ≥max⁡xi L(\theta) = \frac{1}{\theta^n}\, I_{\{\theta \ge \max x_i\}}(\theta) = \begin{array}{ll} 0 & \text{if } \theta < \max x_i \\ \theta^{-n} & \text{if } \theta \ge \max x_i \end{array}

I is the indicator function: 1 if the condition holds, 0 if not.

Why: if the largest data point fits in [0,θ] [0, \theta] , so do the rest. If it does not fit, its factor is 0 and wipes out the product.

Step 2: why differentiating does not work

Where L is not 0, ℓ(θ)=−nlog⁡θ \ell(\theta) = -n\log\theta and ℓ′(θ)=−n/θ \ell'(\theta) = -n/\theta , which is always negative: the likelihood keeps going down. The equation −n/θ=0 -n/\theta = 0 has no solution (the one that froze me in the practice exam). The derivative is not zero because the maximum is not a “smooth” point: it is a corner.

Step 3: reason with the picture

Where θ can be in the uniform(0, θ)Line from 0 to 5 seconds with the 15 delays as points. The zone left of 3.74, in red, is impossible for theta because some delay would be left out. The zone to the right, in green, is allowed, and within it the likelihood grows to the left. The estimator is 3.74, the data maximum.allowed θimpossible θ: some delay would be left out012345θ̂ = max = 3.74seconds of delayL = 1/θ¹⁵ grows to the leftthe smallest allowed θ wins
θ must cover all the data and the smaller the more likely: the sample maximum.

In the picture, the 15 delays on a line. θ is the end of the interval; it has to be to the right of all the points (allowed zone, in green). Inside the allowed zone, the smaller θ, the larger 1/θ15 1/\theta^{15} . The smallest allowed θ is the last point: θ^=max⁡xi=3.74 \hat\theta = \max x_i = 3.74 s.

Saying the maximum of 1/θn 1/\theta^n is “at θ = 0” because the function shoots up there. θ = 0 is not allowed: it would make every data point impossible. The likelihood’s maximum is at the sample maximum.

Result for the cheat sheet. Uniform(0, θ): θ^=max⁡Xi \hat\theta = \max X_i (moments: 2Xˉ 2\bar X ). Whenever the support depends on the parameter, the MLE is an extreme of the sample.

Check it in R

Lu <- function(th) ifelse(th >= max(delay), th^(-15), 0)   # the whole likelihood
grid <- seq(3, 5, by = 0.001)
c(grid_maximum = grid[which.max(Lu(grid))], data_max = max(delay),
  moments = 2 * mean(delay), L_at_3.739 = Lu(3.739))

Output:

grid_maximum     data_max      moments   L_at_3.739 
    3.740000     3.740000     3.933333     0.000000 

Searching on a grid of θ every thousandth, the maximum of L falls at 3.74, the data maximum. Just to the left (3.739) the likelihood is already 0. And by moments, 3.93: to the right of the maximum this time, but not always (in the practice, in a good 30 % of samples it lands to the left).

Check you’ve got it: if tomorrow a delay of 3.90 s comes in, how does the MLE of θ change? And if one of 2.00 s comes in?

With 3.90, θ^ \hat\theta becomes 3.90: θ has to cover the new maximum. With 2.00 it stays at 3.74, because that point already falls inside. The MLE only listens to the largest data point; the moments one, 2Xˉ 2\bar X , moves with both: from 3.93 to 4.18 and to 3.94.

Proof 7: invariance and the distribution of the Rayleigh MLE

What we want to prove

Two things. First, the invariance principle: if θ^ \hat\theta is the MLE of θ, the MLE of τ(θ) \tau(\theta) is τ(θ^) \tau(\hat\theta) . Second, what the random variable α^=12n∑Xi2 \hat\alpha = \frac{1}{2n}\sum X_i^2 of the Rayleigh looks like:

α^∼gamma(n,nα),E(α^)=α,Var(α^)=α2n \hat\alpha \sim \text{gamma}\Big(n, \frac{n}{\alpha}\Big), \qquad E(\hat\alpha) = \alpha, \qquad \text{Var}(\hat\alpha) = \frac{\alpha^2}{n}

Why it matters. With invariance you get the MLE of any function of α without differentiating again. And the second part is a reminder that an estimator changes with every sample: its distribution gives its mean and variance, which the next topic uses to decide whether it is good.

Step 1: invariance, when τ is one-to-one

If τ is one-to-one (for example η=απ/2 \eta = \sqrt{\alpha\pi/2} , the mean wind speed), rewrite the likelihood in terms of η: L∗(η)=L(τ−1(η)) L^*(\eta) = L(\tau^{-1}(\eta)) . The values L∗ L^* takes are exactly those of L, just with another label on the axis. Its maximum is reached at the η whose “original label” is θ^ \hat\theta , that is, at η^=τ(θ^) \hat\eta = \tau(\hat\theta) . The general theorem (τ not one-to-one) is proved the same way by defining the induced likelihood; in ME1 it is used without proof.

With the wind: the MLE of the mean wind speed is α^π/2=93.14⋅π/2=12.10 \sqrt{\hat\alpha\pi/2} = \sqrt{93.14\cdot\pi/2} = 12.10 km/h, and that of P(X>20)=e−400/(2α) P(X > 20) = e^{-400/(2\alpha)} is e−400/186.29=0.117 e^{-400/186.29} = 0.117 .

Step 2: the distribution of Y = X²

If X is Rayleigh(α), Y=X2 Y = X^2 has distribution function, for y>0 y > 0 ,

FY(y)=P(X2≤y)=P(X≤y)=∫0yxαe−x2/(2α)dx=[−e−x2/(2α)]0y=1−e−y/(2α) F_Y(y) = P(X^2 \le y) = P(X \le \sqrt y) = \int_0^{\sqrt y}\frac{x}{\alpha}e^{-x^2/(2\alpha)}dx = \Big[-e^{-x^2/(2\alpha)}\Big]_0^{\sqrt y} = 1 – e^{-y/(2\alpha)}

(the derivative of −e−x2/(2α) -e^{-x^2/(2\alpha)} is exactly xαe−x2/(2α) \frac x\alpha e^{-x^2/(2\alpha)} ). It is the distribution function of an exponential with rate 1/(2α) 1/(2\alpha) : Y∼exp(1/(2α)) Y \sim \text{exp}(1/(2\alpha)) , with mgf MY(t)=1/(2α)1/(2α)−t=11−2αt M_Y(t) = \frac{1/(2\alpha)}{1/(2\alpha) – t} = \frac{1}{1 – 2\alpha t} for t<1/(2α) t < 1/(2\alpha) .

Two whys. X2≤y X^2 \le y is the same as X≤y X \le \sqrt y because X is not negative. And the mgf of an exp(λ) \text{exp}(\lambda) is λ/(λ−t) \lambda/(\lambda – t) : with λ=1/(2α) \lambda = 1/(2\alpha) , multiplying top and bottom by 2α 2\alpha , you get 1/(1−2αt) 1/(1 – 2\alpha t) .

Step 3: the sum

The Yi=Xi2 Y_i = X_i^2 are independent (the Xi X_i are), so the mgf of T=∑Yi T = \sum Y_i is the product:

MT(t)=∏i=1n11−2αt=(1−2αt)−n=(1/(2α)1/(2α)−t)n M_T(t) = \prod_{i=1}^n \frac{1}{1-2\alpha t} = (1 – 2\alpha t)^{-n} = \Big(\frac{1/(2\alpha)}{1/(2\alpha) – t}\Big)^n

which is the mgf of a gamma(n,1/(2α)) \text{gamma}(n, 1/(2\alpha)) .

Why: the mgf of a sum of independent variables is the product of their mgfs; n equal factors give a power n, and (b/(b−t))n \big(b/(b – t)\big)^n is the mgf of a gamma(n, b).

Step 4: divide by 2n

α^=T/(2n) \hat\alpha = T/(2n) . For a constant c, McT(t)=MT(ct) M_{cT}(t) = M_T(ct) :

Mα^(t)=MT(t2n)=(1−2αt2n)−n=(1−αtn)−n=(n/αn/α−t)n M_{\hat\alpha}(t) = M_T\Big(\frac{t}{2n}\Big) = \Big(1 – \frac{2\alpha t}{2n}\Big)^{-n} = \Big(1 – \frac{\alpha t}{n}\Big)^{-n} = \Big(\frac{n/\alpha}{n/\alpha – t}\Big)^n

the mgf of a gamma(n,n/α) \text{gamma}(n, n/\alpha) . By rule 8, its mean is n/(n/α)=α n/(n/\alpha) = \alpha and its variance n/(n/α)2=α2/n n/(n/\alpha)^2 = \alpha^2/n .

Why McT(t)=MT(ct) M_{cT}(t) = M_T(ct) : E(et cT)=E(e(ct)T) E(e^{t\,cT}) = E(e^{(ct)T}) , which is MT M_T evaluated at ct.

From the Rayleigh to the distribution of its MLEChain of four boxes. X is Rayleigh of alpha. Squared, Y equal to X squared is an exponential with rate 1 over 2 alpha, with mgf 1 over 1 minus 2 alpha t. The sum T of n independent ones is a gamma of n and 1 over 2 alpha, with mgf 1 minus 2 alpha t to the minus n. Alpha hat, T over 2n, is a gamma of n and n over alpha, with mgf 1 minus alpha t over n to the minus n, mean alpha and variance alpha squared over n.XRayleigh(α)Y = X²exp(1/(2α))T = Σ Yᵢgamma(n, 1/(2α))α̂ = T / (2n)gamma(n, n/α)squaredadd÷ 2nM(t) = 1/(1 − 2αt)M(t) = (1 − 2αt)⁻ⁿM(t) = (1 − αt/n)⁻ⁿadding n independent ones = multiplying the mgfsdividing by 2n = replacing t with t/(2n)E = α Var = α²/n
Three steps and one mgf at each: the Rayleigh MLE is a gamma centred on α.

In the picture, the whole chain: from a Rayleigh to an exponential (squaring), from n exponentials to a gamma (adding), and from that gamma to another (dividing by 2n). Under each arrow, what changes in the mgf.

For the curious. That E(α^)=α E(\hat\alpha) = \alpha means the estimator does not systematically miss α: some samples overestimate it and others underestimate it, but on average it hits. This is called being unbiased, and it is the first thing in the next topic. That Var(α^)=α2/n \text{Var}(\hat\alpha) = \alpha^2/n goes down with n says that with more data it concentrates around α.

Result for the cheat sheet. Invariance: MLE of τ(θ) \tau(\theta) = τ(θ^) \tau(\hat\theta) . Rayleigh: X2∼exp(1/(2α)) X^2 \sim \text{exp}(1/(2\alpha)) , ∑Xi2∼gamma(n,1/(2α)) \sum X_i^2 \sim \text{gamma}(n, 1/(2\alpha)) , α^∼gamma(n,n/α) \hat\alpha \sim \text{gamma}(n, n/\alpha) .

Check it in R

We simulate 10,000 samples of 40 readings from a Rayleigh with α = 94 (a Rayleigh is simulated as −2αlog⁡U \sqrt{-2\alpha\log U} , with U uniform) and compute α^ \hat\alpha in each:

set.seed(9)
alphas <- replicate(10000, {
  x <- sqrt(-2 * 94 * log(runif(40)))   # 40 readings from a Rayleigh(94)
  sum(x^2) / 80                          # its MLE
})
round(c(mean = mean(alphas), theoretical = 94, var = var(alphas), var_theoretical = 94^2 / 40), 2)
hist(alphas, freq = FALSE, breaks = 40, main = "10,000 MLEs of alpha", xlab = "alpha")
curve(dgamma(x, 40, 40 / 94), add = TRUE, lwd = 2)

Output:

           mean     theoretical             var var_theoretical 
          94.13           94.00          223.13          220.90 
10,000 estimates of α with 40 readingsDensity-scale histogram of 10,000 maximum likelihood estimators of alpha, each with 40 readings simulated from a Rayleigh with alpha 94, between 45 and 165, centred on 94 and slightly skewed right. On top, in coral, the gamma density with shape 40 and rate 40 over 94, which fits it. A dashed line marks alpha equal to 94.0.000.010.020.0345607590105120135150165α̂densityα = 94gamma(40, 0.43)= gamma(n, n/α)
What hist and curve draw: the gamma from the proof fits the simulation.

The mean of the 10,000 MLEs is 94.13, practically α = 94, and their variance 223.13 against the theoretical 942/40=220.9 94^2/40 = 220.9 : the difference is simulation noise. In the picture, the histogram fits the gamma(40, 0.43) from the proof: slightly skewed right (MLEs of 120 are more likely than ones of 68), centred on 94. Our 93.14 is one of those 10,000 points, quite close to the center.

Check you’ve got it: with 160 readings instead of 40, what distribution would the MLE of α have, and what would its standard deviation be if α = 94?

A gamma(160, 160/94), centred on 94. Its variance is 942/160 94^2/160 , so its standard deviation is 94/160=7.43 94/\sqrt{160} = 7.43 , half of what it is with 40 readings (14.86). Four times as much data, half the spread.

Prove it yourself

Three new proofs, with their solution folded away. Try each one on paper before opening it.

1. The geometric. The number of correct readings the station takes before the first sensor failure is geometric: P(X=x)=p(1−p)x P(X = x) = p(1-p)^x , x=0,1,2,… x = 0, 1, 2, \dots Find the MLE of p and check that it is a maximum.

Show the solution

L(p)=∏p(1−p)xi=pn(1−p)s L(p) = \prod p(1-p)^{x_i} = p^n(1-p)^s , with s=∑xi s = \sum x_i . By rules 1 and 2, ℓ(p)=nlog⁡p+slog⁡(1−p) \ell(p) = n\log p + s\log(1-p) .

ℓ′(p)=np−s1−p=n(1−p)−spp(1−p)=n−(n+s)pp(1−p)=0⇒p^=nn+s=11+Xˉ \ell'(p) = \frac np – \frac{s}{1-p} = \frac{n(1-p) – sp}{p(1-p)} = \frac{n – (n+s)p}{p(1-p)} = 0 \Rightarrow \hat p = \frac{n}{n+s} = \frac{1}{1+\bar X} (dividing top and bottom by n).

ℓ′′(p)=−np2−s(1−p)2<0 \ell''(p) = -\frac{n}{p^2} – \frac{s}{(1-p)^2} < 0 always: maximum. By moments you get the same, because E(X)=(1−p)/p E(X) = (1-p)/p and solving Xˉ=(1−p)/p \bar X = (1-p)/p also gives 1/(1+Xˉ) 1/(1+\bar X) .

2. Probability of an hour with no gusts. With the gusts Poisson(λ), find the MLE of the probability that an hour has no strong gust, and compute it with the data (xˉ=3.21 \bar x = 3.21 ).

Show the solution

P(X=0)=e−λ P(X = 0) = e^{-\lambda} . By proof 3, λ^=Xˉ \hat\lambda = \bar X , and by the invariance principle (proof 7), the MLE of e−λ e^{-\lambda} is e−λ^=e−Xˉ e^{-\hat\lambda} = e^{-\bar X} .

With the data: e−3.21=0.040 e^{-3.21} = 0.040 . We estimate that 4 % of hours have no strong gust. In the sample, none of the 24 hours had 0, which with 4 % is to be expected (the usual would be 1 in 24).

3. The shifted exponential. The time the station takes to restart after a power cut has density f(x∣θ)=e−(x−θ) f(x \mid \theta) = e^{-(x – \theta)} for x≥θ x \ge \theta (it never takes less than θ seconds). Find the MLE and the moments estimator of θ.

Show the solution

Maximum likelihood. L(θ)=∏e−(xi−θ)=e−s+nθ L(\theta) = \prod e^{-(x_i – \theta)} = e^{-s + n\theta} if θ≤xi \theta \le x_i for every i, that is, if θ≤min⁡xi \theta \le \min x_i ; and 0 otherwise. Where it is not 0, L(θ)=enθ−s L(\theta) = e^{n\theta – s} grows with θ. So the maximum is at the largest allowed θ: θ^=min⁡(X1,…,Xn)=X(1) \hat\theta = \min(X_1, \dots, X_n) = X_{(1)} . As in the uniform, the derivative (ℓ′=n>0 \ell' = n > 0 ) is never zero: the maximum is at an edge.

Moments. X−θ X – \theta is an exponential with rate 1 (change y=x−θ y = x – \theta ), so E(X)=θ+1 E(X) = \theta + 1 . Matching: θ+1=Xˉ⇒θ~=Xˉ−1 \theta + 1 = \bar X \Rightarrow \tilde\theta = \bar X – 1 . It can come out larger than the smallest data point, and then it would make that point impossible.

When to use each result

If you are asked for…UseWatch out for…
The moments estimator of one parameterE(X)=Xˉ E(X) = \bar X and solveGetting E(X) E(X) right (integral with a change, like the Rayleigh)
The moments estimator of two parametersMean and variance: E(X)=Xˉ E(X) = \bar X , Var(X)=S′2 \text{Var}(X) = S'^2 S′2 S'^2 divides by n, not var()
The MLE of a “nice” distribution (differentiable, fixed support)The four steps: L, ℓ, ℓ’ = 0, ℓ” < 0Terms that do not depend on the parameter vanish when differentiating
The MLE with two parametersPartial derivatives and a systemIf it cannot be solved (gamma, beta, two-parameter Weibull), optim or fitdist
The MLE when the support depends on θDraw L and reasonThe maximum is an extreme of the sample (max or min)
The MLE of a function of the parameterInvariance: τ(θ^) \tau(\hat\theta) Only valid for MLEs, not for moments
The distribution of the MLEChange of variable and mgf (sum of independents)McT(t)=MT(ct) M_{cT}(t) = M_T(ct)

Common mistakes when proving

  • Confusing ∑xi2 \sum x_i^2 with (∑xi)2 (\sum x_i)^2 . In the Rayleigh, the normal with μ known or the variance, the square goes inside the sum.
  • Forgetting the second derivative. It is marked separately in the exam. If ℓ′′ \ell'' depends on the parameter, evaluate it at θ^ \hat\theta (as in the Rayleigh).
  • Differentiating when the support depends on the parameter. Uniform(0, θ), shifted exponential, 2x/θ2 2x/\theta^2 on (0,θ) (0, \theta) : first the picture of L.
  • Dragging constants along. ∑log⁡xi! \sum\log x_i! , n2log⁡2π \frac n2\log 2\pi , ∑log⁡xi \sum\log x_i do not depend on the parameter: write “+ c” and move on.
  • Using S2 S^2 instead of S′2 S'^2 in moments and in the MLE of the normal’s σ².
  • Solving wrongly when dividing equations in the two-parameter moments system: divide the mean equation by the variance one, not the other way round, and check by substituting.

Try it in the R playground

Open the R playground on the site (or RStudio) and paste this script, which checks with simulation the hardest point of the article: that the uniform MLE never overshoots the parameter while the moments one does.

set.seed(1)
theta <- 4; n <- 15
est <- replicate(10000, {
  x <- runif(n, 0, theta)
  c(ml = max(x), mm = 2 * mean(x), largest = max(x))
})
rowMeans(est[1:2, ])                       # mean of each estimator
mean(est["mm", ] < est["largest", ])       # moments below the largest data point
mean(est["ml", ] > theta)                  # maximum likelihood above theta
hist(est["ml", ], breaks = 40, main = "MLE of theta = max(x)", xlab = "theta")

Things to look at:

  1. rowMeans: the mean of the MLE comes out a little below 4 (it can never overshoot) and the moments one, almost exactly 4.
  2. The proportion of samples where the moments estimator falls below the largest data point: more than a third. It is an estimator that is sometimes impossible.
  3. mean(est["ml", ] > theta) gives 0: the sample maximum never exceeds θ.
  4. The histogram: everything pressed to the left of 4, with a wall at 4. Change n <- 15 to n <- 60 and see how it presses closer.

Summary

DistributionMomentsMaximum likelihoodHow you get there
Rayleigh(α)2Xˉ2/π 2\bar X^2/\pi ∑Xi2/(2n) \sum X_i^2/(2n) Integral with t=x2 t = x^2 ; derivative and ℓ” at α^ \hat\alpha
Gamma(α, β)Xˉ2/S′2 \bar X^2/S'^2 , Xˉ/S′2 \bar X/S'^2 optim/fitdistMoments system; digamma, no closed form
Uniform(a, b)Xˉ∓3S′ \bar X \mp \sqrt3 S' —Mean and variance
Bernoulli(p)Xˉ \bar X Xˉ \bar X ℓ′′<0 \ell'' < 0 on all of (0, 1)
Poisson(λ)Xˉ \bar X (or S′2 S'^2 )Xˉ \bar X The constant ∑log⁡xi! \sum\log x_i! vanishes
exp(λ)1/Xˉ 1/\bar X 1/Xˉ 1/\bar X ℓ′′=−n/λ2 \ell'' = -n/\lambda^2
Normal(μ, σ)Xˉ \bar X , S′2 S'^2 Xˉ \bar X , S′2 S'^2 System of two equations
Uniform(0, θ)2Xˉ 2\bar X max⁡Xi \max X_i No derivative: the edge

Three ideas to take away:

  1. The recipe is L, log, derivative, second derivative. The log turns products into sums and does not move the maximum; constants vanish when differentiating.
  2. If the support depends on the parameter, do not differentiate: draw. The maximum is at an extreme of the sample.
  3. The MLE is a random variable with its distribution. With a change of variable and the mgf you get it (the Rayleigh gives a gamma), and from there its mean and variance, which is what measures whether an estimator is good.

Now it is time to do it on the computer: in the point estimation practice in R you estimate the station’s series, draw likelihoods and fit the rain with optim and fitdist. And in the point estimation exercises you have these proofs as the first part of exam-style exercises.

Next step: practicePoint estimation — R practice with the campus station, moments, optimize, optim and fitdist (and the likelihood that came out zero with 400 readings)

Did this article help you? Here is how you can support SergioLearns →