Learning a Constant from Data

Estimators, detectors, and the floor no estimator beats

Statistics runs backwards

A puzzle to carry through the week

How long did the run last? A production line stamps each item with the time it was made, in hours from the start of the run. The run lasted \(\phi\) hours, so the time stamps are spread over \([0,\phi]\). You have seen five, drawn at random: \[3.1,\quad 7.2,\quad 9.9,\quad 12.4,\quad 19.8 \qquad (\text{uniform on } [0,\phi]).\] How large is \(\phi\)?

More than one answer is defensible. Which is best, and is there a best possible? This week turns those two questions into mathematics.

The plan for the week

Estimators. Any function of the data, itself a random variable, judged by its bias and variance.

Detectors. The unknown takes only two values; the optimal statistic is the likelihood ratio.

Maximum likelihood and the floor. The same comparison over all candidate values, and the Cramér–Rao bound that no unbiased estimator beats.

In the notes Estimation within Statistics · Point Estimation and Quality Criteria · Hypothesis Testing and Detection · Maximum Likelihood Estimation · The Cramér–Rao Bound

From the model to the data, and back

Probability runs forward, from a model to the data it generates. Statistics runs backward, from data to the model.

The data are an iid sample whose law belongs to a parametric family with unknown parameter \(\phi\): \[f(\mathbf x;\phi)=\prod_{k=1}^N f_X(x_k;\phi).\] The semicolon says \(\phi\) is unknown but fixed: not random, and with no distribution of its own.

Estimator Any function of the data, \(\widehat\Phi=\Theta(X_1,\dots,X_N)\). Built from random data, it is itself a random variable, and its distribution is how we judge it.

Guess first

What is the frequency of this tone?

Answer two questions in the poll, without talking to your neighbors:

  1. Your estimate of the frequency, in Hz.
  2. How far apart will the class be? A classmate’s guess is typically ± ___ Hz away from the class average.

Who knows what

Each symbol carries one mark: its value is in hand, it is sought, or it is random and only its statistics are available.

The parametric family as a signal flow: \(\phi\) sought, lowercase because it is not random; the family known; \(N\) samples in hand.

Our own panel

predicted spread (class median of Q2) ___ Hz
observed spread \(s\) ___ Hz
class average \(\bar x\) ___ Hz
its standard error \(s/\sqrt N\) ___ Hz

The tone was \(\theta=789\) Hz.

\[\underbrace{\tfrac1N\sum_i (x_i-\theta)^2}_{\text{error}} =\underbrace{\tfrac1N\sum_i (x_i-\bar x)^2}_{\text{spread}} +\underbrace{(\bar x-\theta)^2}_{\text{bias}^2}\]

The spread was measurable before the reveal. The bias was not.

Was \(\abs{\bar x-\theta}\) within a few \(s/\sqrt N\)? If not, we were all wrong in the same direction, and a bigger class would not have helped.

Judging an estimator

Bias, variance, mean square error

Estimator quality \[\text{bias}=\E{\widehat\Phi}-\phi,\qquad \MSE=\E{(\widehat\Phi-\phi)^2}=\Var{\widehat\Phi}+\text{bias}^2 .\]

All three are read at a fixed \(N\). As \(N\) grows: asymptotically unbiased if the bias vanishes, consistent if \(\widehat\Phi\to\phi\), which needs both terms of the MSE to vanish.

Unbiasedness is not the goal; small error is. A little bias that buys a lot of variance is a good trade, and a deliberate one.

Why the error splits in two

Insert the estimator’s own mean and expand, exactly as for the best constant guess: \[\E{(\widehat\Phi-\phi)^2} =\E{(\widehat\Phi-\E{\widehat\Phi})^2} +2\,\underbrace{\E{\widehat\Phi-\E{\widehat\Phi}}}_{=0}\,(\E{\widehat\Phi}-\phi) +(\E{\widehat\Phi}-\phi)^2 .\]

Variance: how much the estimate wobbles from sample to sample. Bias: where it wobbles around. A dartboard with a tight cluster off-center, and a wide cluster on-center.

Two hundred estimates on a target whose center is the truth: the four combinations of small and large bias and variance.

Noise you can see without the truth

Two panels of twenty economists each forecast whether the economy grows next year (1) or shrinks (0).

