Simple Algorithm
Machine Learning · Descent · 22 min

Maximum Likelihood & MAP

Choosing parameters that make the data most probable.

Every time you train a classifier with cross-entropy or fit a line by least squares, you are maximizing a likelihood. This lesson derives maximum likelihood estimates from scratch, shows that they match the model to the data's distribution, and adds a prior to get MAP estimation, which turns out to be ridge and the lasso in disguise.

What you’ll learn

  • Write the likelihood and log-likelihood of i.i.d. data, and derive the maximum likelihood estimates for Bernoulli and Gaussian models.
  • Prove that the Gaussian variance MLE is biased by the factor (n−1)/n(n-1)/n, and explain why that bias is not a flaw in itself.
  • Show that maximizing the likelihood minimizes the cross-entropy and the KL divergence from the empirical distribution, and read common losses as negative log-likelihoods.
  • Derive MAP estimation as the MLE plus a log-prior, and recover ridge from a Gaussian prior and the lasso from a Laplace prior.
  • Explain how zero counts break the MLE on small samples, and repair them with additive smoothing.

The likelihood function

A parametric model is a family of distributions p(x∣θ)p(x \mid \boldsymbol\theta). Given data D={x1,…,xn}\data = \{x_1, \dots, x_n\} drawn i.i.d. from one member of the family, the likelihood is the probability (or density) of the observed data, read as a function of the parameters, and the log-likelihood is its logarithm:

L(θ)=∏i=1np(xi∣θ),ℓ(θ)=log⁡L(θ)=∑i=1nlog⁡p(xi∣θ).L(\boldsymbol\theta) = \prod_{i=1}^n p(x_i \mid \boldsymbol\theta), \qquad \ell(\boldsymbol\theta) = \log L(\boldsymbol\theta) = \sum_{i=1}^n \log p(x_i \mid \boldsymbol\theta).

The maximum likelihood estimate is θ^=arg max⁡θℓ(θ)\hat{\boldsymbol\theta} = \argmax_{\boldsymbol\theta} \ell(\boldsymbol\theta). Logs change nothing about where the maximum is, since log⁡\log is increasing, but they turn products into sums that are easy to differentiate, and they prevent underflow: 1,000 flips of a fair coin have probability 2−1000≈10−3012^{-1000} \approx 10^{-301}, on the edge of what double precision can represent.

DerivationThe Bernoulli MLE
  1. ℓ(p)=∑i=1n[xilog⁡p+(1−xi)log⁡(1−p)]=hlog⁡p+(n−h)log⁡(1−p)\ell(p) = \sum_{i=1}^n \big[x_i \log p + (1-x_i)\log(1-p)\big] = h\log p + (n-h)\log(1-p)

    A coin with P(x=1)=pP(x = 1) = p gives p(x∣p)=px(1−p)1−xp(x \mid p) = p^x (1-p)^{1-x} for x∈{0,1}x \in \{0, 1\}. With hh heads among nn flips:

  2. ℓ′(p)=hp−n−h1−p=0⟹p^=hn\ell'(p) = \frac{h}{p} - \frac{n-h}{1-p} = 0 \quad\Longrightarrow\quad \hat p = \frac{h}{n}

    Set the derivative to zero:

  3. ℓ′′(p)=−hp2−n−h(1−p)2<0\ell''(p) = -\frac{h}{p^2} - \frac{n-h}{(1-p)^2} < 0

    The second derivative is negative everywhere, so ℓ\ell is concave and this stationary point is the global maximum when 0<h<n0 < h < n. If h=0h = 0 or h=nh = n, ℓ\ell is monotone and the maximum sits on the boundary, p^=0\hat p = 0 or 11.

Check your understanding

From 100 flips you find p^=0.7\hat p = 0.7. What is the maximum likelihood estimate of the odds p/(1−p)p/(1-p)?

  1. It must be derived again from scratch; there is no shortcut
  2. 0.70.7, because the odds and the probability are the same parameter
  3. 0.7/0.3≈2.330.7/0.3 \approx 2.33
  4. 1/0.3≈3.331/0.3 \approx 3.33
Show the answer

C. 0.7/0.3≈2.330.7/0.3 \approx 2.33

The MLE is invariant: if θ^\hat{\boldsymbol\theta} maximizes the likelihood, then for any one-to-one reparameterization η=g(θ)\boldsymbol\eta = g(\boldsymbol\theta), the MLE of η\boldsymbol\eta is g(θ^)g(\hat{\boldsymbol\theta}). Relabeling the parameter does not change which distribution makes the data most probable.

