Regression
Regression
Lecture notes
Spring 2016
February 2016
2
Contents
1 Linear Regression 5
1.1 Introduction: underlying question . . . . . . . . . . . . . . . . . . 5
1.1.1 Examples and historical background . . . . . . . . . . . . 5
1.1.2 Linear model and examples . . . . . . . . . . . . . . . . . 7
1.2 Prerequisites for the linear model . . . . . . . . . . . . . . . . . . 12
1.3 The least squares estimator . . . . . . . . . . . . . . . . . . . . . 15
1.3.1 Normal equations . . . . . . . . . . . . . . . . . . . . . . . 15
1.3.2 Geometric interpretation . . . . . . . . . . . . . . . . . . . 17
1.3.3 Link to the MLE for the normal distribution . . . . . . . 19
1.3.4 Why not regress on each variable individually ? . . . . . . 19
1.4 Properties of LS estimation . . . . . . . . . . . . . . . . . . . . . 20
1.4.1 Moments without any normality assumptions . . . . . . . 21
1.4.2 Distribution under the assumption of normality . . . . . . 22
1.4.3 Asymptotic normality . . . . . . . . . . . . . . . . . . . . 23
1.5 Tests and confidence intervals . . . . . . . . . . . . . . . . . . . . 24
1.5.1 Basic test statistics . . . . . . . . . . . . . . . . . . . . . . 24
1.5.2 Confidence band for the entire hyperplane . . . . . . . . . 26
1.5.3 Comparison of nested models, analysis of variance . . . . 27
1.5.4 Coefficient of determination . . . . . . . . . . . . . . . . . 30
1.6 Simple linear regression . . . . . . . . . . . . . . . . . . . . . . . 31
1.6.1 Results for the special case of simple linear regression . . 31
1.6.2 Regression and correlation . . . . . . . . . . . . . . . . . . 32
1.6.3 Switching X and Y; regression to the mean . . . . . . . . 34
1.7 Residual analysis, verification of models . . . . . . . . . . . . . . 36
1.7.1 Normal plot . . . . . . . . . . . . . . . . . . . . . . . . . . 36
1.7.2 Tukey-Anscombe plot . . . . . . . . . . . . . . . . . . . . 39
1.7.3 Time series plot, Durbin-Watson test . . . . . . . . . . . . 40
1.7.4 Interior analysis . . . . . . . . . . . . . . . . . . . . . . . 41
1.7.5 Generalized least squares, weighted regression . . . . . . . 43
1.8 Model selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.8.1 Model selection using “stepwise regression” . . . . . . . . 45
1.8.2 Model selection criteria . . . . . . . . . . . . . . . . . . . 46
1.9 The Gauss-Markov theorem . . . . . . . . . . . . . . . . . . . . . 50
3
4 CONTENTS
B Literature 9
Chapter 1
Linear Regression
Before modern times a widely-held but short-sighted assumption was that vari-
ations in repeated measurement must be due to one measurement being entirely
correct and all others entirely wrong. If for example the position of a star
is measured five times and this yields five different results, it was thought that
the measurement had only been performed correctly once, and incorrectly on
the other four occasions.
This way of thinking only changed about 400 years ago, when the concept of a
“random error” was introduced. This new concept arose from the idea that
all measured data contain a small error that makes them deviate from the
truth, but that they all are approximately true. Thus stochastics was born.
This opened up the possibility of investigating approximate, stochastic relation-
ships between variables – which is the subject of this course.
The method of least squares (or LS for short) was published by Legendre in
1805. Gauss also discussed this method in a book published in 1809 – and there
mentioned that he had been using this method since 1795. This statement
cannot be proven, and so it is not clear who has the honour of having first
discovered least squares.
This method was originally used to solve problems of celestial mechanics, where
data were fit to orbits determined by theory.
Astronomical example (Ceres): On the basis of the Titius-Bode law (dis-
covered by Titius in 1766), which provides an empirical description of the pat-
tern of planetary distances from the Sun, it was thought that the space between
Mars and Jupiter must be inhabited by a further planet. On Jan 1st, 1801,
Giuseppe Piazzi found the missing body and named it Ceres. It is the largest
asteroid.
5
6 Linear Regression
Ceres moves quite rapidly and was soon lost once more. It subsequently was
Gauss who used the method of least squares to compute a sufficiently exact
orbit from the few available data, so that Ceres could be rediscovered.
Later on, this method was used in a much more general way, including in the
social sciences. Yule, for example, carried out an investigation in 1899 into
whether poor people were best served by being put into poorhouses or by being
supported in their usual surroundings. For this purpose he used the regression
equation
Here ∆ denotes the changes between two successive censuses, “Paup” is the
number of people receiving poor relief, “Out” is the ratio of people getting
poor relief outside of poorhouses to the number of people in poorhouses, “Old”
is the proportion of over-65s in the general population and “Pop” is the total
population. This regression equation was fitted using data from two censuses
for each of a number of administrative districts (so-called “unions”). The dis-
tricts had largely autonomous social policies. Yule formed 4 categories of such
“unions” (rural, mixed, urban and metropolitan), and for each category the
coefficients a, b, c and d were estimated separately. Thus the censuses of 1871
und 1881 yielded a estimated coefficient of b = 0.755 for metropolitan districts.
In other words, an increase in the variable Out goes hand in hand with an in-
crease in the number of poor people – even when other influential factors such
as “Old” are accounted for. This led Yule to the conclusion that keeping people
in their usual surroundings and supporting them there actually leads to even
more poverty.
This is not a conclusive argument, however. It has been shown that those
districts with more efficient administration also built more poorhouses at that
time. At the same time, efficient administration leads to a reduction in poverty.
i.e. the effects of efficient administration and of the establishment of poorhouses
cannot be separated. We call these two variables “confounded”. Other economic
factors are also potential confounders. Generally speaking, a lot of care must
be taken when attempting to conclude causality from an observed association.
In particular, we cannot draw conclusions about interventions (changes in the
variables) on the basis of the regression equation. For further discussion of this
point, I refer to D. Freedman’s article “From association to causation: Some
remarks on the history of statistics”, Statistical Science 14 (1999), 243-258,
from which the example above is taken.
Another (fictitious) example: is there a link between the number of storks and
the rate of human births? Some corresponding data are given in Figure 1.1.
The statistics show a highly significant connection between the number of storks
and the birth rate. From this one might wrongly conclude that babies are
brought by storks. (“Cause and effect, causal link”).
In this case the confounding variable is time. This happens quite often (meaningless
correlation of time series). In this example it is quite obvious that this asso-
1.1 Introduction: underlying question 7
ciation does not imply a causal relationship. However, if we look at the amount
of brutality in TV shows and the rate of violent crime, we are quite sure to find
a statistical link (both increase with time), and a causal relationship is possible
a priori – though such a relationship is not easy to prove!
Multiple regression:
Given: a single dependent variable (target variable) which up to
measurement errors (or random fluctuations) depends on several
“independent” or “explanatory” variables (or experimental conditions).
Wanted: the parameter values that describe this linear dependence,
and the error variance.
Yi = θ1 xi1 + . . . + θp xip + εi (i = 1, . . . , n)
Terminology:
• The numbers (Yi ; i = 1, . . . , n) form the vector y of realizations of the
dependent variable (also known as the “target variable” or “response”).
• The numbers (xij ; i = 1, . . . , n) form the vector x(j) of realizations of the
j-th independent (explanatory) variable (experimental condition)
(j = 1, . . . , p).
• The (xij ; j = 1, . . . , p) form the vector xi of explanatory variables (exper-
imental conditions) of the i-th observation (i = 1, . . . , n).
• The numbers (θj ; j = 1, . . . , p) form the unknown parameter vector θ.
• The numbers (εi ; i = 1, . . . , n) form the vector ε of (unknown) errors,
which we shall assume to be random.
8 Linear Regression
While the θj and εi are unknown quantities, all the xij and yi are known.
Yi = xTi θ + εi (i = 1, . . . , n)
Y = X × θ + ε
n×1 n×p p×1 n×1
The first explanatory variable is usually a constant, i.e. xi1 = 1 for all i. The
model thus contains an intercept. To give an interpretation to the parameter θ1
in such a case, we assume the errors εi to have mean zero. In other situations
such an assumption is also generally made.
We furthermore assume that there are more observations than covariates (p <
n) and that the matrix X has the maximum rank possible, p, i.e. that the p
columns of X are linearly independent. If this were not the case, the parameters
would not be identifiable (different choices of parameter may yield the same
model). Sometimes models with linear dependence in the columns are used all
the same, and the identifiability forced by auxiliary conditions.
Examples:
1
1
p = 1, X= , θ1 = µ.
..
.
1
1.1 Introduction: underlying question 9
Here the most common questions are “Is µ1 = µ2 plausible?”, and “How
large is their difference?”, respectively. From the introductory course,
we can already handle these using the 2–sample t-test or the 2–sample
Wilcoxon test.
Statistically speaking, the 2-sample model is the simplest one imaginable.
(In practice it is mostly simpler than the 1-sample (location) model, as
systematic and semi-systematic errors often cancel out.)
(3) One-way (simple) analysis of variance with k levels (groups)
This is a generalization of the previous example from 2 to k groups. In
this case, p = k, the parameters are the group means µj (1 ≤ j ≤ k)
and the matrix X looks similar to above. Another parametrization is also
commonly used, namely
µj = µ + α j ,
where µ is the overall mean and αj is the j-th group effect. In this setup,
the k + 1 parameters cannot all be determined and the columns of X are
linearly dependent. The identifiability
P of these parameters is forced by
introducing a condition such as αj = 0.
This type of model is treated at greater depth in the course Analysis of
Variance (“Angewandte Varianzanalyse und Versuchsplanung”).
(4) Regression through the origin: Yi = βxi + εi (i = 1, . . . n).
x1
x2
p = 1, X = . , θ1 = β.
..
xn
where ηi = exp(εi ). In other words, the errors on the original scale are
multiplicative instead of additive. When the dependence is of power
or exponential type, multiplicative errors are usually more plausible, as
then the error size is proportional to the scale of the target variables.
The physical expectation is that the tremor size should be inversely pro-
portional to the squared distance. In this case, we have a power model
with a known parameter β. Figure 1.4 plots the logarithmic tremor sizes
against the logarithmic distances for a fixed load size. They have an ap-
proximately linear relationship with an roughly constant variation. One
immediate question is whether or not the slope of the linear fit really is
−2, the value postulated by theoretical physical considerations. This will
be one of the questions we shall look into during this course.
Figure 1.4: Distance and tremor size for explosions with explosive loading
3.12. Logarithmic axes are used
• Good parameter estimates. These answer the question: How does the
response change when an explanatory variable changes?
For a linear model fit using least squares to be meaningful, we have to make
certain assumptions. These are also needed for the validity of the statistical
tests and confidence intervals we shall derive. Before we list these conditions
1.2 Prerequisites for the linear model 13
in descending order of importance, let us note that the model places no prereq-
uisites on the explanatory variables. These can be continuous or discrete, and
they may be transformed and combined in an arbitrary manner. Furthermore
there is no difference in principle between the deterministic fixing of the values
of explanatory variables by the experimenter, and their being realizations of
random variables themselves. The theory derived in the following sections will
always regard the explanatory variables as deterministic. That is to say: if
these variables are random, our statements are to be understood as conditional
ones given the values of the explanatory variables.
As we shall see later on, these assumptions can partly be checked statistically.
E [εi ] = 0 ∀i
E [εi εj ] = 0 ∀i, j (i 6= j)
If the errors are correlated, the least squares fit is still of some use, but
its precision is not what we think it is. The levels we obtain for tests,
and the confidence intervals we compute, are wrong. We will discuss this
in more detail later.
14 Linear Regression
E ε2i = σ 2
∀i
All measurements should have the same precision. (In particular, there
should be no “bad errors” with a much higher variance.) A constant error
variance can often be reached by a simple transformation of the target
variable. If the homoscedasticity assumption does not hold, the method
of least squares quickly becomes imprecise (compared to other methods).
This will also be discussed at greater depth later.
Thus least squares can nearly always be used if prediction is our only goal. Some
care must be taken in interpreting the parameters and specifying the precision.
1.3 The least squares estimator 15
Finally, here is an example where Assumption 3 is not true (and neither are
Assumptions 1 and 2). The dependent variable here is the number of live
births in Switzerland since 1930, and the explanatory variable is time (as well
as certain functions of time, if e.g. quadratic trends are also of interest).
As we see in Figure 1.5, the data on live births in Switzerland following World
War II have an approximately linear trend up to 1964. A closer look, though,
reveals that the data are not symmetrically distributed around the regression
line, but that they form “groups” on either side of it; successive maxima and
minima are about twenty years apart (one generation).
Furthermore, the years before 1964 are not “representative” for the following
years – that is, the model is no longer valid. It is generally quite dangerous
to extrapolate a fitted linear model to an area where no observations of the
explanatory variables are available.
We would like the “best possible” estimate of θ. The least squares estimate θ
b
is defined as the quantity that minimizes the L2 –norm of the error:
ky − X θk
b = min ky − Xθk.
θ
Thus we minimize the Euclidean distance of the error y − Xθ from the vector
zero.
(−2) X T (y − X θ)
b =0 ((p × 1) − dimensional zero vector),
These are the normal equations. We have p linear equations for p unknowns
(note that X T X is a p × p matrix). The entries of X T X are the scalar products
of the columns of X. Thus solving the normal equations is especially simple
when the columns x(j) of P X are orthogonal. Another interpretation can be
found by writing X X as ni=1 xi xTi : this way, we see that X T X is n times
T
we immediately obtain:
Pn Pn
i=1 yi x
ei yi
α
e=
b =y ; β = Pi=1
b
n .
n e2i
i=1 x
1.3 The least squares estimator 17
In a multiple linear regression setup that includes an intercept term (thus mak-
ing the corresponding column in X contain only the number 1), we can orthog-
onalize in a similar way:
X p
yi = α + θj x
eij .
j=2
b T X = 0.
(y − X θ)
To compute y
b , we can use the formula
y
b = Xθb = X(X T X)−1 X T y = P y and thus: y
b = Py
| {z }
=:P
QT = Q2 = Q, P Q = QP = 0 (0 as an n × n matrix), tr(Q) = n − p.
Assuming that the explanatory variables are given, the assumptions of our
model (independence and normality of the errors) imply that the conditional
density of y1 , ..., yn is
n p
2
Y 1 X
Ly,X (θ, σ ) = ϕ((yi − θj xij )/σ).
σ
i=1 j=1
This is not the estimator generally used, however. Instead, it is scaled to become
unbiased. We shall see that the correct scaling factor here is n/(n − p). In other
words, the estimator of error variance we shall use is
Pn
2 (yi − ybi )2
b = i=1
σ .
n−p
The following (artificial) example shows why multiple regression cannot simply
be replaced by several simple regression procedures.
Let there be 2 covariates x1 , x2 , and assume that we have the following obser-
vations:
x1 0 1 2 3 0 1 2 3
x2 −1 0 1 2 1 2 3 4
y 1 2 3 4 −1 0 1 2
20 Linear Regression
Left side of Fig. 1.7: We plot the values of y against the corresponding
values of the covariates x1 und x2 . Subsequently, we find a plane that fits these
8 points exactly (in three-dimensional space):
y = 2x1 − x2 σ 2 = 0)
(b
1 4
y = x2 + σ 2 = 1.72)
(b
9 3
Let us first take an intuitive look at the precision of the regression plane. We
assume a known linear model and simulate a random point cloud from this
model. This cloud of points we can now use to fit a regression plane using the
1.4 Properties of LS estimation 21
method of least squares. If we now take a second (or third, . . .) point cloud,
we will generally get a different estimated regression plane – even though the
underlying model, and thus the theoretical plane, are the same (cf. Fig. 1.8).
In other words, the parameter estimates and the fitted regression plane are
random ! Because of this, we do need some idea of their precision.
Figure 1.8: Three different estimated regression lines for the same underlying
model.
The next results do not require the errors εi to be normally distributed. The
assumptions in this section are the following:
E [ε] = 0
Usual model: Y = Xθ + ε with
Cov[ε] = E εεT = σ 2 In×n
Results:
h i
(i) E θb = θ, as
h i
b = E (X T X)−1 X T y = E (X T X)−1 X T (Xθ + ε) = θ + 0 = θ.
E θ
(ii) E [b
ε] = 0, E [b
y] = E [y] = Xθ.
(iii) Cov[ 2 T −1
h θ] = σ (X X)i , as
b
b − θ)T = E (X T X)−1 X T εεT X(X T X)−1 = σ 2 (X T X)−1 .
b − θ)(θ
E (θ
y] = Cov[P y] = σ 2 P P T = σ 2 P
(iv) Cov[b (because P is a projection matrix).
ε] = σ 2 Q
(v) Cov[b (similarly).
(vi) Cov[b
ε, y
b ] = 0, (as QP = 0).
The covariance matrices in (iv) and (v) are only positive definite. We can see
from (v) that the residuals ri = εbi are correlated – unlike the true errors – and
22 Linear Regression
Therefore Pn 2 b 2
2 i=1 ri ky − X θk
σ
b = =
n−p n−p
is an unbiased estimate of σ2, as we already claimed.
b2 . For this
Note that we cannot make any statements about the variance of σ
we would need to know the fourth moment of the errors εi .
(which can easily be checked, noting that the last n − p rows of AT X are all
identically equal to zero). Because of the orthogonality of A, we find that
n
X n
X n
X
εb2i = εb∗2
i = ε∗2
i .
i=1 i=1 i=p+1
From this the claim follows, as the orthogonality of A means that ε∗ also follow
a normal distribution N n (0, σ 2 In×n ).
The above results on the distribution of estimators are the key to subsequent
statements about uncertainty, i.e. confidence intervals or tests. One might
therefore ask how decisive the assumption of normal errors is. It has been seen
that the results are still approximately correct if the errors are not normally dis-
tributed. This is investigated mathematically by looking at the limit behaviour
of the distribution when the number of observations goes to infinity.
Consider the following situation: We have n data (y1 , x1 ), . . . , (yn , xn ) which
satisfy the linear model. Here each xi is a p-dimensional column vector (i.e. xTi
is the i-th row of X). We assume that the errors εi are i.i.d. but not necessarily
normally distributed, and look at the limit case n −→ ∞.
For the asymptotic approximation to hold, we need some weak conditions on
the explanatory variables xi :
• The smallest eigenvalue of X T X = ni=1 xi xTi , namely λmin,n , converges
P
to ∞.
• maxj Pjj = maxj xTj ( ni=1 xi xTi )−1 xj converges to zero.
P
The first condition states that increasing n always yields more information,
while the second condition prohibits any xj from dominating the others.
Theorem 1.4.1. If the errors εi are i.i.d. with mean 0 and variance σ 2 , and if
(xi ) satisfies the conditions just given, then the LS estimators θ
b are consistent
(for θ), and the distribution of
(X T X)1/2 (θ
b − θ)
where
an = X((X T X)−1/2 )T c.
We have a sum of n independent, but not identically distributed terms ani εi .
Furthermore, the distribution of these summands changes with n. This is pre-
cisely the situation for which Lindeberg’s Theorem was established (see the
introductory class for details). We have
n
X n
X
Var ani εi = σ 2 a2ni = σ 2 an T an = σ 2 cT c.
i=1 i=1
i=1
for all η > 0. As all εi have the same distribution and a finite second moment,
it follows that d→∞
E ε2i 1[|εi |>d] = E ε21 1[|ε1 |>d] −→ 0.
As i a2ni = 1 also holds, it suffices to show that maxi |ani | converges to zero.
P
From the Schwarz inequality, we obtain
Assume the linear model with ε ∼ N n (0, σ 2 In×n ). As seen in the last sec-
b exactly follows an N p (θ, σ 2 (X T X)−1 )–
tion, these assumptions imply that θ
distribution, and σb2 is independent of θ.b Some of the consequences of this
are:
1.5 Tests and confidence intervals 25
θb − θi
p i ∼ tn−p .
b ((X T X)−1 )ii
σ
ybi − E [yi ]
√ ∼ tn−p where pii := (P )ii
σ
b pii
yb − E [y0 ]
q 0 ∼ tn−p
b xT0 (X T X)−1 x0
σ
These facts allow us to carry out statistical tests in the usual way (using the
quantities on the left side as test statistics) and to compute confidence intervals
for individual parameters, for linear combinations of them or for the unknown
true location of the hyperplane at some x0 . Furthermore, statement (f) enables
the construction of prediction intervals for future observations.
We illustrate this by the tremor size example that we introduced earlier. Ta-
ble 1.1 shows the computer output when we take the logarithm of tremor size as
our response variable and the logarithms of distance and load size as explana-
tory variables.
The output
p contains the estimated coefficients as well as the residual standard
b ((X T X)−1 )ii and the results of tests of the null hypotheses θi = 0.
error σ
26 Linear Regression
Coefficients:
Value Std. Error t value Pr(> |t|)
(Intercept) 2.8323 0.2229 12.71 0.000
log10(dist) -1.5107 0.1111 -13.59 0.000
log10(ladung) 0.8083 0.3042 2.66 0.011
Residual standard error: 0.1529 on 45 degrees of freedom
Multiple R-Squared: 0.8048
F-statistic: 92.79 on 2 and 45 degrees of freedom
p-value 1.11e-16
The other numbers here will be explained in the subsequent sections. Now the
t distribution with 45 degrees of freedom is very close to the standard normal
distribution. Thus the numbers in Table 1.1 show us that the true coefficient
of the logarithm of distance is less than 2 (in absolute terms), while the true
coefficient of the logarithm of load size may well be 1.
We can also compute a 95% confidence set, for instance, in which the true
hyperplane lies. Before we do this, we will first mention an obvious strategy
which fails. For any point x0 (at which the fitted hyperplane has the expected
response value yb(x0 )), we can construct an interval around yb(x0 ) as above, inside
which we expect the value on the true hyperplane to lie with 95% confidence.
If we do this for each possible value of x0 , do we then get a 95% confidence set
for the true hyperplane?
There is a better way, and it is as follows: The Schwarz inequality for the scalar
product ha, bi = aT (X T X)−1 b implies that
simultaneously for all x0 . This gives us the simultaneous confidence set we are
looking for. Its shape is that of a hyperboloid, and it is the envelope of all
hyperplanes whose parameters are compatible with the data according to b).
Prerequisites:
“Basic hypothesis” H : y = Xθ + ε
(X : n × p, rank(X) = p, ε ∼ N n (0, σ 2 I)).
“Special null hypothesis” H0 : the above, and additionally Bθ = b
(where the dimensions of B are (p − q) × p,
and rank(B) = p − q < p).
Example:
1 0 0 ... 0 0 ... 0
0 1 0 ... 0 0 ... 0
B=
0 0 1 ... 0 0 ... 0 ,
b = 0.
... ... ... ... ... ... ... ...
0 0 0 ... 1 0 ... 0
This null hypothesis can be written in words as “The first p − q coefficients θi
are all zero.” We are testing whether the first p − q variables are superfluous
to the model.
By statement (c) of Section 1.5.1,
b − b)T (B(X T X)−1 B T )−1 (B θ
(B θ b − b)
σ2
(p − q)b
is a suitable test statistic for this null hypothesis. Under this hypothesis, its
distribution is Fp−q,n−p . However, we can use the following geometric argument
to obtain a different shape and interpretation of this test statistic.
We assume that b = 0 (this is not a significant restriction, as we can replace
the original observations by new ones y − Xθ, taking some θ that satisfies
Bθ = b). Then we can project y, first into the p–dimensional space spanned
by the columns of X, and from there into the q–dimensional subspace defined
by the additional condition Bθ = 0.
Let the corresponding sums of squares of the residuals (under H and H0 ) be
SSE and SSE0 .
We know that:
• SSE/(n − p) always is an unbiased estimator of σ 2 , assuming the basic
hypothesis H and the null hypothesis H0 .
• SSE and SSE0 − SSE are sums of squares in orthogonal subspaces, and
under the null hypothesis H0 , we know that (SSE0 − SSe )/(p − q) is
an unbiased estimate of σ 2 . If only the basic hypothesis H is true, the
expectation of this difference is greater than σ 2 .
28 Linear Regression
1 y
e
e
e SSe (n-p)-dim.
e
r
e
-e ŷ
Q %
Q %
Q
Q
Q SSe0 %
%
Q
Q (n-q)-dim. %
Q
Q %SSe0 − SSe
r % (p-q)-dim.
Q %
Q
Q
Q r %
QQ% ŷ(0)
s
.
Thus given H0 :
2
(SSE0 − SSE)/(p − q) b−y
y b (0) /(p − q)
= ∼ Fp−q,n−p
SSE/(n − p) b k2 /(n − p)
ky − y
and we can use the expression on the left side as a test statistic for H0 .
At first glance, the two test statistics we have just derived are different: having
the same distribution does not make them identical. However, the following
lemma shows that both these expressions are in fact identical.
Lemma 1.5.1. The least squares estimator θ b(0) under the supplementary con-
dition Bθ = b is
Furthermore,
b − b)T (B(X T X)−1 B T )−1 (B θ
SSE0 = SSE + (B θ b − b).
X T (y − X θ
b(0) ) + B T λ = 0, Bθ
b(0) = b.
1.5 Tests and confidence intervals 29
b(0) )T (y − X θ
(y − X θ b(0) ))T (X(θ
b−θ
b(0) ) = SSE + (X(θ b−θ
b(0) )).
The decomposition
2 2
b (0)
y−y b k2 + y
= ky − y b (0)
b−y
is also known as analysis of variance, and thus Table 1.2 is known as an Analysis
of Variance (ANOVA) table.
30 Linear Regression
One particularly special case of the preceding results is the following: testing
to see whether the response actually depends on the covariates x.
1 x12 . . . x1p 0 1 0 ... 0
1 ... ... ... 0 0 1 ... 0
X= ... ... ... ...
B= . . . . . . . . . . . . . . . (p−1)×p
1 . . . . . . xnp 0 0 0 ... 1
y y
0 y
Under the null hypothesis H0 : θ
b(0) = b (0) =
y =: y (n×1)
.. ..
. .
0 y
b (0) k2 = ky − yk2
SSE0 = ky − y
b k2 + kb
= ky − y y − yk2
We have already derived the least squares estimators. Here we merely give
explicit formulæ for the most important test statistics and confidence intervals:
Test of the null hypothesis β = β0 at level γ: Reject the null if
|βb − β0 |
√ > tn−2;1−γ/2 ,
σ
b/ SSX
where
n
X
SSX = (xi − x)2 .
i=1
Correspondingly, the confidence interval for β is
σ
βb ± tn−2;1−γ/2 · √
b
.
SSX
The confidence interval for the expectation of a new observation at x0 (i.e. the
value of the regression line at x0 ) is:
s
b 0 ± tn−2;1−γ/2 · σ 1 (x0 − x)2
α
b + βx b + .
n SSX
The confidence interval for the entire regression line (simultaneously for all x)
is s
p
b ± 2F2,n−2;1−γ · σ 1 (x − x)2
α
b + βx b + .
n SSX
Naturally, the simultaneous confidence interval is better than the individual
one. Finally, the prediction interval for a new observation at x0 :
s
b 0 ± tn−2;1−γ/2 · σ 1 (x0 − x)2
αb + βx b 1+ + .
n SSX
The prediction interval is wider than the confidence interval. All three intervals
have boundaries that form hyperbolae.
32 Linear Regression
The concept of correlation used to be applied more often than regression was.
Let Y and X be random variables, i.e. the data x1 , . . . , xn are no longer
considered to be fixed.
Definition 1.6.1. The correlation (“Pearson product moment correlation
coefficient’’) is defined as:
Cov(X, Y )
ρ = ρ(X, Y ) = p (if Var(X) 6= 0, Var(Y ) 6= 0)
Var(X) · Var(Y )
Properties of correlation:
(i) −1 ≤ ρ ≤ +1 (Schwarz inequality)
(ii) |ρ| = 1 ⇔ The joint distribution of X and Y is concentrated on a line
(and the sign of ρ matches the sign of this lines gradient).
(iii) If ρ = 0, X and Y are said to be uncorrelated.
(iv) ρ can be estimated by
Pn
i=1 (xi− x)(yi − y)
r = ρb = pPn Pn ,
2 2
i=1 (xi − x) · i=1 (yi − y)
and for this estimate ρb, we have:
• −1 ≤ ρb ≤ 1
• |b
ρ| = 1 ⇔ all the points lie on a single line
• sign (b
ρ) = sign (β)
b
In Figure 1.10, we can see some typical scatterplots using a variety of correlation
coefficients.
of the Xi with those of the Yi . As the sum of ranks (or of their squares) is fixed,
the formulæ can be simplified thus:
6 ni=1 Di2
P
rS = 1 − Di := Rg(Xi ) − Rg(Yi ).
n(n2 − 1)
Kendall’s rank correlation is defined as
Tk − Td
rK = 2 · ,
n(n − 1)
This measures the strength and direction of the linear dependence between X
and Y after accounting for the linear dependence of X and Y on Z.
If both X and Y are considered to be random, we can write the least squares
estimation line as follows:
σ
bY
y − y = ρb (x − x).
σ
bX
1.6 Simple linear regression 35
Since ρb is always less than 1 in absolute terms, the prediction for Y is always
closer to the mean than the corresponding value of X, if we measure distances in
terms of standard deviations. If for instance ρb is positive and our observation
of X lies e.g. 1 standard deviation above the mean, the prediction of the
corresponding value of Y will be less than one standard deviation above the
mean. In other words, we always predict a regression (return) to the mean; this
has given rise to the name “regression”.
This phenomenon is continually being rediscovered, and is often interpreted at
length in the framework of cultural pessimism. However, as our formulae show,
this phenomenon is a very general one that occurs continually and requires
no special interpretation. It lies in the very nature of prognoses that as more
observations are available in the middle, any prognosis tends towards the mean.
Thus such a regression to the mean is nothing special. This becomes even
clearer if we switch the roles of X and Y . Due to symmetry, the regression line
for X by Y looks like
σ
bX
x − x = ρb (y − y).
σ
bY
In other words, if we look back and ask what value of X led to Y being one
standard deviation above the mean, the answer will be “less than one standard
deviation”. Now we might be tempted to see this as a sign of progress rather
than regression!
Drawing both regression lines in the same plot, we can see how the gradients
σ
bY 1σ bY
ρb and
σ
bX ρb σ
bX
differ. These two regression lines are quite evidently not the same; instead, we
have the scissor-like gap shown in Figure 1.13).
36 Linear Regression
Residual analysis is the process of graphically (and some times also numerically)
analyzing the residuals, i.e. the error estimates
ri := εbi = yi − ybi ,
in order to verify the assumptions on the model after fitting it, and to develop
a better model.
1
u = Fn (x) = #{Xi ≤ x}.
n
This is a step function which approaches the true distribution function when n
becomes large (Lemma of Glivenko and Cantelli). In particular, we have
x−µ
Fn (x) −→ Φ( )
σ
if the Xi follow a normal distribution. Thus if we set
then we obtain
x−µ
z≈
σ
for sufficiently large n. In a normal plot, we plot x against z at selected points. If
Xi really does follow a normal distribution, the normal plot will roughly exhibit
a straight line whose intercept and slope are µ and σ, respectively. However,
the random fluctuations of the data do lead to some deviation away from an
exact line. We can get an idea of the size of such fluctuations by performing
simulations – see Figure 1.14.
1.7 Residual analysis, verification of models 37
There is also a formal test of normality based on the normal plot, the “Shapiro-
Wilks test”. It essentially measures the correlation of the point cloud seen in
the normal plot.
38 Linear Regression
We have so far not paid any attention to the errors εi while performing regres-
sion. However, √ we can use the normal plot of the residuals εbi or the standardized
residuals εbi / 1 − Pii . Recall that the residuals εbi neither have constant vari-
ance, nor are they uncorrelated. Standardizing makes their variance constant
again, though this effect is usually negligible.
In summary: the normal plot checks the normality of the residuals against
possible skewness, heavy- (or short-)tailedness, outliers and other peculiarities.
1.7 Residual analysis, verification of models 39
The Tukey-Anscombe P plot is a plot of the residuals against the fitted values ybi .
We always have ri ybi = 0, i.e. the Tukey-Anscombe plot always has sample
correlation zero. If this plot exhibits a non-linear structure, this is an indication
that the model assumptions are broken. If the residuals were plotted against
the yi , their correlation would make any interpretation more difficult.
The ideal look of a Tukey-Anscombe plot is shown in Figure 1.17. One frequent
deviation from the assumption of constant error variance is a variance that
increases as the target variable does. The effect of this on the Tukey-Anscombe
plot can be seen in Figure 1.18 a)–c). If the Tukey-Anscombe plot contains
some structure in the form of a “trend”, this is an indication that the regression
function has not been specified correctly (i.e. the mean error is not zero.) Figure
1.18d is a typical example of a case in which a quadratic term is most likely
missing.
Figure 1.17: The Tukey-Anscombe Plot for an example in which the model
assumptions hold true.
If the Tukey-Anscombe plot shows some sort of connection between the error
variance and ybi or the variables in x, the target variables should be transformed
or a “weighted regression” performed (see Section 1.7.5). If the spread of the
errors increases linearly with the fitted values, a logarithmic transformation will
stabilize the variance; and if the error spread is proportional to the square root
of the fitted values, taking the square root of the target variable stabilizes the
variance. (This can be shown using Taylor expansions.)
40 Linear Regression
If the errors are dependent, the levels of the tests and confidence intervals are
no longer correct. This can be seen quite easily: If ε ∼ N n (0, Σ), a simple
calculation shows that
b ∼ N p (θ, (X T X)−1 (X T ΣX)(X T X)−1 ).
θ
The size of the correlation effects between the errors also depends on the co-
variates X and on the shape of the covariance matrix Σ. In many cases, this
effect is considerable.
We cannot get far without making some assumptions about the dependence
structure: even if we knew the errors εi , we cannot estimate the n(n + 1)/2
entries of the covariance matrix from n data without some extra information.
If the observations form a time series, their covariance often is a (usually mono-
tonely decreasing) function of the time between observations. Dependence of
this type can be detected by plotting the residuals ri against the observation
times ti . Where these are unknown, the position k(i) of the observation in the
series may be used instead.
If the points vary randomly around the horizontal axis in the time series plot,
everything is fine. However, if adjacent ri are similar, this indicates that the
errors may be serially correlated. Sometimes we even observe a jump in the
level of the residuals. In such a case, the model has evidently changed suddenly
at a particular point in time.
It is possible to test independence against an alternative of serial correlation.
Two such tests are:
(i) The run test, which counts the number of continuous sub-sequences
(“runs”) in which the residuals have identical signs. When independence
is assumed, there should not be too many or too few runs.
(ii) The Durbin-Watson test, which uses the test statistic
Pn−1
(ri+1 − ri )2
T = i=1Pn 2 .
i=1 ri
1.7 Residual analysis, verification of models 41
y6
c
c y32 c
s
c y34
c y3. sc y
33
c c
c c y31 s Replicates
s
c c
c c Data
c point yij
c Near replicates s Mean yi.
-
x2 x1 x6 x3 x4 x5 x
Figure 1.19: Replicates
where εij i.i.d. ∼ N (0, σ 2 ). The sample size is n = ki=1 ni . We can compare
P
this model to the larger model where Y and X are connected by an arbitrary
function f . Introducing the quantities E [Yij ] = f (xi ) = µi as independent
parameters, we have:
Yij = µi + εij (i = 1, . . . , k; j = 1, . . . , ni ).
The least squares estimate of µi is simply the (arithmetic) mean of the obser-
vations at xi :
Xni
µ
bi = yi. = yij /ni .
j=1
Thus we have two nested models and can perform the usual F -test. The or-
thogonal decomposition for the ANOVA table is:
X ni
k X X ni
k X k
X
2 2
(yij − ybi ) = (yij − yi· ) + ni (yi· − ybi )2
i=1 j=1 i=1 j=1
| {z } |i=1 {z }
(1) (2)
• (1) measures the random error, and has ki=1 (ni − 1) = n − k degrees of
P
freedom
• (2) measures the random error and the “lack of fit”, and has k − p degrees
of freedom
If we have two near replicates, we can correct them by moving each of them
parallel to the regression line so that they both have the average of their co-
variates x (cf. Figure 1.20). This then gives us two replicates. When p is large,
however, it can be hard to find near replicates.
1.7 Residual analysis, verification of models 43
g
w9
: w
g
Then we have
In other words, the “tilde model” obtained by the linear transformation using
A−1 satisfies the conditions for the standard multiple regression model we al-
ready know. The key point here is that A is invertible (which is ensured by the
positive definiteness of Σ).
Applying the known theory to the “tilde model”:
For the “tilde model”, we estimate θ using least squares, that is, we minimize
This is the same as performing a least squares estimation for the original data
(y, X) using a different scalar product. The estimate obtained by this is
b = (X̃ T X̃)−1 X̃ T ỹ = (X T Σ−1 X)−1 X T Σ−1 y,
θ
Figure 1.21: Previous model (q-dimensional) and new enclosing model ((q +1)-
dimensional, i.e. with one more variable).
yi = θ1 + θ2 xi2 + . . . + θp xip + εi
Now the variables are taken out of the model one by one (and “stepwise”).
At each step, we remove the variable whose F –value in the comparative
test is smallest, and continue until all such F are significant.
Discussion of stepwise regression:
• “Backward” selection requires more effort, and under some circumstances
it may even incur more numerical problems (if e.g. p ≥ n, we cannot even
carry out this procedure). However, it gives us the greatest certainty of
finding a good model.
• “Forward” and “backward” selection are often combined (using two dif-
ferent significance levels, so as to avoid entering a loop of removing and
including the same x(j) ).
• The stopping rule does not necessarily gives us a “best” model according
to the criteria we shall discuss in the next section.
• The sequence of included or removed variables should not be regarded as
some kind of rank of the importance of the variables.
• “Forward” and “backward” selection may yield entirely different solutions.
Example of this last point: We choose three explanatory variables such that
• X1 and X2 each have only very little correlation with Y , but Y is (almost)
a linear combination of X1 and X2 .
• X3 correlates strongly with Y .
Forward selection will first select X3 and then stop (or perhaps choose {X1 , X3 }
or {X2 , X3 }), while backward selection will choose {X1 , X2 } and then stop.
Mallows’ Cp statistic
bM = ((X M )T X M )−1 (X M )T y
θ
Figure 1.22: Theoretical best linear fit (dashed line) for a model that is actually
quadratic (solid line).
= X M ((X M )T X M )−1 (X M )T µ,
M
E y b
yM ) = σ 2 X M ((X M )T X M )−1 (X M )T ,
Cov(b
i.e. the random fluctuations are as if the model were true. In particular, we
have
Xn
yiM ) = σ 2 tr(X M ((X M )T X M )−1 (X M )T ) = |M |σ 2 .
Var(b
i=1
The more variables we include in our model, the greater the sum of variances
of ybiM .
48 Linear Regression
Our quality measure for a model is the sum of mean squared errors ybiM from
the true values µi :
n
M X
y − µ||2 =
M
yi − µi )2 .
SM SE = SM SE(M ) = E ||b E (b
i=1
Now for any random variable Z and each constant c , we know that
and thus
n
X n
X n
X
yiM ) ybiM 2 2
(E ybiM − µi )2 .
SM SE = Var(b + (E − µi ) = |M |σ +
i=1 i=1 i=1
The first of these summands is small for models containing few variables, while
the second is small for models containing many variables. SM SE is often scaled
by σ 2 , so that
SM SE(M )
Γp (M ) =
σ2
becomes the term of interest. The inequality Γp (M ) ≥ |M | always holds, with
equality being attained exactly when the model M is bias-free (but potentially
contains superfluous terms).
We can also regard ybiM as a prediction for a new observation Yn+i = µi + εn+i .
In this case the sum of prediction square errors is
n
X n n
X X
E (Yn+i − ybiM )2 = E (Yn+i − µi )2 +
M
yi − µi )2 = nσ 2 +SM SE.
SP SE = E (b
i=1 i=1 i=1
(To be more precise, we should actually refer to this as “sum of mean squared
prediction errors”.)
Thus minimizing SM SE or Γp or SP SE always leads to the same model.
However, we cannot compute any of these quantities without knowledge of σ
and µ. One naive estimate of SP SE is the sum of squared errors
n
X
b M ||2 =
SSE(M ) = ||y − y (yi − ybiM )2 ,
i=1
i.e. the criterion used in least squares estimation. However, this quantity
always decreases when additional variables are included in the model, and it
underestimates SP SE:
n
X n
X
b M ||2 = Var(yi − ybiM ) + (E [yi ] − E ybiM )2
E ||y − y
i=1 i=1
n
X
= (n − |M |)σ 2 + (E [yi ] − µi )2 = SP SE(M ) − 2|M |σ 2 .
i=1
1.8 Model selection 49
SSE(M )
Cp (M ) := − n + 2|M |,
b2
σ
as an estimate of Γp . Random fluctuations mean that Cp can become smaller
than |M | (or even negative), unlike Γp .
σ 2 (M )) + α |M |
AIC(α) = n log(b
The vector aKQ = X(X T X)−1 c from the least-squares estimate is a spe-
cial solution of X T a = c. Furthermore, aKQ is orthogonal to all solutions
ah of the homogeneous system of linear equations, X T a = 0, as aKQ T ah =
cT (X T X)−1 X T ah = 0. As Cov[Y] = σ 2 I, we thus can see that
We regard the following general situation: Let (fη (y)) be a parametric family
of strictly positive densities in Rn . Let η be a variable parameter with values
in an open subset of Rk , and let fη (y) be differentiable wrt η. Our parameter
of interest is g(η), where g is an arbitrary real-valued function of η. Then we
have
Theorem 1.9.3 (Cramér-Rao). If T (y) is an arbitrary unbiased estimate of
g(η), i.e.
Eη [T (y)] = g(η) ∀η,
∂g T ∂g
Varη (T (y)) ≥ I(η)−1 ,
∂η ∂η
52 Linear Regression
η = (σ 2 , θ T )T
and
g(η) = cT θ.
First we examine the effect that omitting or adding observations has on the
least squares estimate. The following lemma of Gauss will be useful here:
Lemma 2.1.1. Let A be an invertible matrix of dimension p × p, and let a and
b be two vectors of dimension p for which bT A−1 a 6= −1. Then A + abT is
also invertible, and we find that
1
(A − abT )−1 = A−1 + A−1 abT A−1 .
1− bT A−1 a
53
54 Nonlinear and nonparametric methods
Proof: exercise.
We denote by θb(−i) the least squares estimate when the i-th observation is
omitted, and we furthermore use the shorthand notation
n
X n
X
T
A=X X= xj xTj , c=X y= T
yj xTj .
j=1 j=1
b(−i) = (A − xi xT )−1 (c − yi xi )
θ i
1
= A−1 c − yi A−1 xi + A−1 xi xTi A−1 (c − yi xi )
1 − xTi A−1 xi
b − yi A−1 xi (1 + xTi A−1 xi 1
= θ )+ xTi θA−1 xi ,
1 − xTi A−1 xi 1− xTi A−1 xi
and thus
b(−i) − θ 1
θ b = − (X T X)−1 xi (yi − xTi θ)
b
1 − xTi (X T X)−1 xi
ri
= − (X T X)−1 xi .
1 − Pii
We see that the influence of the i-th observation depends on the i-th residual and
also on the diagonal entry Pii in the “hat matrix” (when using all observations,
including the i-th). Thus a plot of the residuals ri against the Pii is often used
to detect influential observations.
The difference of the parameter estimates is somewhat difficult to interpret, as
it is a whole vector that moreover depends on how the covariates are scaled.
One scalar invariant can be obtained by computing the length of θb(−i) − θ
b with
respect to the metric defined by the estimated covariance matrix of θ:
b
(−i) (−i)
(θ
b b T (X T X)(θ
− θ) b − θ)
b 1 ri2 Pii
Di = 2
= 2
.
pb
σ pσb (1 − Pii ) 1 − Pii
1
∆θ
b= (X T X)−1 x(y − xT θ).
b
1+ xT (X T X)−1 x
We see that the least squares estimate can be changed arbitrarily much by a sin-
gle new observation – in other words, the least squares estimator is not robust.
2.1 Robust methods 55
Moreover, this effect depends quite strongly on the location of the new obser-
vation. This formula can be made a little clearer if we assume that the xi are
chosen randomly and are i.i.d. . We then obtain the first-order approximation
1
(E xi xTi )−1 x(y − xT θ)
b∼
∆θ
n
for n → ∞.
The discovery – and subsequent special treatment – of influential observations
using Cook’s distance does have two drawbacks, however: First, the effect of
omitting two or more observations is not merely the sum of the individual effects
(as one influential observation can mask others). Secondly, omitting influential
observations leads to question marks over the validity of tests and confidence
intervals based on the remaining data.
The reason for the large influence that individual observations can have on
the least squares estimate is that large residuals have a high weight when a
quadratic criterion is being used. To avoid this, we can instead look at the L1
estimator:
Xn
θ = arg min
b |yi − xTi θ|.
θ
i=1
Historically speaking, this method is even older than least squares: it was
suggested and discussed by Boscovich in 1760 and by Laplace in 1789 !
In the location model, i.e. when p = 1 and xi ≡ 1, the solution is the median of
the data, an estimator which for normally distributed data is substantially less
precise than the arithmetic mean (i.e. the least squares estimator): to reach
the same precision, the median requires 50% more observations.
One compromise between minimizing the L2 distance and minimizing the L1
distance is given by Huber regression:
n
X
θ
b = arg min ρc (yi − xTi θ),
θ
i=1
where
1 c
ρc (u) = u2 (|u| ≤ c), ρc (u) = c(|u| − ) (|u| ≥ c),
2 2
cf. Figure 2.1. Choosing c = 0 leads to L1 regression. If we compute derivatives
and set them to zero, we obtain the equations
n
X
ψc (yi − xTi θ)xi = 0,
i=1
Figure 2.1: The Huber function and its derivative for various values of c
Up to a constant factor, this covariance matrix is the same for least squares.
When c lies in the interval [1, 1.5], this factor is much less than 1 for heavy-
tailed distributions and only slightly larger than 1 for the normal distribution.
When comparing numerical estimates, however, we should remember that for
non-normal errors εi , the parameter σ is no longer the error standard deviation,
but the solution of
E [χ(εi /σ)] = 0.
This asymptotic approximation is also the basis of tests and confidence intervals,
whose details we omit here.
Unfortunately Huber regression does not solve all the problems we have with
influential observations. The exact effect of adding or omitting an observation
can no longer be specified. We can, however, approximate the difference in the
estimator caused by the addition of an observation at (x, y) by
1 y − xT θ
(E xi xTi )−1 x ψc (
b∼
∆θ )σ.
nP [|εi | ≤ cσ] σ
Thus the influence of large values of y is bounded when x is fixed, but by varying
x we can nonetheless increase this influence arbitrarily. More refined methods
lacking this weakness will be discussed in the next two sections.
Huber regression is frequently replaced by estimators that assume ψ to be
an odd function and χ an even function. Such estimators are known as M -
estimators. Particularly popular choices of ψ include those that converge to
zero for |r| large, as they then remove large outliers entirely. However, this
usually comes at the price of non-unique solutions to the defining equations.
The solution actually found then depends on the algorithm – and especially on
the choice of starting value.
and
1
η(x, r) = ψc ((||Ax||)r) (Schweppe).
||Ax||
58 Nonlinear and nonparametric methods
The matrix A is to be chosen in such a way that ||Ax|| expresses the deviation
of x from the set of covariates (xi )1≤i≤n . This can be achieved e.g. by setting
We can obtain estimators whose breaking point does not depend on the dimen-
sion by replacing the arithmetic mean by the median in
n n
X 1X
arg min (yi − xTi θ)2 = arg min (yi − xTi θ)2
θ θ n
i=1 i=1
to obtain
b = arg min median((yi − xT θ)2 )
θ i
θ
Figure 2.2: Least median of squares for simple regression. On the left, two
lines with a band containing 50% of the observations. The intercept is chosen so
as to minimize the band’s diameter along the y-axis. On the right, the diameter
of the band as a function of its slope.
search the entire space to find the global minimum, and this quickly becomes
too costly as we move to higher dimensions. In general, stochastic algorithms
are used to select p + 1 data points at random, fit a plane through them and
then compute the value of the target function for the corresponding θ.
One further drawback of this method is its lack of efficiency in the normal case:
the estimator then only converges at the rate n−1/3 . A better convergence
rate can be obtained e.g. by replacing the median by a truncated mean of the
((yi − xTi θ)2 ), omitting the αn (for α < 0.5) largest squared residuals. Usually
this estimator is used as the starting point from which to perform a Newton
iteration to solve the estimator equations for an M -estimator using a function
ψ that converges to zero. The result is then called the M M -estimator.
Developing robust regression estimators that exhibit good statistical and algo-
rithmic properties is still an on-going topic for research.
yi = f (xi , θ) + εi .
Many applied problems are of this type, and the shape of f usually follows
from the theory of the science in which a particular application arises. As an
example, the description of the cumulative oxygen usage y of microorganisms
in samples of river water as a function of incubation time x is usually performed
by the model
f (x, θ) = θ1 (1 − exp(−θ2 x)).
Thus the parameter θ1 is the saturation point, and θ1 · θ2 is the slope at x = 0.
Some sample data and a possible regression function are shown in Figure 2.3.
Figure 2.3: Oxygen usage data as a function of incubation time (left), and a
typical regression function (right).
θ
b = arg min S(θ),
θ
where
n
X
S(θ) = (yi − f (xi , θ))2 .
i=1
This carries the following geometric interpretation: If we vary θ, the points
(f (x1 , θ), . . . , f (xn , θ))T describe a p-dimensional curved surface in Rn , the so-
2.2 Nonlinear least squares 61
called response surface. We now seek the point on the response surface that is
closest to the observation (y1 , . . . , yn )T .
The solution does not generally have a closed form, and thus iterative meth-
ods (Gauss-Newton, Levenberg-Marquardt) are used. In practice, having good
starting values is crucial.
The error variance σ 2 can be estimated in a way similar to that for linear
regression:
n
1 X
b2 =
σ b 2.
(yi − f (xi , θ))
n−p
i=1
where T
∂
a(θ)i = f (xi , θ); j = 1, . . . p .
∂θ j
This means that we approximately have a linear model with explanatory vari-
ables a(θ 0 )i near the true parameter. Furthermore, it can be shown that (under
certain technical conditions) the distribution of θ
b is asymptotically the same as
in the approximating model, i.e.
b asymptotically
θ ∼ N (θ 0 , σ 2 (A(θ 0 )T A(θ 0 ))−1 ).
62 Nonlinear and nonparametric methods
In a similar way to the F test used in linear regression, we can test two nested
models by means of the differences in sums of squared deviations. To test the
null hypothesis Bθ = b, we also need the least squares estimate under the null
hypothesis:
θ
b0 = arg min S(θ).
θ;Bθ=b
b0 ) − S(θ))/q
(S(θ b
T = ,
S(θ)/(n
b − p)
where q denotes the rank of B. In the linear model, this statistic was identical
to the one computed from joint normal distribution of θ b and had an Fq,n−p
distribution under the null hypothesis. In the nonlinear setup, these two statis-
tics differ, and they are only approximately F distributed. This approximation,
however, is often significantly better the the normal approximation of θ.
b
In particular, we can use this to test the null hypothesis θk = θk∗ for any arbitrary
but fixed value of θk∗ . The test statistic then becomes
(−k) (−k)
S(θ
b ) − S(θ)
b S(θ
b ) − S(θ)
b
Tk (θk∗ ) = = ,
S(θ)/(n
b − p) b2
σ
where
b(−k) = θ
θ b(−k) (θ∗ ) = arg min S(θ).
k ∗ θ;θk =θk
(Thus θ b(−k) is the least squares estimate under the null hypothesis, i.e. it is
equal to θb0 in the above notation). Since an F distribution with one degree
of freedom in the denominator is simply the distribution of the square of a
t-distributed variable, we can also regard the test statistic
sign(θk∗ − θbk )
q
τk (θk∗ ) = b(−k) ) − S(θ).
S(θ b
σ
b
2.2 Nonlinear least squares 63
Figure 2.5: Contours and profile traces for the examples of reaction speed
(left) and oxygen use (right). The underlying data are shown in Figures 2.4
and 2.3.
Once p > 2, it is much more difficult to visualize the effect of nonlinearities and
of the dependence between the parameters. We could in principle compute the
64 Nonlinear and nonparametric methods
min S(θ)
θ;θj =θj∗ ,θk =θk∗
for all pairs (j, k), but this is often too expensive computationally. Instead,
(−k)
we can at least plot pairs of profile traces, plotting θbj (θk∗ ) against θk∗ and
(−j)
θb (θ∗ ) against θ∗ for all j < k. The curvature of these profile traces indicates
k j j
the extent of nonlinearity, while their angle shows the level of dependence be-
tween the corresponding parameter estimates. Furthermore, the profile traces
once more intersect the contours of the profile likelihood at points where the
tangents are horizontal or vertical, respectively. This gives us an impression of
where the contour lines should be.
(if the covariates xi are also random, the LHS contains conditional probabilities
given xi ). Solving for Pθ [Yi = 1] gives us
exp(xTi θ)
Pθ [Yi = 1] = = P [U ≥ −xTi θ],
1 + exp(xTi θ)
Zi = xTi θ + εi .
The parameters in such a model are nearly always estimated using maximum
likelihood. It is easy to see that for any y ∈ {0, 1}, we have
Pθ [Yi = 1] y
Pθ [Yi = y] = Pθ [Yi = 0] = exp(y · xTi θ − log(1 + exp(xTi θ))).
Pθ [Yi = 0]
These equations are generally solved numerically using iterative methods. If the
P response values (yij ; 1 ≤ j ≤ ni ),
experimental condition xi has several observed
then `(θ) only depends on their sum yi+ = j yij and the total ni .
Confidence intervals and tests in this model depend on the asymptotic normal
approximation
b asymptotically
θ ∼ N (θ, V (θ)).
The asymptotic covariance matrix V (θ) of θ
b is the inverse of the Fisher infor-
mation (cf. Section 1.9 or Mathematical Statistics):
n n
−1
X X exp(xTi θ)
xi xTi E 2
xi xTi
V (θ) = I(θ) = (yi − Pθ [Yi = 1]) = .
i=1 i=1
(1 + exp(xTi θ))2
Comparisons of two nested models with dimensions p and q < p are possible by
using double the log-likelihood quotient
(p)
2(`(θ
b b(q) )),
) − `(θ
R
(which can be seen by taking the derivative of pβ (y)dy = 1 with respect
to β and switching the integration and differentiation steps). Many common
distributions take on the form of such an exponential family, including the
normal, binomial and Poisson distributions. For the normal distribution, we
have
µ µ2 y2
p(y) = exp(y 2 − 2 − 2 ).
σ 2σ 2σ
Thus if σ is known, we have an exponential family with parameters
µ 1
β= , c(β) = − σ 2 β 2 .
σ2 2
The binomial(n, p) distribution can be written as
y
p n n
p(y) = (1 − p) .
1−p y
This is an exponential family with
p
β = log , c(β) = −n log(1 + eβ ).
1−p
g(µ(βi )) = xTi θ,
and denote its density by f . Then the failure rate (also known as hazard or
risk function) is defined as
1 f (t) d
λ(t) = lim P [t ≤ T ≤ t + h|T ≥ t] = = − log(1 − F (t)).
h→0 h 1 − F (t) dt
The Cox model now postulates that the shape of the i-th failure rate as a
function of the explanatory variables xi is
where λ0 is a base rate. Of course this model does not allow an intercept to be
present, as a constant could be absorbed into λ0 . Raising the j-th component
of the explanatory variables by one unit leads to multiplying the failure rate
by the factor exp(θ j ) (homogeneously for all times). Because of this property,
this model is also known as “proportional hazard model”. It is easy to see that
any strictly monotonous and differentiable transformation of the survival times
transforms a Cox model into another Cox model with the same parameters and
a different λ0 . If λ0 is not specified, this merely means that the choice of a
timescale remains open.
The base rate λ0 naturally appears in the likelihood function, too, which means
that we cannot simply employ the maximum likelihood estimator. We shall
instead estimate the parameter θ by means of the so-called partial likelihood,
defined as
n
Y exp(xTi θ)
P T
.
i=1 j;tj ≥ti exp(xj θ)
The i-th factor is the conditional probability of failure for the i-th observed
unit in the interval [ti , ti + dt), given the failure of one of the units that was still
working just before time ti . Thus the only information on failure times used is
the order in which the failures occur.
Nearly all data of this type suffer from the added complication of censored ob-
servations, whose failure times Ti are not known exactly, but it is only known
that they are greater that some observed censoring time Ci . The reasons for this
include the termination of the study before the failure of all units, or patients
moving away or dying of other causes. In such situations the partial likelihood
can be defined in a similar way: We compute the product over all uncensored
observations, but in the denominator, we only add up the uncensored observa-
tions with tj ≥ ti and the censored observations with cj ≥ ti .
Once again, tests and confidence intervals depend on asymptotic considerations
that we shall not elaborate here.
68 Nonlinear and nonparametric methods
Over the past 20-30 years much attention has been focused on procedures that
make no parametric assumptions about the shape of f in the model
yi = f (xi ) + εi ,
f (x) = E [Yi | Xi = x] .
holds (as long as the second moments do in fact exist). This means that f (Xi )
is the best prediction of Yi from Xi in terms of mean squared error. The
conditional error variance
Kernel estimators:
As an estimate of f (x), we take the weighted mean of the yi in such a way that
the weight of yi is monotonely decreasing in the distance |x − xi |. The weights
are determined by a so-called kernel K and a bandwidth h > 0. A kernel is a
probability density which is symmetric around 0 and either has support [−1, 1]
or is very rapidly decreasing (as is e.g. the normal density). There are two
versions that differ considerably in the stochastic case. The Nadaraya-Watson
version is defined as
Pn
yi K((x − xi )/h)
f (x) = Pi=1
b n .
i=1 K((x − xi )/h)
2.5 Nonparametric regression 69
and we define s0 = −∞, si = (xi + xi+1 )/2 for 0 < i < n and sn = +∞. Our
estimate is then
n Z si
X 1
f (x) =
b yi K((x − u)/h)du.
si−1 h
i=1
The differences between these two estimators are quite important if the the
covariates xi are distributed unevenly, as we can see in Figure 2.6. We can
see that the Gasser-Müller version gives higher weights to observations whose
corresponding xi have an isolated location.
In both versions, the bandwidth h regulates the smoothness of fb: The larger
h is chosen to be, the smoother the estimate, but the less it can adapt to the
data.
If the covariates xi are chosen at random, the number of observations having a
significantly non-zero weight can vary quite strongly as x varies. For the first
estimator (Nadaraya-Watson), there may even be none of them. To avoid such
an occurrence, we can choose a variable bandwidth, e.g. to fix the number of
observations for which x − h ≤ xi ≤ x + h. The latter procedure leads to a
so-called nearest neighbour estimator.
Kernel estimators especially struggle to estimate f at the fringes, i.e. for x < h
and x > 1 − h. As for such points the averaged observations nearly all lie on
one side of x, systematic errors can occur.
70 Nonlinear and nonparametric methods
Smoothing splines:
The first term, a sum over i, indicates the goodness of fit of f to the observa-
tions. The second term, the L2 norm of the second derivative, measures the
smoothness of f , and the parameter λ regulates the compromise that governs
the trade-off of the opposite aims of making both terms small simultaneously.
It can be shown that the solution of the minimization problem is a cubical spline
with nodes at the xi , and that this solution is furthermore linear on the fringe
intervals [0, x1 ] and [xn , 1]. If we take λ → 0, we obtain the spline that just
interpolates the data, and for λ → ∞ we obtain the least squares line. Thus
the role of λ corresponds to that of the bandwidth h.
To compute the smoothing spline,we choose a basis of the vector space of splines
with nodes xi . Computing the coefficients of the solution with respect to this
basis then leads to minimization of a quadratic function. If we are applying a
numerically stable and fast procedure, a good choice of basis is crucial. Here
the so-called B-splines have a good track record.
if we look at the bias and variance of such an estimator. We can show that for
local polynomials with odd p,
h i
E fb(x) − f (x) ∼ const(K, p) hp+1 f (p+1) (x)
and −1
σ2
1 X
Var[fb(x)] ∼ const(K, p) ε K((x − xi )/h) .
nh nh
Here we assume the xi to be fixed (or if they are not, we condition on them),
and that the bandwidth h = hn satisfies hn → 0 and nhn → ∞. From the
above formulæ, we see that h should be small to obtain a small (absolute) bias,
and h should be large to obtain a small variance. Hence the title of this section.
One quantity that considers bias and variance simultaneously is the mean
squared error:
h i h i 1
E (fb(x) − f (x))2 = Var[fb(x)] + (E fb(x) − f (x))2 = O( ) + O(h2(p+1) ).
nh
The order of this is minimal if both its summands have the same order, i.e.
h = O(n−1/(2p+3) ). Such a choice leads to a mean squared error of the order
O(n−(2p+2)/(2p+3) ). Looking closely, we would prefer to have p as large as
possible; in practice, however, this is not quite right, as a larger value of p
also enlarges the constants and requires stronger assumptions on f . In any
case, the constants are the greatest problem when applying these results: they
contain unknown terms such as the derivatives of f , and the optimal choice of
h depends on the location x. Thus the data-dependent yet optimal choice of
bandwidth is quite a difficult problem.
We could also find the optimal kernel K (by minimizing const(K, p)). It turns
out, however, that the choice of K is of secondary importance, as almost all
continuous kernels are nearly as good as each other.
The bias of the Nadaraya-Watson kernel estimators has a more complicated
form, but their variance is asymptotically equivalent to that of the local poly-
nomials with p = 1. For the Gasser-Müller version, the bias is the same as for
local polynomials with p = 1, but instead the constant involved in the variance
is 1.5 the size as the one obtained for local polynomials of degree p = 1. We
even know the bias and variance for the smoothing splines; it is similar to that
of local polynomials of degree p = 3.
quite well illustrated by the following example: If the points xi are equally
distributed inside the cube [−1, 1]p , the proportion of points lying in the unit
sphere {x; ||x|| ≤ 1} is approximately the same as the probability of a xi lying
in this unit sphere, i.e. the volume of the unit sphere times 2−p . If p = 2, this
probability is 79%, for p = 5 it is still 16%, and for p = 10 only 0.25% ! On
√
the other hand, the ratio of diameters of sphere and cube is 1 : p, thus for
p = 10, we roughly have the ratio 1 : 3. So the assumption that f is constant or
linear on the unit sphere does not differ significantly from the assumption that
f is constant or linear on the entire cube – yet we still nearly always have too
few observations inside the unit sphere to estimate a constant or linear function
well.
Appendix A
1
2 Results from probability theory
• E [AY + b] = AE [Y] + b,
• Cov[AY + b] = A · Cov[Y] · AT .
In particular, the latter rule tells us that for an arbitrary vector a of dimension
n × 1:
0 ≤ Var[aT Y] = Cov[aT Y] = aT Cov[Y]a.
1 1 2
ϕ(x) := √ e− 2 x
2π
A.2 The normal distribution 3
(This is a probability density, i.e. the integral of ϕ(x) over the real axis
is 1). The cumulative density function
Z x
Φ(x) = ϕ(y)dy
−∞
d log f (x) f0
= (x) = ax + b ,
dx f
1 2
it follows that f (x) = e 2 ax +bx+c . This quantity f 0 /f is quite important
in statistics. Thus in a certain sense, the normal distribution really is the
most simple continuous distribution on the whole real line!
d) Linear transformations of the standard normal distribution N (0, 1) :
Regard X ∼ N (0, 1) and the transformation x 7−→ y := µ + σx, taking
an arbitrary µ and some σ > 0. Then the distribution of Y := µ + σX is
the general normal distribution N (µ, σ 2 ).
Computing the density of Y : From
we conclude that
2
1 1 2 1 1 (y−µ)
√ e− 2 x dx = √ e− 2 σ2 dy.
2π 2π · σ
| {z }
density of Y :=µ+σX
Mean: E [Y ] = µ
Variance: Var[Y ] = σ 2
E (Y − µ)3 /σ 3 = 0
Skewness (standardized 3rd moment): γ1 =
Kurtosis, excess (stand. 4th moment): γ2 = E (Y − µ)4 /σ 4 − 3 = 0
X = AY + µ.
E [X] = AE [Y] + µ = µ
and
Figure A.2: Despite normal marginal distributions, the joint distribution need
not be a normal one.
and between these two extremes the correlation varies in a continuous manner,
including taking on the value 0 at some point. However, the two variables here
are always dependent. Thus we also see that without joint normality, lack of
correlation does not mean independence.
These distributions are derived from the normal distribution and have an im-
portant role in various tests in regression. Let
X1 , X2 , . . . , Xm , Y1 , Y2 , . . . , Yn independent ∼ N (0, 1).
The distribution of Pm
1
X2
Wm,n = m
1 Pni=1 2i
n i=1 Yi
is called F distribution with m degrees of freedom in the enumerator and n
degrees of freedom in the denominator (and is written Fm,n ). In particular, we
have
1
L(Wm,n ) → χ2m (m fest, n → ∞)
m
and
L(Wm,n ) → 1, (m → ∞, n → ∞).
Literature
Daniel, C. and Wood, F. S. (1980). Fitting Equations to Data, 2nd edn, Wiley,
N. Y. A classic for data analysis and applications.
9
10 Literature