Split: half are wrong whatever happens, and we know it today. Unanimous: error \(0\) or \(1\), and only the outcome will tell.

Variance (noise) is measured from the estimates alone; bias needs the truth.

One recipe, three levels

The same average read three ways: (a) the whole population, where \(m_X\) is a number; (b) one sample, one estimate, off by an unknown amount; (c) every possible sample, whose estimates form the sampling distribution.

The archetype: the sample mean

\(\widehat M_X=\frac1N\sum_kX_k\) is unbiased by linearity, at every \(N\), and has variance \(\sigma_X^2/N\). So it is consistent (the law of large numbers, read as a fact about an estimator), and by the central limit theorem its whole sampling distribution is known: \[\widehat M_X\approx\Gauss\!\paren{m_X,\tfrac{\sigma_X^2}{N}} .\]

None of this assumed a distribution for the data: only a finite variance. It is the yardstick every other estimator is measured against.

Estimating a spread: Bessel’s correction

With the mean known, \(\frac1N\sum_k(X_k-m_X)^2\) is unbiased. With the mean estimated from the same data it is not: \[\E{\frac1N\sum_{k=1}^N(X_k-\widehat M_X)^2}=\frac{N-1}{N}\,\sigma_X^2, \qquad\text{so use}\qquad \widehat\Sigma_X^2=\frac{1}{N-1}\sum_{k=1}^N(X_k-\widehat M_X)^2 .\]

\(\widehat M_X\) is by construction the point closest to the data, so the residuals around it are too small. Fitting the mean uses up one of the \(N\) directions the data could vary in: \(N-1\) degrees of freedom remain.

Unbiased is not the same as better

The two variance estimators over 10000 samples of size \(N=30\) from \(\Gauss(0,1)\).

Bias², variance and MSE of the two estimators against \(N\).

Matching moments

Method of moments With \(p\) unknown parameters, set \(\frac1N\sum_k x_k^n=\E{X^n;\phi}\) for \(n=1,\dots,p\) and solve.

The puzzle (\(p=1\)). The model mean is \(\phi/2\), so \[\widehat\phi_{\text{MoM}}=\frac2N\sum_kx_k=20.96,\] the twice the average guess: unbiased, consistent, one moment.

A Gaussian (\(p=2\)). Matching \(\E{X}\) and \(\E{X^2}\) gives \[\widehat m=\bar x,\qquad \widehat\sigma^2=\frac1N\sum_k(x_k-\bar x)^2,\] the divide-by-\(N\) estimator of the last slide.

Suspiciously wasteful: it reads only the average, while a sample near the edge says far more about where the edge is. The rest of the week explains how much it throws away.

Two moments do not pick a law

Four laws fitted to one sample of twelve points by matching the mean and variance. Left: every fit reproduces both moments and they still disagree everywhere. Right: their skewness and excess kurtosis.

The fits differ only in the higher moments, which twelve points estimate very badly. Matching moments answers the questions you asked of it, and no others.

Deciding: is it there, or not?

The simplest inference

  • Radar. An aircraft in this range cell, or receiver noise alone?
  • Alarm. Someone at the door, or a sensor drifting?
  • Communication. Was a \(0\) sent, or a \(1\)?

The parameter takes only two values, \(H_0\) and \(H_1\), and the answer must be one of them, with no option to hedge.

Detection as a signal flow: the same picture as estimation, with a parameter that takes only two values.

With two answers there is no estimator distribution to track: the whole problem is which data lead to which answer.

The rule is the region

A decision rule is fixed by its decision regions: decide \(H_1\) if \(\mathbf x\in\mathcal X_1\), \(H_0\) if \(\mathbf x\in\mathcal X_0\).

decide \(H_0\) decide \(H_1\)
\(H_0\) true correct silence false alarm \(P_F\)
\(H_1\) true miss \(1-P_D\) detection \(P_D\)

Each row sums to one, so two numbers describe any rule completely, and they pull against each other: fewer false alarms buys more misses.

Type I and Type II in statistics, false alarm and miss in radar, false positive and false negative in medicine: the same table.

From a test statistic to regions

Threshold a test statistic: \(\Theta(\mathbf x)\gtrless t\), so that \(\mathcal X_1=\set{\mathbf x:\Theta(\mathbf x)>t}\).