Gaussian MLE, and a biased variance

DerivationMean and variance of a Gaussian
  1. ℓ(μ,σ2)=−n2log⁡(2πσ2)−12σ2∑i=1n(xi−μ)2\ell(\mu, \sigma^2) = -\frac n2\log(2\pi\sigma^2) - \frac1{2\sigma^2}\sum_{i=1}^n (x_i-\mu)^2

    For xi∼N(μ,σ2)x_i \sim \mathcal N(\mu, \sigma^2) i.i.d., the log-likelihood is

  2. μ^=xˉ=1n∑i=1nxi,σ^2=1n∑i=1n(xi−xˉ)2\hat\mu = \bar x = \frac1n\sum_{i=1}^n x_i, \qquad \hat\sigma^2 = \frac1n\sum_{i=1}^n (x_i - \bar x)^2

    Setting ∂ℓ/∂μ=∑i(xi−μ)/σ2=0\partial\ell/\partial\mu = \sum_i (x_i - \mu)/\sigma^2 = 0 gives the sample mean, whatever σ2\sigma^2 is. Then ∂ℓ/∂σ2=−n2σ2+12σ4∑i(xi−μ^)2=0\partial\ell/\partial\sigma^2 = -\frac{n}{2\sigma^2} + \frac{1}{2\sigma^4}\sum_i (x_i - \hat\mu)^2 = 0 gives the average squared deviation:

  3. ∑i=1n(xi−xˉ)2=∑i=1n(xi−μ)2−n(xˉ−μ)2\sum_{i=1}^n (x_i - \bar x)^2 = \sum_{i=1}^n (x_i - \mu)^2 - n(\bar x - \mu)^2

    To find E[σ^2]\E[\hat\sigma^2], expand around the true mean. The cross term collapses because ∑i(xi−xˉ)=0\sum_i (x_i - \bar x) = 0:

  4. E[∑i=1n(xi−xˉ)2]=nσ2−σ2⟹E[σ^2]=n−1n σ2\E\Big[\sum_{i=1}^n (x_i - \bar x)^2\Big] = n\sigma^2 - \sigma^2 \quad\Longrightarrow\quad \E[\hat\sigma^2] = \frac{n-1}{n}\,\sigma^2

    Each (xi−μ)2(x_i - \mu)^2 has mean σ2\sigma^2 and Var⁡xˉ=σ2/n\Var\bar x = \sigma^2/n, so the deviations from xˉ\bar x fall short by exactly one σ2\sigma^2: xˉ\bar x is fitted to the same data, so the points sit closer to it than to the truth.

Predict before you look

You estimate a Gaussian's variance by maximum likelihood from n=5n = 5 observations. On average, the estimate is what percentage of the true variance?

Show the answer

80 %

