Statistical models, estimators and maximum likelihood
Heinrich Heine University Düsseldorf
In the data science process, the road from the data to a product (be it a report, a prediction or new and interesting data), we model the data. Strictly speaking we model partial aspects, sections of the data (just as the data themselves are only a section of reality).
In doing so we may be interested in how the data came about, but we may equally be driven by the wish to be able to say something particular about them, or to do something particular with them. So it helps to be clear about what kind of information one wants to coax out of the data, and then to tune the models to that.
Often several approaches are available for computing the same kind of information. The results may well differ, and frequently (in unsupervised learning) we cannot compare the computed results with the “right” result. All that is left then is to compare the information content of the models (to compute the entropy), to examine every model assumption for plausibility, and to develop general criteria for the quality of models. The last of these is what we now set about.
The classical approach – classical in the sense of historically oldest – begins by formalising the models and the aspects one wants to compute from the data with them.
One speaks of a statistical model, of a statistic, and of various estimators for a statistic which can then be compared with one another. One criterion is whether an estimator lands near the “right” result at least for very large samples. But hold on – if we do not know the right result, how can we say anything of the sort?
The solution is to restrict ourselves to those statistical models in which we can describe the rough structure of the right result for an estimator well enough that statements such as “in the limit this estimator estimates the expected value of that statistic on the data” become available after all. And then one can talk about how good the values look away from the limit, for somewhat smaller samples. Along the way we meet a notion that matters a great deal to data science and machine learning: the maximum likelihood principle.
A very concrete example first. Given data that come as a vector x of length n of real numbers (float), of which we know that they arose as a sample of a one-dimensional normally distributed random variable X with expected value μ(X) and variance σ2(X), we want to estimate the standard deviation σ(X). For this the books offer two different formulas, σ(x) and σ∗(x), which differ only in their denominator:
So the two formulas deliver noticeably different numbers – a good two per cent apart in the variance, and that at n=48. Which is the right one? And in passing: that we may replace μ(X) by mean(x) at all is something we have so far only taken to be plausible; the justification is the example “the sample mean is unbiased” in the section Unbiasedness below.
With these formulas one has to be a little careful when implementing them in practice – because what is μ?
In an application I do not know μ(X) and must therefore use μ(x). But then it turns out that the information in {xi−μ(x)}i=1n−1 suffices to compute xn−μ(x), since by the definition of μ(x) we have xn−μ(x)=∑i=1n−1(μ(x)−xi). In a sense, then, using μ(x) in place of μ(X) leaves us one degree of freedom fewer than n. We shall see in a moment how that affects the properties of these two estimators for σ(X).
Once statistical models have been defined formally, one can also talk very well about confidence intervals and hypothesis tests, which is what the chapter Statistical tests does. Confidence intervals extend the bare estimation of a statistic by the information on what margin of error one attaches to that estimate. Hypothesis tests extend it by arriving at decisions in the end. In discussing hypothesis tests it is unavoidable to speak also about the problematic notion of significance. But one thing at a time!
As a map for the definitions that follow – on the left what one talks about, on the right what it formally becomes:
in everyday terms
formally
a family of distributions from which we want to pick one
statistical model(X,Pθ:θ∈Θ)
the quantity we want to estimate (say μ or σ)
map τ:Θ→Σ
the sample we are holding in our hands
an element x∈X – or, as long as it has not been drawn yet, a random variable with values in X
the procedure that turns the sample into a number
statistic, or estimator, T:X→Σ
The sample space X here is not the space of a single measured value but the space of all samples: with n real measurements X=Rn, so a sample is a single point in a fairly large space.
The crucial move is in the last row. Because the sample is a random variable and the estimation procedure is a map on it, the result of estimating is again a random variable. That lets us speak of its expected value and its variance – and that is exactly what we need in order to be able to say at all what a good estimator is: bias, consistency and mean squared error are all formulated in this language.
Such an estimator therefore has the smallest spread around the value to be estimated among all unbiased estimators.
In general it is very hard to determine uniformly best unbiased estimators (in general there are none). Looking ahead: the Cramér–Rao inequality for regular statistical models bounds the variance of an estimator from below by the Fisher information (a quantity that can also be computed from the relative entropy), and so lets us recognise uniformly best estimators by the fact that they do not exceed this variance bound. For an unbiased estimator T of a real parameter θ it reads
where I(θ) is the Fisher information. An unbiased estimator that attains this bound is therefore a uniformly best estimator. For distributions from a so-called exponential family (in a certain sense a common generalisation of the normal distribution, the binomial distribution, the gamma distribution and so on), the uniformly best estimators can be described directly in this way.
For many models that matter in practice, though, there is no closed formula for a good estimator at all – the contaminated normal distribution is the example that still awaits us in the course. What one needs then is a principle that yields, instead of a formula, an optimisation problem whose solution can be approximated numerically. That is exactly what the maximum likelihood principle does, and the iterative procedure that goes with it is the EM algorithm.
So if we are given data x, the likelihood function for x expresses, for every parameter θ, how the probability density of Pθ comes out at the point x. If the density is large, then x is an observation that is probable under the parameter θ. If the density is small, then x is improbable under θ. As a reminder: if we take the hypothesis H=(θ is the true parameter ) and write D=x (for data), then P(D∣H)=Lx(θ)=fθ(x) is the likelihood (cf. Bayes’ theorem, version 3, in the chapter Covariance and dependence).
We have already worked out a first example of this without using the name: in the chapter
The most important discrete distributions we determined, for k successes
in n trials, the p under which that observation is most probable, and obtained
p^=nk. In the language of this chapter that is the maximum likelihood estimator
in the binomial model X={0,…,n}, Θ=[0,1], Pp=Bin(n,p).
Trick
Instead of maximising the likelihood of x over all possible θ, one can also take the logarithm of the likelihood, the so-called log-likelihoodlogρ(x,θ), and maximise that. Because the logarithm is strictly increasing, likelihood and log-likelihood attain their maxima in the same places.
If, for instance, ρ has the form eAeB (as in a 2-fold product model), then logρ has the form A+B and setting derivatives to 0 becomes a great deal easier. Even with this trick, however, no closed analytic solution can be found in general – which is where computer science gets to shine with approximation algorithms, such as the expectation maximization algorithm, which we take up later in the course.
That leads us to an obvious generalisation of the k-means procedure: we could allow more complicated covariance matrices and so push the likelihood up further. The problem that then arises, however, is that no closed form can be determined for the log-likelihood either, and that one has to think up a new algorithm for the estimation!