A statistic collapses \(N\)-dimensional data onto one axis, so the region becomes an interval. The question is which statistic.

One threshold, one point on the ROC

Figure 1: Left: the two densities of the data, with three thresholds. Right: each threshold is one point on the receiver operating characteristic (ROC).

The diagonal is a coin flip. Better separation pushes the curve to the top-left corner.

From data to ROC: the intruder alarm

A door sensor reports a score every second. Threshold it, collect the two conditional histograms, sweep the threshold.

Sweeping the threshold

One threshold is one operating point. The curve is the whole family of rules of this form, and choosing a detector means choosing a point on it.

A noisier sensor breaks the simple rule

When an intruder changes the spread of the score and not only its level, a threshold on \(x\) is the wrong shape of rule. What should be thresholded?

Threshold the likelihood ratio

\[\Lambda(\mathbf x)=\frac{f(\mathbf x;H_1)}{f(\mathbf x;H_0)}\;\underset{H_0}{\overset{H_1}{\gtrless}}\;t\]

Neyman–Pearson lemma Among all rules with false-alarm rate \(P_F\le\alpha\), the likelihood-ratio test maximizes \(P_D\).

Why. \(P_D-t\,P_F=\int_{\mathcal X_1}\bracket{f(\mathbf x;H_1)-t\,f(\mathbf x;H_0)}\dd\mathbf x\) is largest if \(\mathcal X_1\) collects exactly the points where the integrand is positive, which is where \(\Lambda(\mathbf x)>t\). The false-alarm budget fixes \(t\).

The rule is never “compare \(x\) with a number”; it is “compare \(\Lambda(\mathbf x)\) with a number.” The lemma needs simple hypotheses: no unknown parameter left inside either density.

The noisier sensor, resolved

The region \(\set{\Lambda>t}\) is two tails, not an interval: an extreme score either way is what the wide alternative predicts. Its ROC lies above the simple threshold’s everywhere.

In Gaussian noise, one number decides everything

A known level in Gaussian noise \(X=\pm A+N\), \(N\sim\Gauss(0,\sigma^2)\). Then \(\ln\Lambda(x)=2Ax/\sigma^2\) is linear in \(x\), so the test is a threshold on \(x\) after all, and \(P_F=Q\!\paren{\tfrac{\gamma+A}{\sigma}}\), \(P_D=Q\!\paren{\tfrac{\gamma-A}{\sigma}}\).

Figure 2: ROCs for four separations \(d = 2A/\sigma\).

The ROC depends only on \(d=2A/\sigma\), the separation in noise units. That is why detection performance is always quoted as a signal-to-noise ratio.

Did a human make this up?

A classroom experiment Write down a sequence of 30 heads and tails. Half of the room: flip a real coin. The other half: invent the sequence, as randomly as you can. Mark which you did, and hand it in.

While we collect: can we tell the two piles apart, without knowing which is which?

Is the coin fair?

The obvious test: the fraction of heads \(\widehat P_H\). Under \(H_0\) (fair, independent coin) it is a sample mean of \(N\) Bernoulli\((\tfrac12)\) tosses, so \(H_0\) supplies its mean and its variance:

The \(z\)-test \[Z_H=\frac{\widehat P_H-\tfrac12}{1/(2\sqrt{N})}\;\overset{H_0}{\approx}\;\Gauss(0,1), \qquad\text{reject if }\abs{Z_H}>2 .\]

Compute it for both piles. Both pass: people know that a coin shows heads half the time.

Nothing unknown in the null distribution, so this is the \(z\)-test in its exact setting. But a passed test says only that this statistic saw nothing.

The reveal: count the alternations

Count the steps where the outcome changes. For a fair, independent coin these are \(N-1\) iid Bernoulli\((\tfrac12)\) indicators, so the same test applies with \(N-1\) in place of \(N\): \[Z_A=\frac{\widehat P_A-\tfrac12}{1/(2\sqrt{N-1})} .\]

Figure 3: z-scores over 2000 simulated sequences of N = 100: a real coin (grey) and a person who switches with probability 0.6 (orange).

People break up runs because runs look unrandom, and alternate at about \(0.6\): \(Z_A\approx2\) at \(N=100\). Same formula, a different statistic: real randomness has longer runs than intuition expects.

Maximum likelihood

The density, read backwards