E[σ^2]=n−1nσ2=45σ2\E[\hat\sigma^2] = \frac{n-1}{n}\sigma^2 = \frac45\sigma^2: a 20% underestimate on average. Dividing by n−1n-1 instead (Bessel's correction) removes the bias. Yet for Gaussian data the MLE has the smaller mean squared error, 0.36σ40.36\sigma^4 against 0.5σ40.5\sigma^4 at n=5n = 5, and dividing by n+1n+1 does better still (0.33σ40.33\sigma^4). Unbiasedness is one virtue among several, not a requirement.

The same steps in dd dimensions give μ^=xˉ\hat{\boldsymbol\mu} = \bar{\mathbf x} and Σ^=1n∑i(xi−xˉ)(xi−xˉ)⊤\hat\Sigma = \frac1n\sum_i (\mathbf x_i - \bar{\mathbf x})(\mathbf x_i - \bar{\mathbf x})^\top. Conditional models work the same way. In linear regression with Gaussian noise, yi∣xi∼N(w⊤xi,σ2)y_i \mid \mathbf x_i \sim \mathcal N(\mathbf w^\top \mathbf x_i, \sigma^2), the log-likelihood is −n2log⁡(2πσ2)−12σ2∥y−Xw∥2-\frac n2 \log(2\pi\sigma^2) - \frac{1}{2\sigma^2}\norm{\mathbf y - X\mathbf w}^2. For any σ2\sigma^2 it is maximized by minimizing the squared error: the MLE of w\mathbf w is least squares, and σ^2=RSS/n\hat\sigma^2 = \mathrm{RSS}/n, biased low again (the unbiased version divides by n−dn - d).

Maximum likelihood matches distributions

Why is maximum likelihood a sensible goal at all? Rewrite the average log-likelihood as an expectation under the empirical distribution p^n\hat p_n, which puts mass 1/n1/n on each data point.

DerivationMLE = minimum cross-entropy = minimum KL
  1. 1n ℓ(θ)=1n∑i=1nlog⁡pθ(xi)=Ex∼p^n[log⁡pθ(x)]\frac1n\,\ell(\boldsymbol\theta) = \frac1n\sum_{i=1}^n \log p_{\boldsymbol\theta}(x_i) = \E_{x\sim\hat p_n}\big[\log p_{\boldsymbol\theta}(x)\big]

    The average log-likelihood is an average of log⁡pθ\log p_{\boldsymbol\theta} over the data:

  2. −1n ℓ(θ)=H(p^n,pθ)=H(p^n)+DKL(p^n ∥ pθ)-\frac1n\,\ell(\boldsymbol\theta) = H(\hat p_n, p_{\boldsymbol\theta}) = H(\hat p_n) + \KL(\hat p_n \,\|\, p_{\boldsymbol\theta})

    For discrete data its negative is the cross-entropy from p^n\hat p_n to the model, which splits into the data's own entropy plus the KL divergence:

  3. θ^MLE=arg min⁡θ H(p^n,pθ)=arg min⁡θ DKL(p^n ∥ pθ)\hat{\boldsymbol\theta}_{\text{MLE}} = \argmin_{\boldsymbol\theta}\, H(\hat p_n, p_{\boldsymbol\theta}) = \argmin_{\boldsymbol\theta}\, \KL(\hat p_n \,\|\, p_{\boldsymbol\theta})

    H(p^n)H(\hat p_n) does not depend on θ\boldsymbol\theta. So maximizing the likelihood is the same as making the model's distribution as close as possible, in KL, to the data's:

  4. 1n ℓ(θ) → n→∞  EP[log⁡pθ(x)]=−H(P)−DKL(P ∥ pθ)\frac1n\,\ell(\boldsymbol\theta)\ \xrightarrow{\ n\to\infty\ }\ \E_{P}\big[\log p_{\boldsymbol\theta}(x)\big] = -H(P) - \KL(P \,\|\, p_{\boldsymbol\theta})

    As n→∞n \to \infty the law of large numbers turns the average into an expectation under the true distribution PP (for densities, HH is the differential entropy). The MLE therefore aims at the parameter whose distribution is closest to the truth in KL: the true parameter if the model is right, the best approximation if it is not.

Loss you minimizeNoise model it assumesWhere you meet it
squared error (y−f(x))2(y - f(\mathbf x))^2y∣x∼N(f(x),σ2)y \mid \mathbf x \sim \mathcal N(f(\mathbf x), \sigma^2)least squares, most regression
absolute error ∣y−f(x)∣\abs{y - f(\mathbf x)}Laplace noise around f(x)f(\mathbf x)median regression, robust to outliers
log loss −ylog⁡q−(1−y)log⁡(1−q)-y\log q - (1-y)\log(1-q)y∣x∼Bernoulli(q(x))y \mid \mathbf x \sim \mathrm{Bernoulli}(q(\mathbf x))logistic regression, binary classifiers
softmax cross-entropy −log⁡qy(x)-\log q_{y}(\mathbf x)y∣xy \mid \mathbf x categorical with probabilities q(x)q(\mathbf x)multiclass networks
Poisson deviance, up to constants μ−ylog⁡μ\mu - y\log\muy∣x∼Poisson(μ(x))y \mid \mathbf x \sim \mathrm{Poisson}(\mu(\mathbf x))count regression
Choosing a loss is choosing a noise model, and the noise model says what the prediction means: squared error makes f(x)f(\mathbf x) an estimate of the conditional mean, absolute error of the conditional median.

MAP: a prior becomes a penalty

Put a prior p(θ)p(\boldsymbol\theta) on the parameters. The posterior is proportional to likelihood × prior, and its mode is the MAP estimate. The evidence p(D)p(\data) does not depend on θ\boldsymbol\theta, so it drops out:

θ^MAP=arg max⁡θ [ ℓ(θ)+log⁡p(θ) ].\hat{\boldsymbol\theta}_{\text{MAP}} = \argmax_{\boldsymbol\theta}\ \big[\,\ell(\boldsymbol\theta) + \log p(\boldsymbol\theta)\,\big].

MAP is maximum likelihood with a penalty, and the penalty is the negative log-prior. For a coin with a Beta prior Beta(a,b)\mathrm{Beta}(a, b), the same calculus as before gives p^MAP=(h+a−1)/(n+a+b−2)\hat p_{\text{MAP}} = (h + a - 1)/(n + a + b - 2): the prior adds a−1a - 1 imaginary heads and b−1b - 1 imaginary tails.

DerivationRidge and the lasso are MAP estimates
  1. −log⁡p(w∣D)=12σ2∥y−Xw∥2+12τ2∥w∥22+const-\log p(\mathbf w \mid \data) = \frac{1}{2\sigma^2}\norm{\mathbf y - X\mathbf w}^2 + \frac{1}{2\tau^2}\norm{\mathbf w}_2^2 + \text{const}

    Linear regression with y∣X,w∼N(Xw,σ2I)\mathbf y \mid X, \mathbf w \sim \mathcal N(X\mathbf w, \sigma^2 I) and a Gaussian prior w∼N(0,τ2I)\mathbf w \sim \mathcal N(\mathbf 0, \tau^2 I). The negative log-posterior, up to constants, is

  2. w^MAP=arg min⁡w ∥y−Xw∥2+λ∥w∥22,λ=σ2τ2\hat{\mathbf w}_{\text{MAP}} = \argmin_{\mathbf w}\ \norm{\mathbf y - X\mathbf w}^2 + \lambda\norm{\mathbf w}_2^2, \qquad \lambda = \frac{\sigma^2}{\tau^2}

    Multiply by 2σ22\sigma^2, which does not move the minimizer: this is ridge regression, with the penalty set by the ratio of noise to prior variance.

  3. w^MAP=arg min⁡w ∥y−Xw∥2+λ∥w∥1,λ=2σ2b\hat{\mathbf w}_{\text{MAP}} = \argmin_{\mathbf w}\ \norm{\mathbf y - X\mathbf w}^2 + \lambda\norm{\mathbf w}_1, \qquad \lambda = \frac{2\sigma^2}{b}

    With independent Laplace priors p(wj)=12be−∣wj∣/bp(w_j) = \frac{1}{2b}e^{-\abs{w_j}/b} instead, −log⁡p(w)=∥w∥1/b+const-\log p(\mathbf w) = \norm{\mathbf w}_1/b + \text{const}, and the same rescaling gives the lasso (Tibshirani, 1996, noted this reading):

Small samples: zero counts and smoothing

For a categorical variable with KK outcomes and counts n1,…,nKn_1, \dots, n_K, maximizing ∑knklog⁡πk\sum_k n_k \log \pi_k subject to ∑kπk=1\sum_k \pi_k = 1 (one Lagrange multiplier) gives π^k=nk/n\hat\pi_k = n_k/n. Every outcome that has not been seen gets probability exactly zero.

That is fatal in naive Bayes. A spam filter multiplies one probability per word; if "refund" never occurred in the legitimate emails of the training set, any new email containing it gets likelihood zero under "legitimate", whatever its other thousand words say. The standard repair is additive smoothing:

π^k=nk+αn+Kα.\hat\pi_k = \frac{n_k + \alpha}{n + K\alpha}.

With α=1\alpha = 1 it is Laplace's add-one rule. It is the posterior mean under a symmetric Dirichlet prior with parameter α\alpha, or the MAP estimate under a Dirichlet with parameter α+1\alpha + 1, as Conjugate Priors & Exact Posteriors shows.

Predict before you look

A six-sided die is rolled 20 times and never shows a six. With add-one smoothing (α=1\alpha = 1, K=6K = 6), what probability do you assign to a six?

Show the answer

3.8 %

(0+1)/(20+6)=1/26≈3.8%(0 + 1)/(20 + 6) = 1/26 \approx 3.8\%. The MLE says 0%, which no one believes about a die. The smoothed estimate is still well below the fair 16.7%16.7\%, because twenty rolls with no six are some evidence against it, but it leaves room for the next roll to be a six.

How much should you trust an MLE once it is defined? As n→∞n \to \infty, under regularity conditions, it is consistent (it converges to the true parameter; Wald, 1949) and asymptotically normal, with variance 1/(n I(θ))1/(n\,I(\theta)), where I(θ)I(\theta) is the Fisher information carried by one observation. For a coin I(p)=1/(p(1−p))I(p) = 1/(p(1-p)), so the standard error is about p^(1−p^)/n\sqrt{\hat p(1-\hat p)/n}: with 70 heads in 100 flips, about 0.0460.046. The Convergence lesson Asymptotics of Maximum Likelihood proves these results, and shows where they fail.

Computing MLEs, and the road ahead

Closed forms are the exception. For exponential families the likelihood equations reduce to matching averages of a few statistics; otherwise the negative log-likelihood is simply a loss to minimize numerically, by gradient methods, by Newton's method (iteratively reweighted least squares for generalized linear models), or by EM when some variables are unobserved (Latent Variables & EM). Optimizing over unconstrained transformed parameters, such as a log-scale, keeps positive quantities positive, and invariance means nothing is lost.

python
import numpy as np
from scipy import optimize, stats

x = np.random.default_rng(0).gamma(shape=2.0, scale=1.5, size=500)  # positive data

def nll(params):
    # optimize log(shape) and log(scale): both stay positive
    shape, scale = np.exp(params)
    return -stats.gamma.logpdf(x, a=shape, scale=scale).sum()

res = optimize.minimize(nll, x0=[0.0, np.log(x.mean())], method="L-BFGS-B")
shape_hat, scale_hat = np.exp(res.x)  # invariance: transform back

# At the MLE the likelihood equation for the scale reads shape * scale = mean(x)
print(shape_hat * scale_hat, x.mean())

A Gamma fit by numerical maximum likelihood. The two printed numbers agree up to the optimizer's tolerance: setting ∂ℓ/∂θ=0\partial\ell/\partial\theta = 0 for the scale θ\theta gives kθ=xˉk\theta = \bar x exactly, a first glimpse of moment matching in exponential families.

Key takeaways

  • The likelihood ∏ip(xi∣θ)\prod_i p(x_i \mid \boldsymbol\theta) is the probability of the data as a function of the parameters, not a distribution over them. The MLE maximizes it, usually through the log-likelihood, and is invariant to reparameterization.
  • For a coin p^=h/n\hat p = h/n; for a Gaussian μ^=xˉ\hat\mu = \bar x and σ^2=1n∑i(xi−xˉ)2\hat\sigma^2 = \frac1n\sum_i (x_i - \bar x)^2, biased by the factor (n−1)/n(n-1)/n; for linear regression with Gaussian noise the MLE is least squares.
  • Maximum likelihood minimizes the cross-entropy and the KL divergence DKL(p^n ∥ pθ)\KL(\hat p_n \,\|\, p_{\boldsymbol\theta}); squared error, absolute error and cross-entropy are negative log-likelihoods under matching noise models.
  • MAP estimation adds the log-prior to the log-likelihood: a Gaussian prior gives ridge with λ=σ2/τ2\lambda = \sigma^2/\tau^2, a Laplace prior the lasso with λ=2σ2/b\lambda = 2\sigma^2/b. Unlike the MLE, the MAP estimate depends on the parameterization.
  • On small samples the MLE gives unseen outcomes probability zero; additive smoothing (nk+α)/(n+Kα)(n_k + \alpha)/(n + K\alpha) fixes it. As nn grows the MLE becomes consistent and approximately normal with variance 1/(n I(θ))1/(n\,I(\theta)).

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

σ^2=1n∑i(xi−xˉ)2\hat\sigma^2 = \frac1n\sum_i (x_i - \bar x)^2 is computed from nn i.i.d. draws of N(μ,σ2)\mathcal N(\mu, \sigma^2). What is E[σ^2]\E[\hat\sigma^2]?

  1. σ2\sigma^2: the MLE is unbiased
  2. n−1nσ2\frac{n-1}{n}\sigma^2
  3. nn−1σ2\frac{n}{n-1}\sigma^2
  4. It depends on μ\mu
Show the answer

B. n−1nσ2\frac{n-1}{n}\sigma^2

∑i(xi−xˉ)2=∑i(xi−μ)2−n(xˉ−μ)2\sum_i (x_i - \bar x)^2 = \sum_i (x_i - \mu)^2 - n(\bar x - \mu)^2 has expectation nσ2−σ2n\sigma^2 - \sigma^2. Fitting xˉ\bar x to the same data uses up one observation's worth of variation.

Question 2

Maximizing the likelihood of discrete data is equivalent to minimizing which quantity over θ\boldsymbol\theta?

  1. DKL(p^n ∥ pθ)\KL(\hat p_n \,\|\, p_{\boldsymbol\theta}), the KL from the empirical distribution to the model
  2. DKL(pθ ∥ p^n)\KL(p_{\boldsymbol\theta} \,\|\, \hat p_n), the KL from the model to the data
  3. The entropy of the model, H(pθ)H(p_{\boldsymbol\theta})
  4. The squared distance between θ\boldsymbol\theta and the true parameter
Show the answer

A. DKL(p^n ∥ pθ)\KL(\hat p_n \,\|\, p_{\boldsymbol\theta}), the KL from the empirical distribution to the model

−1nℓ(θ)=H(p^n)+DKL(p^n ∥ pθ)-\frac1n\ell(\boldsymbol\theta) = H(\hat p_n) + \KL(\hat p_n \,\|\, p_{\boldsymbol\theta}), and the first term is constant. The expectation is taken under the data, which is why every observed point must get positive model probability.

Question 3

Linear regression has Gaussian noise of variance σ2\sigma^2 and a prior w∼N(0,τ2I)\mathbf w \sim \mathcal N(\mathbf 0, \tau^2 I). The MAP estimate minimizes ∥y−Xw∥2+λ∥w∥22\norm{\mathbf y - X\mathbf w}^2 + \lambda\norm{\mathbf w}_2^2 with which λ\lambda?

  1. λ=τ2/σ2\lambda = \tau^2/\sigma^2
  2. λ=1/τ2\lambda = 1/\tau^2
  3. λ=σ2/τ2\lambda = \sigma^2/\tau^2
  4. It is the lasso, not ridge
Show the answer

C. λ=σ2/τ2\lambda = \sigma^2/\tau^2

The negative log-posterior is 12σ2∥y−Xw∥2+12τ2∥w∥2\frac{1}{2\sigma^2}\norm{\mathbf y - X\mathbf w}^2 + \frac{1}{2\tau^2}\norm{\mathbf w}^2; multiplying by 2σ22\sigma^2 gives λ=σ2/τ2\lambda = \sigma^2/\tau^2. Noisier data or a tighter prior both mean more shrinkage.

Question 4

A naive Bayes spam filter is trained by maximum likelihood. The word "refund" never appeared in any legitimate training email. What happens to a new legitimate email that contains "refund"?

  1. Nothing unusual: one word has little effect on the total
  2. Its likelihood under "legitimate" is exactly zero, so the filter can never label it legitimate, whatever else it says
  3. The filter ignores words it has not seen with a class
  4. Its likelihood under "spam" becomes zero instead
Show the answer

B. Its likelihood under "legitimate" is exactly zero, so the filter can never label it legitimate, whatever else it says

Naive Bayes multiplies one estimated probability per word, and the MLE for "refund" given "legitimate" is 0/n=00/n = 0. One zero factor wipes out all other evidence. Additive smoothing, (nk+α)/(n+Kα)(n_k + \alpha)/(n + K\alpha), gives every word a small positive probability.

Question 5

You change parameterization from pp to the log-odds η=log⁡p1−p\eta = \log\frac{p}{1-p}, keeping the same data and the same prior beliefs (transformed correctly). Which estimates are guaranteed to describe the same distribution before and after?

  1. Both the MLE and the MAP estimate
  2. Neither: every estimate depends on the parameterization
  3. Only the MAP estimate
  4. Only the MLE
Show the answer

D. Only the MLE

The likelihood is a function of the distribution, so its maximizer just gets relabeled: η^=log⁡p^1−p^\hat\eta = \log\frac{\hat p}{1-\hat p}. A prior density picks up a Jacobian factor when you change variables, so its peak, and the posterior's, can move to a different distribution. With a flat prior on pp and 3 heads in 3 flips, the MAP is p=1p = 1 in one parameterization and p=0.8p = 0.8 in the other.

Go deeper

Further reading

  • R. A. Fisher, "On the mathematical foundations of theoretical statistics," Philosophical Transactions of the Royal Society A 222, 309–368 (1922).
  • G. Casella & R. L. Berger, Statistical Inference, 2nd ed. (Duxbury, 2002), chapter 7.
  • C. M. Bishop, Pattern Recognition and Machine Learning (Springer, 2006), sections 1.2 and 2.3.
  • R. Tibshirani, "Regression shrinkage and selection via the lasso," Journal of the Royal Statistical Society B 58(1), 267–288 (1996).