Hold the data fixed and let the parameter vary: \(f(\mathbf x;\phi)\) becomes the likelihood of \(\phi\). \[\widehat\phi_{\text{ML}}=\argmax_\phi\ \ln f(\mathbf x;\phi) =\argmax_\phi\ \sum_{k=1}^N\ln f_X(x_k;\phi).\]

Figure 4: Eight data points (ticks) and five candidate laws. Each stem is one factor of the likelihood; the candidate with the largest product (red) wins.

Detection compared two members of the family. Maximum likelihood compares all of them: \(\widehat\phi_{\text{ML}}\) is the candidate that wins every pairwise likelihood-ratio test at threshold \(t=1\).

Setting the derivative to zero

The Gaussian mean With \(\sigma^2\) known, \(\ln f=-\frac{1}{2\sigma^2}\sum_k(x_k-\phi)^2+\text{const}\), so \[\frac{\partial}{\partial\phi}\ln f=\frac{1}{\sigma^2}\sum_k(x_k-\phi)=0 \quad\Longrightarrow\quad \widehat\phi_{\text{ML}}=\frac1N\sum_k x_k .\]

Figure 5: The same eight points against Gaussians of known width at five means. The likelihood peaks at the sample mean.

The sample mean was maximum likelihood all along, for Gaussian data. The logarithm moved no maximum: it turned the product into a sum, one term per observation.

The likelihood sharpens with data

Figure 6: Log-likelihood of a Gaussian mean for one realization at three sample sizes, each normalized to its peak (dots: the ML estimate).

More data barely moves the peak; it makes it sharper. A sharp peak means the data tell nearby values of \(\phi\) apart. The curvature at the peak is the subject of the last part.

The center of a law, three noise models

The same unknown in all three: the center \(m\) of a symmetric law. Only the noise model changes.

noise model log-likelihood ML estimate of \(m\)
Gaussian, known \(\sigma^2\) \(-\frac{1}{2\sigma^2}\sum_k(x_k-m)^2\) sample mean \(\bar x\)
Laplacian, known \(b\) \(-\frac1b\sum_k\abs{x_k-m}\) sample median
Uniform on \([m-h,m+h]\), known \(h\) \(-N\ln(2h)\) if every \(\abs{x_k-m}\le h\) midrange \(\tfrac12(\min_kx_k+\max_kx_k)\)

The noise model chooses the loss. One estimator uses every sample, one essentially one (the middle), one exactly two (the extremes), and each is right for its own tails.

The three sampling distributions

Figure 7: Each estimator on data from each model: 20000 trials of \(N=15\), all parents with mean 0 and variance 1.
Figure 8: Standard deviation, relative to the best in each column. The matched estimator (red) wins every column; the cost of a mismatch is lopsided.

The puzzle by maximum likelihood

Each time stamp has density \(1/\phi\) on \([0,\phi]\), and \(0\) beyond it. So \[f(\mathbf x;\phi)=\begin{cases}\phi^{-N}, & \phi\ge\max_kx_k,\\ 0, & \text{otherwise.}\end{cases}\]

No derivative is zero anywhere: the maximum sits on the edge of the admissible set. Any smaller \(\phi\) rules out a time stamp we saw; any larger one spreads the same five points more thinly.

Scaling up the maximum

\(N\) points drop into \([0,\phi]\) and cut it into \(N+1\) gaps. By symmetry the gaps have the same expected length, \(\phi/(N+1)\), including the one between the largest value and the edge.

So the maximum falls short by one gap on average, \(\E{\max_kX_k}=\frac{N}{N+1}\,\phi\), and the fix adds the average gap seen in the data: \[\widehat\phi=\frac{N+1}{N}\max_kx_k=\max_kx_k+\frac{\max_kx_k}{N}=19.8+3.96=23.76 .\]

Figure 9: The five time stamps cut the axis into six gaps; the scaled maximum adds one average gap past the largest.

The puzzle, answered three ways

Figure 10: The range \(\phi=100\) of uniform data, estimated 40000 times by each of the three guesses.

The maximum can never exceed the truth, so ML is biased low, yet it has the smallest spread. Scaling by \((N+1)/N\) removes the bias for a little extra spread. Both leave the moment estimator far behind.

How good can it get?

Score and Fisher information

Score and Fisher information \[S(\mathbf X;\phi)=\frac{\partial}{\partial\phi}\ln f(\mathbf X;\phi),\qquad I(\phi)=\E{S(\mathbf X;\phi)^2}.\]

The score is the slope of the log-likelihood at \(\phi\). It has mean zero at the true parameter, and its spread, \(I(\phi)\), measures how sharply the likelihood depends on \(\phi\): the curvature of the likelihood we watched sharpen with \(N\), averaged over the data.

For an iid sample the scores add, and so does the information: \(I_N(\phi)=N\,I_1(\phi)\).

The Cramér–Rao bound

Cramér–Rao bound Every unbiased estimator satisfies \(\Var{\widehat\Phi}\ge 1/I(\phi)\).

Why. The error of an unbiased estimator is correlated with the score (their covariance is exactly \(1\)), and a correlation coefficient cannot exceed one: by Cauchy–Schwarz, \(1\le\Var{\widehat\Phi}\,I(\phi)\).

A floor under every unbiased estimator, however clever, and it falls like \(1/N\).

The floor, and who stands on it

Figure 11: Standard deviation of two estimators of a Gaussian mean against the Cramér–Rao floor \(\sigma/\sqrt{N}\).

For Gaussian data \(I_N=N/\sigma^2\): no unbiased estimator beats \(\sigma^2/N\), and the sample mean sits exactly on it. The median pays about 25% in spread.

The floor for a variance

For Gaussian data the information about \(\sigma^2\) is \(I=N/(2\sigma^4)\), so every unbiased estimator of the variance has \(\Var{\widehat\Sigma^2}\ge 2\sigma^4/N\).

Figure 12: Variance of the two variance estimators divided by the bound, against N.

The unbiased estimator never reaches the bound: it is a lower limit, not a promise. The ML curve sits below it, which is no contradiction, since the bound speaks only about unbiased estimators.

ML against the average

The center of three symmetric laws of equal variance. Left: the error of the average (the same in all three) and of maximum likelihood (mean, median and midrange). Right: their ratio.

The average cannot tell the three laws apart, because it never looks at the density. ML does: it is twice as good for Laplacian data, and for uniform data its error falls like \(1/N^2\) instead of \(1/N\).

What maximum likelihood actually promises

Maximum likelihood, as \(N\to\infty\)

  • Consistency: \(\widehat\phi_{\text{ML}}\to\phi\) under mild conditions.
  • Asymptotic normality: \(\sqrt N\,(\widehat\phi_{\text{ML}}-\phi)\to\Gauss(0,1/I_1(\phi))\).
  • Asymptotic efficiency: it reaches the Cramér–Rao floor.

All three are asymptotic. None of them says anything about \(N=12\), which is the case you usually have.

The puzzle beats the bound

The bound assumes the support of \(f_X(x;\phi)\) does not move with \(\phi\). The puzzle breaks exactly that: the data live on \([0,\phi]\), whose edge is the parameter, and the score is the constant \(-N/\phi\), which cannot have mean zero.

The scaled maximum \[\Var{\widehat\Phi}=\frac{\phi^2}{N(N+2)}:\] an error falling like \(1/N\) rather than \(1/\sqrt N\). An edge is located far more precisely than a center.

“The Cramér–Rao bound is the best possible” is a statement about unbiased estimators in regular models. The Gaussian mean is both; the range of a uniform is neither.

The puzzle, settled

estimator bias variance error falls like
twice the average (moments) \(0\) \(\phi^2/(3N)\) \(1/\sqrt N\)
largest value (ML) \(-\phi/(N+1)\) \(\approx\phi^2/N^2\) \(1/N\)
scaled maximum \(0\) \(\phi^2/(N(N+2))\) \(1/N\)

For the five time stamps: \(20.96\), \(19.8\), \(23.76\). Reading only the average threw away the information that sits at the edge, and no amount of cleverness with the average recovers it.

Recap

This week

  1. An estimator is a random variable, judged by its own distribution: bias and variance, which add up to the mean square error. Unbiased is not the same as better.
  1. Detection is estimation with two candidates, and the likelihood ratio is the optimal statistic. Maximum likelihood is the same comparison over all candidates, and the noise model chooses its loss.
  1. Fisher information sets a floor for every unbiased estimator in a regular model. It falls like \(1/N\), and for Gaussian data the sample mean sits exactly on it.