Part IB — Statistics
Based on lectures by D. Spiegelhalter
Notes taken by Dexter Chua
Lent 2015
These notes are not endorsed by the lecturers, and I have modified them (often
significantly) after lectures. They are nowhere near accurate representations of what
was actually lectured, and in particular, all errors are almost surely mine.
Estimation
Review of distribution and density functions, parametric families. Examples: bino-
mial, Poisson, gamma. Sufficiency, minimal sufficiency, the Rao-Blackwell theorem.
Maximum likelihood estimation. Confidence intervals. Use of prior distributions and
Bayesian inference. [5]
Hypothesis testing
Simple examples of hypothesis testing, null and alternative hypothesis, critical region,
size, power, type I and type II errors, Neyman-Pearson lemma. Significance level of
outcome. Uniformly most powerful tests. Likelihood ratio, and use of generalised likeli-
ho od ratio to construct test statistics for composite hypotheses. Examples, including
t
-tests and
F
-tests. Relationship with confidence intervals. Goodness-of-fit tests and
contingency tables. [4]
Linear models
Derivation and joint distribution of maximum likelihood estimators, least squares,
Gauss-Markov theorem. Testing hypotheses, geometric interpretation. Examples,
including simple linear regression and one-way analysis of variance. Use of software. [7]
Contents
0 Introduction
1 Estimation
1.1 Estimators
1.2 Mean squared error
1.3 Sufficiency
1.4 Likelihood
1.5 Confidence intervals
1.6 Bayesian estimation
2 Hypothesis testing
2.1 Simple hypotheses
2.2 Composite hypotheses
2.3 Tests of goodness-of-fit and independence
2.3.1 Goodness-of-fit of a fully-specified null distribution
2.3.2 Pearson’s chi-squared test
2.3.3 Testing independence in contingency tables
2.4 Tests of homogeneity, and connections to confidence intervals
2.4.1 Tests of homogeneity
2.4.2 Confidence intervals and hypothesis tests
2.5 Multivariate normal theory
2.5.1 Multivariate normal distribution
2.5.2 Normal random samples
2.6 Student’s t-distribution
3 Linear models
3.1 Linear models
3.2 Simple linear regression
3.3 Linear models with normal assumptions
3.4 The F distribution
3.5 Inference for β
3.6 Simple linear regression
3.7 Expected response at x
∗
3.8 Hypothesis testing
3.8.1 Hypothesis testing
3.8.2 Simple linear regression
3.8.3
One way analysis of variance with equal numbers in each
group
0 Introduction
Statistics is a set of principles and procedures for gaining and processing quan-
titative evidence in order to help us make judgements and decisions. In this
course, we focus on formal statistical inference. In the process, we assume that
we have some data generated from some unknown probability model, and we aim
to use the data to learn about certain properties of the underlying probability
model.
In particular, we perform parametric inference. We assume that we have
a random variable
X
that follows a particular known family of distribution
(e.g. Poisson distribution). However, we do not know the parameters of the
distribution. We then attempt to estimate the parameter from the data given.
For example, we might know that
X ∼ Poisson
(
µ
) for some
µ
, and we want
to figure out what µ is.
Usually we repeat the experiment (or observation) many times. Hence we
will have
X
1
, X
2
, ··· , X
n
being iid with the same distribution as
X
. We call the
set X = (X
1
, X
2
, ··· , X
n
) a simple random sample. This is the data we have.
We will use the observed X = x to make inferences about the parameter
θ
,
such as
– giving an estimate
ˆ
θ(x) of the true value of θ.
– Giving an interval estimate (
ˆ
θ
1
(x),
ˆ
θ
2
(x)) for θ
– testing a hypothesis about θ, e.g. whether θ = 0.
1 Estimation
1.1 Estimators
The goal of estimation is as follows: we are given iid
X
1
, ··· , X
n
, and we know
that their probability density/mass function is
f
X
(
x
;
θ
) for some unknown
θ
.
We know
f
X
but not
θ
. For example, we might know that they follow a Poisson
distribution, but we do not know what the mean is. The objective is to estimate
the value of θ.
Definition (Statistic). A statistic is an estimate of
θ
. It is a function
T
of the
data. If we write the data as x = (
x
1
, ··· , x
n
), then our estimate is written as
ˆ
θ = T (x). T (X) is an estimator of θ.
The distribution of T = T (X) is the sampling distribution of the statistic.
Note that we adopt the convention where capital X denotes a random variable
and x is an observed value. So
T
(X) is a random variable and
T
(x) is a particular
value we obtain after experiments.
Example. Let X
1
, ··· , X
n
be iid N(µ, 1). A possible estimator for µ is
T (X) =
1
n
X
X
i
.
Then for any particular observed sample x, our estimate is
T (x) =
1
n
X
x
i
.
What is the sampling distribution of
T
? Recall from IA Probability that in
general, if
X
i
∼ N
(
µ
i
, σ
2
i
), then
P
X
i
∼ N
(
P
µ
i
,
P
σ
2
i
), which is something we
can prove by considering moment-generating functions.
So we have
T
(X)
∼ N
(
µ,
1
/n
). Note that by the Central Limit Theorem,
even if
X
i
were not normal, we still have approximately
T
(X)
∼ N
(
µ,
1
/n
) for
large values of
n
, but here we get exactly the normal distribution even for small
values of n.
The estimator
1
n
P
X
i
we had above is a rather sensible estimator. Of course,
we can also have silly estimators such as
T
(X) =
X
1
, or even
T
(X) = 0
.
32
always.
One way to decide if an estimator is silly is to look at its bias.
Definition (Bias). Let
ˆ
θ
=
T
(X) be an estimator of
θ
. The bias of
ˆ
θ
is the
difference between its expected value and true value.
bias(
ˆ
θ) = E
θ
(
ˆ
θ) − θ.
Note that the subscript
θ
does not represent the random variable, but the thing
we want to estimate. This is inconsistent with the use for, say, the probability
mass function.
An estimator is unbiased if it has no bias, i.e. E
θ
(
ˆ
θ) = θ.
To find out
E
θ
(
T
), we can either find the distribution of
T
and find its
expected value, or evaluate
T
as a function of X directly, and find its expected
value.
Example. In the above example, E
µ
(T ) = µ. So T is unbiased for µ.
1.2 Mean squared error
Given an estimator, we want to know how good the estimator is. We have just
come up with the concept of the bias above. However, this is generally not a
good measure of how good the estimator is.
For example, if we do 1000 random trials
X
1
, ··· , X
1000
, we can pick our
estimator as
T
(X) =
X
1
. This is an unbiased estimator, but is really bad because
we have just wasted the data from the other 999 trials. On the other hand,
T
′
(X) = 0
.
01 +
1
1000
P
X
i
is biased (with a bias of 0
.
01), but is in general much
more trustworthy than
T
. In fact, at the end of the section, we will construct
cases where the only possible unbiased estimator is a completely silly estimator
to use.
Instead, a commonly used measure is the mean squared error.
Definition (Mean squared error). The mean squared error of an estimator
ˆ
θ
is
E
θ
[(
ˆ
θ − θ)
2
].
Sometimes, we use the root mean squared error, that is the square root of
the above.
We can express the mean squared error in terms of the variance and bias:
E
θ
[(
ˆ
θ − θ)
2
] = E
θ
[(
ˆ
θ − E
θ
(
ˆ
θ) + E
θ
(
ˆ
θ) − θ)
2
]
= E
θ
[(
ˆ
θ − E
θ
(
ˆ
θ))
2
] + [E
θ
(
ˆ
θ) − θ]
2
+ 2E
θ
[E
θ
(
ˆ
θ) − θ] E
θ
[
ˆ
θ − E
θ
(
ˆ
θ)]
| {z }
0
= var(
ˆ
θ) + bias
2
(
ˆ
θ).
If we are aiming for a low mean squared error, sometimes it could be preferable to
have a biased estimator with a lower variance. This is known as the “bias-variance
trade-off”.
For example, suppose
X ∼ binomial
(
n, θ
), where
n
is given and
θ
is to be
determined. The standard estimator is
T
U
=
X/n
, which is unbiased.
T
U
has
variance
var
θ
(T
U
) =
var
θ
(X)
n
2
=
θ(1 − θ)
n
.
Hence the mean squared error of the usual estimator is given by
mse(T
U
) = var
θ
(T
U
) + bias
2
(T
U
) = θ(1 − θ)/n.
Consider an alternative estimator
T
B
=
X + 1
n + 2
= w
X
n
+ (1 −w)
1
2
,
where
w
=
n/
(
n
+ 2). This can be interpreted to be a weighted average (by the
sample size) of the sample mean and 1/2. We have
E
θ
(T
B
) − θ =
nθ + 1
n + 2
− θ = (1 −w)
1
2
− θ
,
and is biased. The variance is given by
var
θ
(T
B
) =
var
θ
(X)
(n + 2)
2
= w
2
θ(1 − θ)
n
.
Hence the mean squared error is
mse(T
B
) = var
θ
(T
B
) + bias
2
(T
B
) = w
2
θ(1 − θ)
n
+ (1 −w)
2
1
2
− θ
2
.
We can plot the mean squared error of each estimator for possible values of
θ
.
Here we plot the case where n = 10.
unbiased estimator
biased estimator
θ
mse
0 0.2 0.4 0.6 0.8 1.0
0
0.01
0.02
0.03
This biased estimator has smaller MSE unless θ has extreme values.
We see that sometimes biased estimators could give better mean squared
errors. In some cases, not only could unbiased estimators be worse — they could
be completely nonsense.
Suppose
X ∼ Poisson
(
λ
), and for whatever reason, we want to estimate
θ
= [
P
(
X
= 0)]
2
=
e
−2λ
. Then any unbiased estimator
T
(
X
) must satisfy
E
θ
(T (X)) = θ, or equivalently,
E
λ
(T (X)) = e
−λ
∞
X
x=0
T (x)
λ
x
x!
= e
−2λ
.
The only function T that can satisfy this equation is T (X) = (−1)
X
.
Thus the unbiased estimator would estimate e
−2λ
to be 1 if X is even, -1 if
X is odd. This is clearly nonsense.
1.3 Sufficiency
Often, we do experiments just to find out the value of
θ
. For example, we might
want to estimate what proportion of the population supports some political
candidate. We are seldom interested in the data points themselves, and just
want to learn about the big picture. This leads us to the concept of a sufficient
statistic. This is a statistic
T
(X) that contains all information we have about
θ
in the sample.
Example. Let
X
1
, ···X
n
be iid
Bernoulli
(
θ
), so that
P
(
X
i
= 1) = 1
− P
(
X
i
=
0) = θ for some 0 < θ < 1. So
f
X
(x | θ) =
n
Y
i=1
θ
x
i
(1 − θ)
1−x
i
= θ
P
x
i
(1 − θ)
n−
P
x
i
.
This depends on the data only through
T
(X) =
P
x
i
, the total number of ones.
Suppose we are now given that
T
(X) =
t
. Then what is the distribution of
X? We have
f
X|T =t
(x) =
P
θ
(X = x, T = t)
P
θ
(T = t)
=
P
θ
(X = x)
P
θ
(T = t)
.
Where the last equality comes because since if X = x, then
T
must be equal to
t. This is equal to
θ
P
x
i
(1 − θ)
n−
P
x
i
n
t
θ
t
(1 − θ)
n−t
=
n
t
−1
.
So the conditional distribution of X given
T
=
t
does not depend on
θ
. So if we
know
T
, then additional knowledge of x does not give more information about
θ
.
Definition (Sufficient statistic). A statistic
T
is sufficient for
θ
if the conditional
distribution of X given T does not depend on θ.
There is a convenient theorem that allows us to find sufficient statistics.
Theorem (The factorization criterion). T is sufficient for θ if and only if
f
X
(x | θ) = g(T (x), θ)h(x)
for some functions g and h.
Proof. We first prove the discrete case.
Suppose f
X
(x | θ) = g(T (x), θ)h(x). If T (x) = t, then
f
X|T =t
(x) =
P
θ
(X = x, T (X) = t)
P
θ
(T = t)
=
g(T (x), θ)h(x)
P
{y:T (y)=t}
g(T (y), θ)h(y)
=
g(t, θ)h(x)
g(t, θ)
P
h(y)
=
h(x)
P
h(y)
which doesn’t depend on θ. So T is sufficient.
The continuous case is similar. If
f
X
(x
| θ
) =
g
(
T
(x)
, θ
)
h
(x), and
T
(x) =
t
,
then
f
X|T =t
(x) =
g(T (x), θ)h(x)
R
y:T (y)=t
g(T (y), θ)h(y) dy
=
g(t, θ)h(x)
g(t, θ)
R
h(y) dy
=
h(x)
R
h(y) dy
,
which does not depend on θ.
Now suppose
T
is sufficient so that the conditional distribution of X
| T
=
t
does not depend on θ. Then
P
θ
(X = x) = P
θ
(X = x, T = T (x)) = P
θ
(X = x | T = T (x))P
θ
(T = T(x)).
The first factor does not depend on
θ
by assumption; call it
h
(x). Let the second
factor be g(t, θ), and so we have the required factorisation.
Example. Continuing the above example,
f
X
(x | θ) = θ
P
x
i
(1 − θ)
n−
P
x
i
.
Take
g
(
t, θ
) =
θ
t
(1
− θ
)
n−t
and
h
(x) = 1 to see that
T
(X) =
P
X
i
is sufficient
for θ.
Example. Let
X
1
, ··· , X
n
be iid
U
[0
, θ
]. Write 1
[A]
for the indicator function
of an arbitrary set A. We have
f
X
(x | θ) =
n
Y
i=1
1
θ
1
[0≤x
i
≤θ]
=
1
θ
n
1
[max
i
x
i
≤θ]
1
[min
i
x
i
≥0]
.
If we let T = max
i
x
i
, then we have
f
X
(x | θ) =
1
θ
n
1
[t≤θ]
| {z }
g(t,θ)
1
[min
i
x
i
≥0]
| {z }
h(x)
.
So T = max
i
x
i
is sufficient.
Note that sufficient statistics are not unique. If
T
is sufficient for
θ
, then
so is any 1-1 function of
T
. X is always sufficient for
θ
as well, but it is not of
much use. How can we decide if a sufficient statistic is “good”?
Given any statistic
T
, we can partition the sample space
X
n
into sets
{
x
∈ X
:
T
(x) =
t}
. Then after an experiment, instead of recording the actual
value of x, we can simply record the partition x falls into. If there are less
partitions than possible values of x, then effectively there is less information we
have to store.
If
T
is sufficient, then this data reduction does not lose any information
about
θ
. The “best” sufficient statistic would be one in which we achieve the
maximum possible reduction. This is known as the minimal sufficient statistic.
The formal definition we take is the following:
Definition (Minimal sufficiency). A sufficient statistic
T
(X) is minimal if it is
a function of every other sufficient statistic, i.e. if
T
′
(X) is also sufficient, then
T
′
(X) = T
′
(Y) ⇒ T (X) = T (Y).
Again, we have a handy theorem to find minimal statistics:
Theorem. Suppose T = T(X) is a statistic that satisfies
f
X
(x; θ)
f
X
(y; θ)
does not depend on θ if and only if T (x) = T (y).
Then T is minimal sufficient for θ.
Proof.
First we have to show sufficiency. We will use the factorization criterion
to do so.
Firstly, for each possible t, pick a favorite x
t
such that T (x
t
) = t.
Now let x
∈ X
N
and let
T
(x) =
t
. So
T
(x) =
T
(x
t
). By the hypothesis,
f
X
(x;θ)
f
X
(x
t
:θ)
does not depend on θ. Let this be h(x). Let g(t, θ) = f
X
(x
t
, θ). Then
f
X
(x; θ) = f
X
(x
t
; θ)
f
X
(x; θ)
f
X
(x
t
; θ)
= g(t, θ)h(x).
So T is sufficient for θ.
To show that this is minimal, suppose that
S
(X) is also sufficient. By the
factorization criterion, there exist functions g
S
and h
S
such that
f
X
(x; θ) = g
S
(S(x), θ)h
S
(x).
Now suppose that S(x) = S(y). Then
f
X
(x; θ)
f
X
(y; θ)
=
g
S
(S(x), θ)h
S
(x)
g
S
(S(y), θ)h
S
(y)
=
h
S
(x)
h
S
(y)
.
This means that the ratio
f
X
(x;θ)
f
X
(y;θ)
does not depend on
θ
. By the hypothesis, this
implies that
T
(x) =
T
(y). So we know that
S
(x) =
S
(y) implies
T
(x) =
T
(y).
So T is a function of S. So T is minimal sufficient.
Example. Suppose X
1
, ··· , X
n
are iid N (µ, σ
2
). Then
f
X
(x | µ, σ
2
)
f
X
(y | µ, σ
2
)
=
(2πσ
2
)
−n/2
exp
−
1
2σ
2
P
i
(x
i
− µ)
2
(2πσ
2
)
−n/2
exp
−
1
2σ
2
P
i
(y
i
− µ)
2
= exp
(
−
1
2σ
2
X
i
x
2
i
−
X
i
y
2
i
!
+
µ
σ
2
X
i
x
i
−
X
i
y
i
!)
.
This is a constant function of (
µ, σ
2
) iff
P
i
x
2
i
=
P
i
y
2
i
and
P
i
x
i
=
P
i
y
i
. So
T (X) = (
P
i
X
2
i
,
P
i
X
i
) is minimal sufficient for (µ, σ
2
).
As mentioned, sufficient statistics allow us to store the results of our exper-
iments in the most efficient way. It turns out if we have a minimal sufficient
statistic, then we can use it to improve any estimator.
Theorem (Rao-Blackwell Theorem). Let
T
be a sufficient statistic for
θ
and let
˜
θ
be an estimator for
θ
with
E
(
˜
θ
2
)
< ∞
for all
θ
. Let
ˆ
θ
(x) =
E
[
˜
θ
(X)
| T
(X) =
T (x)]. Then for all θ,
E[(
ˆ
θ − θ)
2
] ≤ E[(
˜
θ − θ)
2
].
The inequality is strict unless
˜
θ is a function of T .
Here we have to be careful with our definition of
ˆ
θ
. It is defined as the
expected value of
˜
θ
(X), and this could potentially depend on the actual value of
θ
. Fortunately, since
T
is sufficient for
θ
, the conditional distribution of X given
T
=
t
does not depend on
θ
. Hence
ˆ
θ
=
E
[
˜
θ
(X)
| T
] does not depend on
θ
, and
so is a genuine estimator. In fact, the proof does not use that
T
is sufficient; we
only require it to be sufficient so that we can compute
ˆ
θ.
Using this theorem, given any estimator, we can find one that is a function
of a sufficient statistic and is at least as good in terms of mean squared error of
estimation. Moreover, if the original estimator
˜
θ
is unbiased, so is the new
ˆ
θ
.
Also, if
˜
θ is already a function of T , then
ˆ
θ =
˜
θ.
Proof.
By the conditional expectation formula, we have
E
(
ˆ
θ
) =
E
[
E
(
˜
θ | T
)] =
E(
˜
θ). So they have the same bias.
By the conditional variance formula,
var(
˜
θ) = E[var(
˜
θ | T )] + var[E(
˜
θ | T )] = E[var(
˜
θ | T )] + var(
ˆ
θ).
Hence
var
(
˜
θ
)
≥ var
(
ˆ
θ
). So
mse
(
˜
θ
)
≥ mse
(
ˆ
θ
), with equality only if
var
(
˜
θ | T
) =
0.
Example. Suppose
X
1
, ··· , X
n
are iid
Poisson
(
λ
), and let
θ
=
e
−λ
, which is
the probability that X
1
= 0. Then
p
X
(x | λ) =
e
−nλ
λ
P
x
i
Q
x
i
!
.
So
p
X
(x | θ) =
θ
n
(−log θ)
P
x
i
Q
x
i
!
.
We see that T =
P
X
i
is sufficient for θ, and
P
X
i
∼ Poisson(nλ).
We start with an easy estimator
θ
is
˜
θ
= 1
X
1
=0
, which is unbiased (i.e.
if we observe nothing in the first observation period, we assume the event is
impossible). Then
E[
˜
θ | T = t] = P
X
1
= 0 |
n
X
1
X
i
= t
!
=
P(X
1
= 0)P(
P
n
2
X
i
= t)
P(
P
n
1
X
i
= t)
=
n − 1
n
t
.
So
ˆ
θ
= (1
−
1
/n
)
P
x
i
. This approximately (1
−
1
/n
)
n
¯
X
≈ e
−
¯
X
=
e
−
ˆ
λ
, which
makes sense.
Example. Let
X
1
, ··· , X
n
be iid
U
[0
, θ
], and suppose that we want to estimate
θ
. We have shown above that
T
=
max X
i
is sufficient for
θ
. Let
ˆ
θ
= 2
X
1
, an
unbiased estimator. Then
E[
˜
θ | T = t] = 2E[X
1
| max X
i
= t]
= 2E[X
1
| max X
i
= t, X
1
= max X
i
]P(X
1
= max X
i
)
+ 2E[X
1
| max X
i
= t, X
1
= max X
i
]P(X
1
= max X
i
)
= 2
t ×
1
n
+
t
2
n − 1
n
=
n + 1
n
t.
So
ˆ
θ =
n+1
n
max X
i
is our new estimator.
1.4 Likelihood
There are many different estimators we can pick, and we have just come up with
some criteria to determine whether an estimator is “good”. However, these do
not give us a systematic way of coming up with an estimator to actually use. In
practice, we often use the maximum likelihood estimator.
Let
X
1
, ··· , X
n
be random variables with joint pdf/pmf
f
X
(x
| θ
). We
observe X = x.
Definition (Likelihood). For any given x, the likelihood of
θ
is
like
(
θ
) =
f
X
(x
|
θ
), regarded as a function of
θ
. The maximum likelihood estimator (mle) of
θ
is
an estimator that picks the value of θ that maximizes like(θ).
Often there is no closed form for the mle, and we have to find
ˆ
θ
numerically.
When we can find the mle explicitly, in practice, we often maximize the
log-likelihood instead of the likelihood. In particular, if
X
1
, ··· , X
n
are iid, each
with pdf/pmf f
X
(x | θ), then
like(θ) =
n
Y
i=1
f
X
(x
i
| θ),
log like(θ) =
n
X
i=1
log f
X
(x
i
| θ).
Example. Let X
1
, ··· , X
n
be iid Bernoulli(p). Then
l(p) = log like(p) =
X
x
i
log p +
n −
X
x
i
log(1 −p).
Thus
dl
dp
=
P
x
i
p
−
n −
P
x
i
1 − p
.
This is zero when
p
=
P
x
i
/n
. So this is the maximum likelihood estimator
(and is unbiased).
Example. Let
X
1
, ··· , X
n
be iid
N
(
µ, σ
2
), and we want to estimate
θ
= (
µ, σ
2
).
Then
l(µ, σ
2
) = log like(µ, σ
2
) = −
n
2
log(2π) −
n
2
log(σ
2
) −
1
2σ
2
X
(x
i
− µ)
2
.
This is maximized when
∂l
∂µ
=
∂l
∂σ
2
= 0.
We have
∂l
∂µ
= −
1
σ
2
X
(x
i
− µ),
∂l
∂σ
2
= −
n
2σ
2
+
1
2σ
4
X
(x
i
− µ)
2
.
So the solution, hence maximum likelihood estimator is (
ˆµ, ˆσ
2
) = (
¯x, S
xx
/n
),
where ¯x =
1
n
P
x
i
and S
xx
=
P
(x
i
− ¯x)
2
.
We shall see later that
S
XX
/σ
2
=
nˆσ
2
σ
2
∼ χ
2
n−1
, and so
E
(
ˆσ
2
) =
(n−1)σ
2
n
, i.e.
ˆσ
2
is biased.
Example (German tank problem). Suppose the American army discovers some
German tanks that are sequentially numbered, i.e. the first tank is numbered 1,
the second is numbered 2, etc. Then if
θ
tanks are produced, then the probability
distribution of the tank number is
U
(0
, θ
). Suppose we have discovered
n
tanks
whose numbers are
x
1
, x
2
, ··· , x
n
, and we want to estimate
θ
, the total number
of tanks produced. We want to find the maximum likelihood estimator.
Then
like(θ) =
1
θ
n
1
[max x
i
≤θ]
1
[min x
i
≥0]
.
So for
θ ≥ max x
i
,
like
(
θ
) = 1
/θ
n
and is decreasing as
θ
increases, while for
θ < max x
i
, like(θ) = 0. Hence the value
ˆ
θ = max x
i
maximizes the likelihood.
Is
ˆ
θ
unbiased? First we need to find the distribution of
ˆ
θ
. For 0
≤ t ≤ θ
, the
cumulative distribution function of
ˆ
θ is
F
ˆ
θ
(t) = P (
ˆ
θ ≤ t) = P(X
i
≤ t for all i) = (P(X
i
≤ t))
n
=
t
θ
n
,
Differentiating with respect to T , we find the pdf f
ˆ
θ
=
nt
n−1
θ
n
. Hence
E(
ˆ
θ) =
Z
θ
0
t
nt
n−1
θ
n
dt =
nθ
n + 1
.
So
ˆ
θ is biased, but asymptotically unbiased.
Example. Smarties come in
k
equally frequent colours, but suppose we do not
know
k
. Assume that we sample with replacement (although this is unhygienic).
Our first Smarties are Red, Purple, Red, Yellow. Then
like(k) = P
k
(1st is a new colour)P
k
(2nd is a new colour)
P
k
(3rd matches 1st)P
k
(4th is a new colour)
= 1 ×
k − 1
k
×
1
k
×
k − 2
k
=
(k − 1)(k −2)
k
3
.
The maximum likelihood is 5 (by trial and error), even though it is not much
likelier than the others.
How does the mle relate to sufficient statistics? Suppose that
T
is sufficient
for
θ
. Then the likelihood is
g
(
T
(x)
, θ
)
h
(x), which depends on
θ
through
T
(x).
To maximise this as a function of
θ
, we only need to maximize
g
. So the mle
ˆ
θ
is a function of the sufficient statistic.
Note that if
ϕ
=
h
(
θ
) with
h
injective, then the mle of
ϕ
is given by
h
(
ˆ
θ
). For
example, if the mle of the standard deviation
σ
is
ˆσ
, then the mle of the variance
σ
2
is
ˆσ
2
. This is rather useful in practice, since we can use this to simplify a lot
of computations.
1.5 Confidence intervals
Definition. A 100
γ
% (0
< γ <
1) confidence interval for
θ
is a random interval
(
A
(X)
, B
(X)) such that
P
(
A
(X)
< θ < B
(X)) =
γ
, no matter what the true
value of θ may be.
It is also possible to have confidence intervals for vector parameters.
Notice that it is the endpoints of the interval that are random quantities,
while θ is a fixed constant we want to find out.
We can interpret this in terms of repeat sampling. If we calculate (
A
(x)
, B
(x))
for a large number of samples x, then approximately 100
γ
% of them will cover
the true value of θ.
It is important to know that having observed some data x and calculated
95% confidence interval, we cannot say that
θ
has 95% chance of being within
the interval. Apart from the standard objection that
θ
is a fixed value and
either is or is not in the interval, and hence we cannot assign probabilities to
this event, we will later construct an example where even though we have got a
50% confidence interval, we are 100% sure that θ lies in that interval.
Example. Suppose
X
1
, ··· , X
n
are iid
N
(
θ,
1). Find a 95% confidence interval
for θ.
We know
¯
X ∼ N(θ,
1
n
), so that
√
n(
¯
X − θ) ∼ N(0, 1).
Let
z
1
, z
2
be such that Φ(
z
2
)
−
Φ(
z
1
) = 0
.
95, where Φ is the standard normal
distribution function.
We have P[z
1
<
√
n(
¯
X − θ) < z
2
] = 0.95, which can be rearranged to give
P
¯
X −
z
2
√
n
< θ <
¯
X −
z
1
√
n
= 0.95.
so we obtain the following 95% confidence interval:
¯
X −
z
2
√
n
,
¯
X −
z
1
√
n
.
There are many possible choices for
z
1
and
z
2
. Since
N
(0
,
1) density is symmetric,
the shortest such interval is obtained by
z
2
=
z
0.025
=
−z
1
. We can also choose
other values such as
z
1
=
−∞
,
z
2
= 1
.
64, but we usually choose symmetric end
points.
The above example illustrates a common procedure for finding confidence
intervals:
–
Find a quantity
R
(X
, θ
) such that the
P
θ
-distribution of
R
(X
, θ
) does not
depend on
θ
. This is called a pivot. In our example,
R
(X
, θ
) =
√
n
(
¯
X −θ
).
–
Write down a probability statement of the form
P
θ
(
c
1
< R
(X
, θ
)
< c
2
) =
γ
.
– Rearrange the inequalities inside P(. . .) to find the interval.
Usually
c
1
, c
2
are percentage points from a known standardised distribution, often
equitailed. For example, we pick 2
.
5% and 97
.
5% points for a 95% confidence
interval. We could also use, say 0% and 95%, but this generally results in a
wider interval.
Note that if (
A
(X)
, B
(X)) is a 100
γ
% confidence interval for
θ
, and
T
(
θ
)
is a monotone increasing function of
θ
, then (
T
(
A
(X))
, T
(
B
(X))) is a 100
γ
%
confidence interval for T (θ).
Example. Suppose
X
1
, ··· , X
50
are iid
N
(0
, σ
2
). Find a 99% confidence interval
for σ
2
.
We know that X
i
/σ ∼ N(0, 1). So
1
σ
2
50
X
i=1
X
2
i
∼ χ
2
50
.
So R(X, σ
2
) =
P
50
i=1
X
2
i
/σ
2
is a pivot.
Recall that χ
2
n
(α) is the upper 100α% point of χ
2
n
, i.e.
P(χ
2
n
≤ χ
2
n
(α)) = 1 − α.
So we have c
1
= χ
2
50
(0.995) = 27.99 and c
2
= χ
2
50
(0.005) = 79.49.
So
P
c
1
<
P
X
2
i
σ
2
< c
2
= 0.99,
and hence
P
P
X
2
i
c
2
< σ
2
<
P
X
2
i
c
1
= 0.99.
Using the remark above, we know that a 99% confidence interval for
σ
is
q
P
X
2
i
c
2
,
q
P
X
2
i
c
1
.
Example. Suppose
X
1
, ··· , X
n
are iid
Bernoulli
(
p
). Find an approximate
confidence interval for p.
The mle of p is ˆp =
P
X
i
/n.
By the Central Limit theorem,
ˆp
is approximately
N
(
p, p
(1
− p
)
/n
) for large
n.
So
√
n(ˆp − p)
p
p(1 − p)
is approximately
N
(0
,
1) for large
n
. So letting
z
(1−γ)/2
be
the solution to Φ(z
(1−γ)/2
) − Φ(−z
(1−γ)/2
) = 1 − γ, we have
P
ˆp − z
(1−γ)/2
r
p(1 − p)
n
< p < ˆp + z
(1−γ)/2
r
p(1 − p)
n
!
≈ γ.
But
p
is unknown! So we approximate it by
ˆp
to get a confidence interval for
p
when n is large:
P
ˆp − z
(1−γ)/2
r
ˆp(1 − ˆp)
n
< p < ˆp + z
(1−γ)/2
r
ˆp(1 − ˆp)
n
!
≈ γ.
Note that we have made a lot of approximations here, but it would be difficult
to do better than this.
Example. Suppose an opinion poll says 20% of the people are going to vote
UKIP, based on a random sample of 1
,
000 people. What might the true
proportion be?
We assume we have an observation of
x
= 200 from a
binomial
(
n, p
) distri-
bution with
n
= 1
,
000. Then
ˆp
=
x/n
= 0
.
2 is an unbiased estimate, and also
the mle.
Now
var
(
X/n
) =
p(1−p)
n
≈
ˆp(1−ˆp)
n
= 0
.
00016. So a 95% confidence interval is
ˆp − 1.96
r
ˆp(1 − ˆp)
n
, ˆp + 1.96
r
ˆp(1 − ˆp)
n
!
= 0.20±1.96×0.013 = (0.175, 0.225),
If we don’t want to make that many approximations, we can note that
p
(1
−p
)
≤
1
/
4 for all 0
≤ p ≤
1. So a conservative 95% interval is
ˆp±
1
.
96
p
1/4n ≈ ˆp±
p
1/n
.
So whatever proportion is reported, it will be ’accurate’ to ±1/
√
n.
Example. Suppose
X
1
, X
2
are iid from
U
(
θ −
1
/
2
, θ
+ 1
/
2). What is a sensible
50% confidence interval for θ?
We know that each
X
i
is equally likely to be less than
θ
or greater than
θ
.
So there is 50% chance that we get one observation on each side, i.e.
P
θ
(min(X
1
, X
2
) ≤ θ ≤ max(X
1
, X
2
)) =
1
2
.
So (min(X
1
, X
2
), max(X
1
, X
2
)) is a 50% confidence interval for θ.
But suppose after the experiment, we obtain
|x
1
−x
2
| ≥
1
2
. For example, we
might get
x
1
= 0
.
2
, x
2
= 0
.
9, then we know that, in this particular case,
θ
must
lie in (min(X
1
, X
2
), max(X
1
, X
2
)), and we don’t have just 50% “confidence”!
This is why after we calculate a confidence interval, we should not say “there
is 100(1
− α
)% chance that
θ
lies in here”. The confidence interval just says
that “if we keep making these intervals, 100(1
− α
)% of them will contain
θ
”.
But if have calculated a particular confidence interval, the probability that that
particular interval contains θ is not 100(1 −α)%.
1.6 Bayesian estimation
So far we have seen the frequentist approach to a statistical inference, i.e.
inferential statements about θ are interpreted in terms of repeat sampling. For
example, the percentage confidence in a confidence interval is the probability
that the interval will contain θ, not the probability that θ lies in the interval.
In contrast, the Bayesian approach treats
θ
as a random variable taking
values in Θ. The investigator’s information and beliefs about the possible values
of
θ
before any observation of data are summarised by a prior distribution
π
(
θ
).
When X = x are observed, the extra information about
θ
is combined with the
prior to obtain the posterior distribution π(θ | x) for θ given X = x.
There has been a long-running argument between the two approaches. Re-
cently, things have settled down, and Bayesian methods are seen to be appropriate
in huge numbers of application where one seeks to assess a probability about a
“state of the world”. For example, spam filters will assess the probability that a
specific email is a spam, even though from a frequentist’s point of view, this is
nonsense, because the email either is or is not a spam, and it makes no sense to
assign a probability to the email’s being a spam.
In Bayesian inference, we usually have some prior knowledge about the
distribution of
θ
(e.g. between 0 and 1). After collecting some data, we will find
a posterior distribution of θ given X = x.
Definition (Prior and posterior distribution). The prior distribution of
θ
is the
probability distribution of the value of
θ
before conducting the experiment. We
usually write as π(θ).
The posterior distribution of
θ
is the probability distribution of the value of
θ given an outcome of the experiment x. We write as π(θ | x).
By Bayes’ theorem, the distributions are related by
π(θ | x) =
f
X
(x | θ)π(θ)
f
X
(x)
.
Thus
π(θ | x) ∝ f
X
(x | θ)π(θ).
posterior ∝ likelihood × prior.
where the constant of proportionality is chosen to make the total mass of
the posterior distribution equal to one. Usually, we use this form, instead of
attempting to calculate f
X
(x).
It should be clear that the data enters through the likelihood, so the inference
is automatically based on any sufficient statistic.
Example. Suppose I have 3 coins in my pocket. One is 3 : 1 in favour of tails,
one is a fair coin, and one is 3 : 1 in favour of heads.
I randomly select one coin and flip it once, observing a head. What is the
probability that I have chosen coin 3?
Let
X
= 1 denote the event that I observe a head,
X
= 0 if a tail. Let
θ
denote the probability of a head. So θ is either 0.25, 0.5 or 0.75.
Our prior distribution is π(θ = 0.25) = π(θ = 0.5) = π(θ = 0.75) = 1/3.
The probability mass function
f
X
(
x | θ
) =
θ
x
(1
− θ
)
1−x
. So we have the
following results:
θ π(θ) f
X
(x = 1 | θ) f
X
(x = 1 | θ)π(θ) π(θ | x)
0.25 0.33 0.25 0.0825 0.167
0.50 0.33 0.50 0.1650 0.333
0.75 0.33 0.75 0.2475 0.500
Sum 1.00 1.50 0.4950 1.000
So if we observe a head, then there is now a 50% chance that we have picked
the third coin.
Example. Suppose we are interested in the true mortality risk
θ
in a hospital
H
which is about to try a new operation. On average in the country, around
10% of the people die, but mortality rates in different hospitals vary from around
3% to around 20%. Hospital
H
has no deaths in their first 10 operations. What
should we believe about θ?
Let X
i
= 1 if the ith patient in H dies. The
f
x
(x | θ) = θ
P
x
i
(1 − θ)
n−
P
x
i
.
Suppose a priori that θ ∼ beta(a, b) for some unknown a > 0, b > 0 so that
π(θ) ∝ θ
a−1
(1 − θ)
b−1
.
Then the posteriori is
π(θ | x) ∝ f
x
(x | θ)π(θ) ∝ θ
P
x
i
+a−1
(1 − θ)
n−
P
x
i
+b−1
.
We recognize this as beta(
P
x
i
+ a, n −
P
x
i
+ b). So
π(θ | x) =
θ
P
x
i
+a−1
(1 − θ)
n−
P
x
i
+b−1
B(
P
x
i
+ a, n −
P
x
i
+ b)
.
In practice, we need to find a Beta prior distribution that matches our information
from other hospitals. It turns out that
beta
(
a
= 3
, b
= 27) prior distribution has
mean 0.1 and P(0.03 < θ < .20) = 0.9.
Then we observe data
P
x
i
= 0,
n
= 0. So the posterior is
beta
(
P
x
i
+
a, n −
P
x
i
+ b) = beta(3, 37). This has a mean of 3/40 = 0.075.
This leads to a different conclusion than a frequentist analysis. Since nobody
has died so far, the mle is 0, which does not seem plausible. Using a Bayesian
approach, we have a higher mean than 0 because we take into account the data
from other hospitals.
For this problem, a beta prior leads to a beta posterior. We say that the
beta family is a conjugate family of prior distributions for Bernoulli samples.
Suppose that
a
=
b
= 1 so that
π
(
θ
) = 1 for 0
< θ <
1 — the uniform
distribution. Then the posterior is
beta
(
P
x
i
+ 1
, n −
P
x
i
+ 1), with properties
mean mode variance
prior 1/2 non-unique 1/12
posterior
P
x
i
+ 1
n + 2
P
x
i
n
(
P
x
i
+ 1)(n −
P
x
i
+ 1)
(n + 2)
2
(n + 3)
Note that the mode of the posterior is the mle.
The posterior mean estimator,
P
x
i
+1
n+2
is discussed in Lecture 2, where we
showed that this estimator had smaller mse than the mle for non-extreme value
of θ. This is known as the Laplace’s estimator.
The posterior variance is bounded above by 1
/
(4(
n
+ 3)), and this is smaller
than the prior variance, and is smaller for larger n.
Again, note that the posterior automatically depends on the data through
the sufficient statistic.
After we come up with the posterior distribution, we have to decide what
estimator to use. In the case above, we used the posterior mean, but this might
not be the best estimator.
To determine what is the “best” estimator, we first need a loss function. Let
L
(
θ, a
) be the loss incurred in estimating the value of a parameter to be
a
when
the true value is θ.
Common loss functions are quadratic loss
L
(
θ, a
) = (
θ − a
)
2
, absolute error
loss L(θ, a) = |θ − a|, but we can have others.
When our estimate is a, the expected posterior loss is
h(a) =
Z
L(θ, a)π(θ | x) dθ.
Definition (Bayes estimator). The Bayes estimator
ˆ
θ
is the estimator that
minimises the expected posterior loss.
For quadratic loss,
h(a) =
Z
(a − θ)
2
π(θ | x) dθ.
h
′
(a) = 0 if
Z
(a − θ)π(θ | x) dθ = 0,
or
a
Z
π(θ | x) dθ =
Z
θπ(θ | x) dθ,
Since
R
π
(
θ |
x) d
θ
= 1, the Bayes estimator is
ˆ
θ
=
R
θπ
(
θ |
x) d
θ
, the posterior
mean.
For absolute error loss,
h(a) =
Z
|θ − a|π(θ | x) dθ
=
Z
a
−∞
(a − θ)π(θ | x) dθ +
Z
∞
a
(θ − a)π(θ | x) dθ
= a
Z
a
−∞
π(θ | x) dθ −
Z
a
−∞
θπ(θ | x) dθ
+
Z
∞
a
θπ(θ | x) dθ − a
Z
∞
a
π(θ | x) dθ.
Now h
′
(a) = 0 if
Z
a
−∞
π(θ | x) dθ =
Z
∞
a
π(θ | x) dθ.
This occurs when each side is 1/2. So
ˆ
θ is the posterior median.
Example. Suppose that
X
1
, ··· , X
n
are iid
N
(
µ,
1), and that a priori
µ ∼
N(0, τ
−2
) for some τ
−2
. So τ is the certainty of our prior knowledge.
The posterior is given by
π(µ | x) ∝ f
x
(x | µ)π(µ)
∝ exp
−
1
2
X
(x
i
− µ)
2
exp
−
µ
2
τ
2
2
∝ exp
"
−
1
2
(n + τ
2
)
µ −
P
x
i
n + τ
2
2
#
since we can regard
n
,
τ
and all the
x
i
as constants in the normalisation term,
and then complete the square with respect to
µ
. So the posterior distribution
of
µ
given x is a normal distribution with mean
P
x
i
/
(
n
+
τ
2
) and variance
1/(n + τ
2
).
The normal density is symmetric, and so the posterior mean and the posterior
median have the same value
P
x
i
/(n + τ
2
).
This is the optimal estimator for both quadratic and absolute loss.
Example. Suppose that
X
1
, ··· , X
n
are iid
Poisson
(
λ
) random variables, and
λ has an exponential distribution with mean 1. So π(λ) = e
−λ
.
The posterior distribution is given by
π(λ | x) ∝ e
nλ
λ
P
x
i
e
−λ
= λ
P
x
i
e
−(n+1)λ
, λ > 0,
which is
gamma (
P
x
i
+ 1, n + 1)
. Hence under quadratic loss, our estimator is
ˆ
λ =
P
x
i
+ 1
n + 1
,
the posterior mean.
Under absolute error loss,
ˆ
λ solves
Z
ˆ
λ
0
(n + 1)
P
x
i
+1
λ
P
x
i
e
−(n+1)λ
(
P
x
i
)!
dλ =
1
2
.
2 Hypothesis testing
Often in statistics, we have some hypothesis to test. For example, we want to
test whether a drug can lower the chance of a heart attack. Often, we will have
two hypotheses to compare: the null hypothesis states that the drug is useless,
while the alternative hypothesis states that the drug is useful. Quantitatively,
suppose that the chance of heart attack without the drug is
θ
0
and the chance
with the drug is
θ
. Then the null hypothesis is
H
0
:
θ
=
θ
0
, while the alternative
hypothesis is H
1
: θ = θ
0
.
It is important to note that the null hypothesis and alternative hypothesis
are not on equal footing. By default, we assume the null hypothesis is true.
For us to reject the null hypothesis, we need a lot of evidence to prove that.
This is since we consider incorrectly rejecting the null hypothesis to be a much
more serious problem than accepting it when we should not. For example, it is
relatively okay to reject a drug when it is actually useful, but it is terrible to
distribute drugs to patients when the drugs are actually useless. Alternatively,
it is more serious to deem an innocent person guilty than to say a guilty person
is innocent.
In general, let
X
1
, ··· , X
n
be iid, each taking values in
X
, each with unknown
pdf/pmf
f
. We have two hypotheses,
H
0
and
H
1
, about
f
. On the basis of data
X = x, we make a choice between the two hypotheses.
Example.
–
A coin has
P
(
Heads
) =
θ
, and is thrown independently
n
times. We could
have H
0
: θ =
1
2
versus H
1
: θ =
3
4
.
–
Suppose
X
1
, ··· , X
n
are iid discrete random variables. We could have
H
0
:
the distribution is Poisson with unknown mean, and
H
1
: the distribution
is not Poisson.
–
General parametric cases: Let
X
1
, ··· , X
n
be iid with density
f
(
x | θ
).
f
is known while
θ
is unknown. Then our hypotheses are
H
0
:
θ ∈
Θ
0
and
H
1
: θ ∈ Θ
1
, with Θ
0
∩ Θ
1
= ∅.
–
We could have
H
0
:
f
=
f
0
and
H
1
:
f
=
f
1
, where
f
0
and
f
1
are densities
that are completely specified but do not come form the same parametric
family.
Definition (Simple and composite hypotheses). A simple hypothesis
H
specifies
f completely (e.g. H
0
: θ =
1
2
). Otherwise, H is a composite hypothesis.
2.1 Simple hypotheses
Definition (Critical region). For testing
H
0
against an alternative hypothesis
H
1
, a test procedure has to partition
X
n
into two disjoint exhaustive regions
C
and
¯
C
, such that if x
∈ C
, then
H
0
is rejected, and if x
∈
¯
C
, then
H
0
is not
rejected. C is the critical region.
When performing a test, we may either arrive at a correct conclusion, or
make one of the two types of error:
Definition (Type I and II error).
(i) Type I error: reject H
0
when H
0
is true.
(ii) Type II error: not rejecting H
0
when H
0
is false.
Definition (Size and power). When H
0
and H
1
are both simple, let
α = P(Type I error) = P(X ∈ C | H
0
is true).
β = P(Type II error) = P(X ∈ C | H
1
is true).
The size of the test is α, and 1 − β is the power of the test to detect H
1
.
If we have two simple hypotheses, a relatively straightforward test is the
likelihood ratio test.
Definition (Likelihood). The likelihood of a simple hypothesis
H
:
θ
=
θ
∗
given
data x is
L
x
(H) = f
X
(x | θ = θ
∗
).
The likelihood ratio of two simple hypotheses H
0
, H
1
given data x is
Λ
x
(H
0
; H
1
) =
L
x
(H
1
)
L
x
(H
0
)
.
A likelihood ratio test (LR test) is one where the critical region
C
is of the form
C = {x : Λ
x
(H
0
; H
1
) > k}
for some k.
It turns out this rather simple test is “the best” in the following sense:
Lemma (Neyman-Pearson lemma). Suppose
H
0
:
f
=
f
0
,
H
1
:
f
=
f
1
, where
f
0
and
f
1
are continuous densities that are nonzero on the same regions. Then
among all tests of size less than or equal to
α
, the test with the largest power is
the likelihood ratio test of size α.
Proof. Under the likelihood ratio test, our critical region is
C =
x :
f
1
(x)
f
0
(x)
> k
,
where
k
is chosen such that
α
=
P
(
reject H
0
| H
0
) =
P
(X
∈ C | H
0
) =
R
C
f
0
(x) dx. The probability of Type II error is given by
β = P(X ∈ C | f
1
) =
Z
¯
C
f
1
(x) dx.
Let
C
∗
be the critical region of any other test with size less than or equal to
α
.
Let α
∗
= P(X ∈ C
∗
| H
0
) and β
∗
= P(X ∈ C
∗
| H
1
). We want to show β ≤ β
∗
.
We know α
∗
≤ α, i.e
Z
C
∗
f
0
(x) dx ≤
Z
C
f
0
(x) dx.
Also, on C, we have f
1
(x) > kf
0
(x), while on
¯
C we have f
1
(x) ≤ kf
0
(x). So
Z
¯
C
∗
∩C
f
1
(x) dx ≥ k
Z
¯
C
∗
∩C
f
0
(x) dx
Z
¯
C∩C
∗
f
1
(x) dx ≤ k
Z
¯
C∩C
∗
f
0
(x) dx.
Hence
β −β
∗
=
Z
¯
C
f
1
(x) dx −
Z
¯
C
∗
f
1
(x) dx
=
Z
¯
C∩C
∗
f
1
(x) dx +
Z
¯
C∩
¯
C
∗
f
1
(x) dx
−
Z
¯
C
∗
∩C
f
1
(x) dx −
Z
¯
C∩
¯
C
∗
f
1
(x) dx
=
Z
¯
C∩C
∗
f
1
(x) dx −
Z
¯
C
∗
∩C
f
1
(x) dx
≤ k
Z
¯
C∩C
∗
f
0
(x) dx − k
Z
¯
C
∗
∩C
f
0
(x) dx
= k
Z
¯
C∩C
∗
f
0
(x) dx +
Z
C∩C
∗
f
0
(x) dx
− k
Z
¯
C
∗
∩C
f
0
(x) dx +
Z
C∩C
∗
f
0
(x) dx
= k(α
∗
− α)
≤ 0.
C
∗
¯
C
∗
¯
C C
C
∗
∩
¯
C
(f
1
≤ kf
0
)
¯
C
∗
∩ C
(f
1
≥ kf
0
)
C
∗
∩ C
β/H
1
α/H
0
α
∗
/H
0
β
∗
/H
1
Here we assumed the
f
0
and
f
1
are continuous densities. However, this
assumption is only needed to ensure that the likelihood ratio test of exactly size
α
exists. Even with non-continuous distributions, the likelihood ratio test is still
a good idea. In fact, you will show in the example sheets that for a discrete
distribution, as long as a likelihood ratio test of exactly size
α
exists, the same
result holds.
Example. Suppose
X
1
, ··· , X
n
are iid
N
(
µ, σ
2
0
), where
σ
2
0
is known. We want
to find the best size
α
test of
H
0
:
µ
=
µ
0
against
H
1
:
µ
=
µ
1
, where
µ
0
and
µ
1
are known fixed values with µ
1
> µ
0
. Then
Λ
x
(H
0
; H
1
) =
(2πσ
2
0
)
−n/2
exp
−
1
2σ
2
0
P
(x
i
− µ
1
)
2
(2πσ
2
0
)
−n/2
exp
−
1
2σ
2
0
P
(x
i
− µ
0
)
2
= exp
µ
1
− µ
0
σ
2
0
n¯x +
n(µ
2
0
− µ
2
1
)
2σ
2
0
.
This is an increasing function of
¯x
, so for any
k
, Λ
x
> k ⇔ ¯x > c
for some
c
.
Hence we reject H
0
if ¯x > c, where c is chosen such that P(
¯
X > c | H
0
) = α.
Under H
0
,
¯
X ∼ N(µ
0
, σ
2
0
/n), so Z =
√
n(
¯
X − µ
0
)/σ
0
∼ N(0, 1).
Since ¯x > c ⇔ z > c
′
for some c
′
, the size α test rejects H
0
if
z =
√
n(¯x − µ
0
)
σ
0
> z
α
.
For example, suppose
µ
0
= 5,
µ
1
= 6,
σ
0
= 1,
α
= 0
.
05,
n
= 4 and x =
(5.1, 5.5, 4.9, 5.3). So ¯x = 5.2.
From tables,
z
0.05
= 1
.
645. We have
z
= 0
.
4 and this is less than 1
.
645. So x
is not in the rejection region.
We do not reject
H
0
at the 5% level and say that the data are consistent
with H
0
.
Note that this does not mean that we accept
H
0
. While we don’t have
sufficient reason to believe it is false, we also don’t have sufficient reason to
believe it is true.
This is called a z-test.
In this example, LR tests reject
H
0
if
z > k
for some constant
k
. The size of
such a test is
α
=
P
(
Z > k | H
0
) = 1
−
Φ(
k
), and is decreasing as
k
increasing.
Our observed value
z
will be in the rejected region iff
z > k ⇔ α > p
∗
=
P
(
Z >
z | H
0
).
Definition (
p
-value). The quantity
p
∗
is called the
p
-value of our observed data
x. For the example above, z = 0.4 and so p
∗
= 1 − Φ(0.4) = 0.3446.
In general, the
p
-value is sometimes called the “observed significance level” of
x. This is the probability under
H
0
of seeing data that is “more extreme” than
our observed data x. Extreme observations are viewed as providing evidence
against H
0
.
2.2 Composite hypotheses
For composite hypotheses like
H
:
θ ≥
0, the error probabilities do not have a
single value. We define
Definition (Power function). The power function is
W (θ) = P(X ∈ C | θ) = P(reject H
0
| θ).
We want W (θ) to be small on H
0
and large on H
1
.
Definition (Size). The size of the test is
α = sup
θ∈Θ
0
W (θ).
This is the worst possible size we can get.
For θ ∈ Θ
1
, 1 − W (θ) = P(Type II error | θ).
Sometimes the Neyman-Pearson theory can be extended to one-sided alter-
natives.
For example, in the previous example, we have shown that the most powerful
size α test of H
0
: µ = µ
0
versus H
1
: µ = µ
1
(where µ
1
> µ
0
) is given by
C =
x :
√
n(¯x − µ
0
)
σ
0
> z
α
.
The critical region depends on
µ
0
, n, σ
0
, α
, and the fact that
µ
1
> µ
0
. It does
not depend on the particular value of
µ
1
. This test is then uniformly the most
powerful size α for testing H
0
: µ = µ
0
against H
1
: µ > µ
0
.
Definition (Uniformly most powerful test). A test specified by a critical region
C
is uniformly most powerful (UMP) size
α
test for test
H
0
:
θ ∈
Θ
0
against
H
1
: θ ∈ Θ
1
if
(i) sup
θ∈Θ
0
W (θ) = α.
(ii)
For any other test
C
∗
with size
≤ α
and with power function
W
∗
, we have
W (θ) ≥ W
∗
(θ) for all θ ∈ Θ
1
.
Note that these may not exist. However, the likelihood ratio test often works.
Example. Suppose
X
1
, ··· , X
n
are iid
N
(
µ, σ
2
0
) where
σ
0
is known, and we
wish to test H
0
: µ ≤ µ
0
against H
1
: µ > µ
0
.
First consider testing
H
′
0
:
µ
=
µ
0
against
H
′
1
:
µ
=
µ
1
, where
µ
1
> µ
0
. The
Neyman-Pearson test of size α of H
′
0
against H
′
1
has
C =
x :
√
n(¯x − µ
0
)
σ
0
> z
α
.
We show that
C
is in fact UMP for the composite hypotheses
H
0
against
H
1
.
For µ ∈ R, the power function is
W (µ) = P
µ
(reject H
0
)
= P
µ
√
n(
¯
X − µ
0
)
σ
0
> z
α
= P
µ
√
n(
¯
X − µ)
σ
0
> z
α
+
√
n(µ
0
− µ)
σ
0
= 1 − Φ
z
α
+
√
n(µ
0
− µ)
σ
0
To show this is UMP, we know that
W
(
µ
0
) =
α
(by plugging in).
W
(
µ
) is an
increasing function of µ. So
sup
µ≤µ
0
W (µ) = α.
So the first condition is satisfied.
For the second condition, observe that for any
µ > µ
0
, the Neyman-Pearson
size
α
test of
H
′
0
vs
H
′
1
has critical region
C
. Let
C
∗
and
W
∗
belong to any
other test of
H
0
vs
H
1
of size
≤ α
. Then
C
∗
can be regarded as a test of
H
′
0
vs
H
′
1
of size
≤ α
, and the Neyman-Pearson lemma says that
W
∗
(
µ
1
)
≤ W
(
µ
1
).
This holds for all µ
1
> µ
0
. So the condition is satisfied and it is UMP.
We now consider likelihood ratio tests for more general situations.
Definition (Likelihood of a composite hypothesis). The likelihood of a composite
hypothesis H : θ ∈ Θ given data x to be
L
x
(H) = sup
θ∈Θ
f(x | θ).
So far we have considered disjoint hypotheses Θ
0
,
Θ
1
, but we are not interested
in any specific alternative. So it is easier to take Θ
1
= Θ rather than Θ
\
Θ
0
.
Then
Λ
x
(H
0
; H
1
) =
L
x
(H
1
)
L
x
(H
0
)
=
sup
θ∈Θ
1
f(x | θ)
sup
θ∈Θ
0
f(x | θ)
≥ 1,
with large values of Λ indicating departure from H
0
.
Example. Suppose that
X
1
, ··· , X
n
are iid
N
(
µ, σ
2
0
), with
σ
2
0
known, and we
wish to test
H
0
:
µ
=
µ
0
against
H
1
:
µ
=
µ
0
(for given constant
µ
0
). Here
Θ
0
= {µ
0
} and Θ = R.
For the numerator, we have
sup
Θ
f
(x
| µ
) =
f
(x
| ˆµ
), where
ˆµ
is the mle.
We know that ˆµ = ¯x. Hence
Λ
x
(H
0
; H
1
) =
(2πσ
2
0
)
−n/2
exp
−
1
2σ
2
0
P
(x
i
− ¯x)
2
(2πσ
2
0
)
−n/2
exp
−
1
2σ
2
0
P
(x
i
− µ
0
)
2
.
Then H
0
is rejected if Λ
x
is large.
To make our lives easier, we can use the logarithm instead:
2 log Λ(H
0
; H
1
) =
1
σ
2
0
h
X
(x
i
− µ
0
)
2
−
X
(x
i
− ¯x)
2
i
=
n
σ
2
0
(¯x − µ
0
)
2
.
So we can reject H
0
if we have
√
n(¯x − µ
0
)
σ
0
> c
for some c.
We know that under
H
0
,
Z
=
√
n(
¯
X − µ
0
)
σ
0
∼ N
(0
,
1). So the size
α
generalised likelihood test rejects H
0
if
√
n(¯x − µ
0
)
σ
0
> z
α/2
.
Alternatively, since
n(
¯
X − µ
0
)
2
σ
2
0
∼ χ
2
1
, we reject H
0
if
n(¯x − µ
0
)
2
σ
2
0
> χ
2
1
(α),
(check that z
2
α/2
= χ
2
1
(α)).
Note that this is a two-tailed test — i.e. we reject
H
0
both for high and low
values of ¯x.
The next theorem allows us to use likelihood ratio tests even when we cannot
find the exact relevant null distribution.
First consider the “size” or “dimension” of our hypotheses: suppose that
H
0
imposes
p
independent restrictions on Θ. So for example, if Θ =
{θ
:
θ
=
(θ
1
, ··· , θ
k
)}, and we have
– H
0
: θ
i
1
= a
1
, θ
i
2
= a
2
, ··· , θ
i
p
= a
p
; or
– H
0
: Aθ = b (with A p × k, b p × 1 given); or
– H
0
: θ
i
= f
i
(φ), i = 1, ··· , k for some φ = (φ
1
, ··· , φ
k−p
).
We say Θ has
k
free parameters and Θ
0
has
k − p
free parameters. We write
|Θ
0
| = k − p and |Θ| = k.
Theorem (Generalized likelihood ratio theorem). Suppose Θ
0
⊆
Θ
1
and
|
Θ
1
|−
|Θ
0
| = p. Let X = (X
1
, ··· , X
n
) with all X
i
iid. If H
0
is true, then as n → ∞,
2 log Λ
X
(H
0
; H
1
) ∼ χ
2
p
.
If
H
0
is not true, then 2
log
Λ tends to be larger. We reject
H
0
if 2
log
Λ
> c
,
where c = χ
2
p
(α) for a test of approximately size α.
We will not prove this result here. In our example above,
|
Θ
1
| − |
Θ
0
|
= 1,
and in this case, we saw that under
H
0
, 2
log
Λ
∼ χ
2
1
exactly for all
n
in that
particular case, rather than just approximately.
2.3 Tests of goodness-of-fit and independence
2.3.1 Goodness-of-fit of a fully-specified null distribution
So far, we have considered relatively simple cases where we are attempting to
figure out, say, the mean. However, in reality, more complicated scenarios arise.
For example, we might want to know if a dice is fair, i.e. if the probability of
getting each number is exactly
1
6
. Our null hypothesis would be that
p
1
=
p
2
=
··· = p
6
=
1
6
, while the alternative hypothesis allows any possible values of p
i
.
In general, suppose the observation space
X
is partitioned into
k
sets, and
let
p
i
be the probability that an observation is in set
i
for
i
= 1
, ··· , k
. We want
to test “
H
0
: the
p
i
’s arise from a fully specified model” against “
H
1
: the
p
i
’s
are unrestricted (apart from the obvious p
i
≥ 0,
P
p
i
= 1)”.
Example. The following table lists the birth months of admissions to Oxford
and Cambridge in 2012.
Sep Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug
470 515 470 457 473 381 466 457 437 396 384 394
Is this compatible with a uniform distribution over the year?
Out of
n
independent observations, let
N
i
be the number of observations in
ith set. So (N
1
, ··· , N
k
) ∼ multinomial(k; p
1
, ··· , p
k
).
For a generalized likelihood ratio test of
H
0
, we need to find the maximised
likelihood under H
0
and H
1
.
Under
H
1
,
like
(
p
1
, ··· , p
k
)
∝ p
n
1
1
···p
n
k
k
. So the log likelihood is
l
=
constant
+
P
n
i
log p
i
. We want to maximise this subject to
P
p
i
= 1. Us-
ing the Lagrange multiplier, we will find that the mle is
ˆp
i
=
n
i
/n
. Also
|Θ
1
| = k − 1 (not k, since they must sum up to 1).
Under
H
0
, the values of
p
i
are specified completely, say
p
i
=
˜p
i
. So
|
Θ
0
|
= 0.
Using our formula for ˆp
i
, we find that
2 log Λ = 2 log
ˆp
n
1
1
··· ˆp
n
k
k
˜p
n
1
1
··· ˜p
n
k
k
= 2
X
n
i
log
n
i
n˜p
i
(1)
Here
|
Θ
1
|−|
Θ
0
|
=
k−
1. So we reject
H
0
if 2
log
Λ
> χ
2
k−1
(
α
) for an approximate
size α test.
Under
H
0
(no effect of month of birth),
˜p
i
is the proportion of births in
month
i
in 1993/1994 in the whole population — this is not simply proportional
to the number of days in each month (or even worse,
1
12
), as there is for example
an excess of September births (the “Christmas effect”). Then
2 log Λ = 2
X
n
i
log
n
i
n˜p
i
= 44.86.
P
(
χ
2
11
>
44
.
86) = 3
×
10
−9
, which is our
p
-value. Since this is certainly less than
0.001, we can reject
H
0
at the 0
.
1% level, or can say the result is “significant at
the 0.1% level”.
The traditional levels for comparison are
α
= 0
.
05
,
0
.
01
,
0
.
001, roughly
corresponding to “evidence”, “strong evidence” and “very strong evidence”.
A similar common situation has
H
0
:
p
i
=
p
i
(
θ
) for some parameter
θ
and
H
1
as before. Now
|
Θ
0
|
is the number of independent parameters to be estimated
under H
0
.
Under H
0
, we find mle
ˆ
θ by maximizing n
i
log p
i
(θ), and then
2 log Λ = 2 log
ˆp
1
n
1
··· ˆp
k
n
k
p
1
(
ˆ
θ)
n
1
···p
k
(
ˆ
θ)
n
k
!
= 2
X
n
i
log
n
i
np
i
(
ˆ
θ)
!
. (2)
The degrees of freedom are k − 1 − |Θ
0
|.
2.3.2 Pearson’s chi-squared test
Notice that the two log likelihoods are of the same form. In general, let
o
i
=
n
i
(observed number) and let
e
i
=
n ˜p
i
or
np
i
(
ˆ
θ
) (expected number). Let
δ
i
=
o
i
−e
i
.
Then
2 log Λ = 2
X
o
i
log
o
i
e
i
= 2
X
(e
i
+ δ
i
) log
1 +
δ
i
e
i
= 2
X
(e
i
+ δ
i
)
δ
i
e
i
−
δ
2
i
2e
2
i
+ O(δ
3
i
)
= 2
X
δ
i
+
δ
2
i
e
i
−
δ
2
i
2e
i
+ O(δ
3
i
)
We know that
P
δ
i
= 0 since
P
e
i
=
P
o
i
. So
≈
X
δ
2
i
e
i
=
X
(o
i
− e
i
)
2
e
i
.
This is known as the Pearson’s chi-squared test.
Example. Mendel crossed 556 smooth yellow male peas with wrinkled green
peas. From the progeny, let
(i) N
1
be the number of smooth yellow peas,
(ii) N
2
be the number of smooth green peas,
(iii) N
3
be the number of wrinkled yellow peas,
(iv) N
4
be the number of wrinkled green peas.
We wish to test the goodness of fit of the model
H
0
: (p
1
, p
2
, p
3
, p
4
) =
9
16
,
3
16
,
3
16
,
1
16
.
Suppose we observe (n
1
, n
2
, n
3
, n
4
) = (315, 108, 102, 31).
We find (
e
1
, e
2
, e
3
, e
4
) = (312
.
75
,
104
.
25
,
104
.
25
,
34
.
75). The actual 2
log
Λ =
0.618 and the approximation we had is
P
(o
i
−e
i
)
2
e
i
= 0.604.
Here |Θ
0
| = 0 and |Θ
1
| = 4 − 1 = 3. So we refer to test statistics χ
2
3
(α).
Since
χ
2
3
(0
.
05) = 7
.
815, we see that neither value is significant at 5%. So
there is no evidence against Mendel’s theory. In fact, the
p
-value is approximately
P
(
χ
2
3
>
0
.
6)
≈
0
.
90. This is a really good fit, so good that people suspect the
numbers were not genuine.
Example. In a genetics problem, each individual has one of the three possible
genotypes, with probabilities
p
1
, p
2
, p
3
. Suppose we wish to test
H
0
:
p
i
=
p
i
(
θ
),
where
p
1
(θ) = θ
2
, p
2
= 2θ(1 − θ), p
3
(θ) = (1 − θ)
2
.
for some θ ∈ (0, 1).
We observe N
i
= n
i
. Under H
0
, the mle
ˆ
θ is found by maximising
X
n
i
log p
i
(θ) = 2n
1
log θ + n
2
log(2θ(1 − θ)) + 2n
3
log(1 −θ).
We find that
ˆ
θ =
2n
1
+n
2
2n
. Also, |Θ
0
| = 1 and |Θ
1
| = 2.
After conducting an experiment, we can substitute
p
i
(
ˆ
θ
) into (2), or find the
corresponding Pearson’s chi-squared statistic, and refer to χ
2
1
.
2.3.3 Testing independence in contingency tables
Definition (Contingency table). A contingency table is a table in which obser-
vations or individuals are classified according to one or more criteria.
Example. 500 people with recent car changes were asked about their previous
and new cars. The results are as follows:
New car
Large Medium Small
Previous
car
Large 56 52 42
Medium 50 83 67
Small 18 51 81
This is a two-way contingency table: Each person is classified according to the
previous car size and new car size.
Consider a two-way contingency table with
r
rows and
c
columns. For
i
= 1
, ··· , r
And
j
= 1
, ··· , c
, let
p
ij
be the probability that an individual
selected from the population under consideration is classified in row
i
and
column j. (i.e. in the (i, j) cell of the table).
Let
p
i+
=
P
(
in row i
) and
p
+j
=
P
(
in column j
). Then we must have
p
++
=
P
i
P
j
p
ij
= 1.
Suppose a random sample of
n
individuals is taken, and let
n
ij
be the number
of these classified in the (i, j) cell of the table.
Let n
i+
=
P
j
n
ij
and n
+j
=
P
i
n
ij
. So n
++
= n.
We have
(N
11
, ··· , N
1c
, N
21
, ··· , N
rc
) ∼ multinomial(rc; p
11
, ··· , p
1c
, p
21
, ··· , p
rc
).
We may be interested in testing the null hypothesis that the two classifications
are independent. So we test
– H
0
: p
ij
= p
i+
p
+j
for all i, j, i.e. independence of columns and rows.
– H
1
: p
ij
are unrestricted.
Of course we have the usual restrictions like p
++
= 1, p
ij
≥ 0.
Under H
1
, the mles are ˆp
ij
=
n
ij
n
.
Under H
0
, the mles are ˆp
i+
=
n
i+
n
and ˆp
+j
=
n
+j
n
.
Write o
ij
= n
ij
and e
ij
= nˆp
i+
ˆp
+j
= n
i+
n
+j
/n.
Then
2 log Λ = 2
r
X
i=1
c
X
j=1
o
ij
log
o
ij
e
ij
≈
r
X
i=1
c
X
j=1
(o
ij
− e
ij
)
2
e
ij
.
using the same approximating steps for Pearson’s Chi-squared test.
We have
|
Θ
1
|
=
rc −
1, because under
H
1
the
p
ij
’s sum to one. Also,
|
Θ
0
|
= (
r −
1) + (
c −
1) because
p
1+
, ··· , p
r+
must satisfy
P
i
p
i+
= 1 and
p
+1
, ··· , p
+c
must satisfy
P
j
p
+j
= 1. So
|Θ
1
| − |Θ
0
| = rc − 1 − (r − 1) −(c − 1) = (r −1)(c − 1).
Example. In our previous example, we wish to test
H
0
: the new and previous
car sizes are independent. The actual data is:
New car
Large Medium Small Total
Previous
car
Large 56 52 42 150
Medium 50 83 67 120
Small 18 51 81 150
Total 124 186 190 500
while the expected values given by H
0
is
New car
Large Medium Small Total
Previous
car
Large 37.2 55.8 57.0 150
Medium 49.6 74.4 76.0 120
Small 37.2 55.8 57.0 150
Total 124 186 190 500
Note the margins are the same. It is quite clear that they do not match well,
but we can find the p value to be sure.
XX
(o
ij
− e
ij
)
2
e
ij
= 36
.
20, and the degrees of freedom is (3
−
1)(3
−
1) = 4.
From the tables, χ
2
4
(0.05) = 9.488 and χ
2
4
(0.01) = 13.28.
So our observed value of 36.20 is significant at the 1% level, i.e. there is
strong evidence against H
0
. So we conclude that the new and present car sizes
are not independent.
2.4
Tests of homogeneity, and connections to confidence
intervals
2.4.1 Tests of homogeneity
Example. 150 patients were randomly allocated to three groups of 50 patients
each. Two groups were given a new drug at different dosage levels, and the third
group received a placebo. The responses were as shown in the table below.
Improved No difference Worse Total
Placebo 18 17 15 50
Half dose 20 10 20 50
Full dose 25 13 12 50
Total 63 40 47 150
Here the row totals are fixed in advance, in contrast to our last section, where
the row totals are random variables.
For the above, we may be interested in testing
H
0
: the probability of
“improved” is the same for each of the three treatment groups, and so are
the probabilities of “no difference” and “worse”, i.e.
H
0
says that we have
homogeneity down the rows.
In general, we have independent observations from
r
multinomial distributions,
each of which has
c
categories, i.e. we observe an
r ×c
table (
n
ij
), for
i
= 1
, ··· , r
and j = 1, ··· , c, where
(N
i1
, ··· , N
ic
) ∼ multinomial(n
i+
, p
i1
, ··· , p
ic
)
independently for each i = 1, ··· , r. We want to test
H
0
: p
1j
= p
2j
= ··· = p
rj
= p
j
,
for j = 1, ··· , c, and
H
1
: p
ij
are unrestricted.
Using H
1
, for any matrix of probabilities (p
ij
),
like((p
ij
)) =
r
Y
i=1
n
i+
!
n
i1
! ···n
ic
!
p
n
i1
i1
···p
n
ic
ic
,
and
log like = constant +
r
X
i=1
c
X
j=1
n
ij
log p
ij
.
Using Lagrangian methods, we find that ˆp
ij
=
n
ij
n
i+
.
Under H
0
,
log like = constant +
c
X
j=1
n
+j
log p
j
.
By Lagrangian methods, we have ˆp
j
=
n
+j
n
++
.
Hence
2 log Λ =
r
X
i=1
c
X
j=1
n
ij
log
ˆp
ij
ˆp
j
= 2
r
X
i=1
c
X
j=1
n
ij
log
n
ij
n
i+
n
+j
/n
++
,
which is the same as what we had last time, when the row totals are unrestricted!
We have
|
Θ
1
|
=
r
(
c −
1) and
|
Θ
0
|
=
c −
1. So the degrees of freedom is
r
(
c −
1)
−
(
c −
1) = (
r −
1)(
c −
1), and under
H
0
, 2
log
Λ is approximately
χ
2
(r−1)(c−1)
. Again, it is exactly the same as what we had last time!
We reject H
0
if 2 log Λ > χ
2
(r−1)(c−1)
(α) for an approximate size α test.
If we let
o
ij
=
n
ij
, e
ij
=
n
i+
n
+j
n
++
, and
δ
ij
=
o
ij
− e
ij
, using the same approxi-
mating steps as for Pearson’s chi-squared, we obtain
2 log Λ ≈
X
(o
ij
− e
ij
)
2
e
ij
.
Example. Continuing our previous example, our data is
Improved No difference Worse Total
Placebo 18 17 15 50
Half dose 20 10 20 50
Full dose 25 13 12 50
Total 6 3 40 47 150
The expected under H
0
is
Improved No difference Worse Total
Placebo 21 13.3 15.7 50
Half dose 21 13.3 15.7 50
Full dose 21 13.3 15.7 50
Total 63 40 47 150
We find 2
log
Λ = 5
.
129, and we refer this to
χ
2
4
. Clearly this is not significant,
as the mean of
χ
2
4
is 4, and is something we would expect to happen solely by
chance.
We can calculate the
p
-value: from tables,
χ
2
4
(0
.
05) = 9
.
488, so our observed
value is not significant at 5%, and the data are consistent with H
0
.
We conclude that there is no evidence for a difference between the drug at
the given doses and the placebo.
For interest,
X
(o
ij
− e
ij
)
2
e
ij
= 5.173,
giving the same conclusion.
2.4.2 Confidence intervals and hypothesis tests
Confidence intervals or sets can be obtained by inverting hypothesis tests, and
vice versa
Definition (Acceptance region). The acceptance region
A
of a test is the
complement of the critical region C.
Note that when we say “acceptance”, we really mean “non-rejection”! The
name is purely for historical reasons.
Theorem (Duality of hypothesis tests and confidence intervals). Suppose
X
1
, ··· , X
n
have joint pdf f
X
(x | θ) for θ ∈ Θ.
(i)
Suppose that for every
θ
0
∈
Θ there is a size
α
test of
H
0
:
θ
=
θ
0
. Denote
the acceptance region by
A
(
θ
0
). Then the set
I
(X) =
{θ
: X
∈ A
(
θ
)
}
is a
100(1 − α)% confidence set for θ.
(ii)
Suppose
I
(X) is a 100(1
− α
)% confidence set for
θ
. Then
A
(
θ
0
) =
{
X :
θ
0
∈ I(X)} is an acceptance region for a size α test of H
0
: θ = θ
0
.
Intuitively, this says that “confidence intervals” and “hypothesis accep-
tance/rejection” are the same thing. After gathering some data X, we can
produce a, say, 95% confidence interval (
a, b
). Then if we want to test the
hypothesis H
0
: θ = θ
0
, we simply have to check whether θ
0
∈ (a, b).
On the other hand, if we have a test for
H
0
:
θ
=
θ
0
, then the confidence
interval is all θ
0
in which we would accept H
0
: θ = θ
0
.
Proof. First note that θ
0
∈ I(X) iff X ∈ A(θ
0
).
For (i), since the test is size α, we have
P(accept H
0
| H
0
is true) = P(X ∈ A(θ
0
) | θ = θ
0
) = 1 − α.
And so
P(θ
0
∈ I(X) | θ = θ
0
) = P(X ∈ A(θ
0
) | θ = θ
0
) = 1 − α.
For (ii), since I(X) is a 100(1 −α)% confidence set, we have
P (θ
0
∈ I(X) | θ = θ
0
) = 1 − α.
So
P(X ∈ A(θ
0
) | θ = θ
0
) = P(θ ∈ I(X) | θ = θ
0
) = 1 − α.
Example. Suppose
X
1
, ··· , X
n
are iid
N
(
µ,
1) random variables and we want
a 95% confidence set for µ.
One way is to use the theorem and find the confidence set that belongs to the
hypothesis test that we found in the previous example. We find a test of size 0.05
of
H
0
:
µ
=
µ
0
against
H
1
:
µ
=
µ
0
that rejects
H
0
when
|
√
n
(
¯x − µ
0
)
| >
1
.
96
(where 1.96 is the upper 2.5% point of N(0, 1)).
Then
I
(X) =
{µ
: X
∈ A
(
µ
)
}
=
{µ
:
|
√
n
(
¯
X − µ
)
| <
1
.
96
}
. So a 95%
confidence set for µ is (
¯
X − 1.96/
√
n,
¯
X + 1.96/
√
n).
2.5 Multivariate normal theory
2.5.1 Multivariate normal distribution
So far, we have only worked with scalar random variables or a vector of iid random
variables. In general, we can have a random (column) vector X = (
X
1
, ··· , X
n
)
T
,
where the X
i
are correlated.
The mean of this vector is given by
µ = E[X] = (E(X
1
), ··· , E(X
n
))
T
= (µ
1
, ··· , µ
n
)
T
.
Instead of just the variance, we have the covariance matrix
cov(X) = E[(X − µ)(X −µ)
T
] = (cov(X
i
, X
j
))
ij
,
provided they exist, of course.
We can multiply the vector X by an m × n matrix A. Then we have
E[AX] = Aµ,
and
cov(AX) = A cov(X)A
T
. (∗)
The last one comes from
cov(AX) = E[(AX − E[AX])(AX −E[AX])
T
]
= E[A(X − EX)(X − EX)
T
A
T
]
= AE[(X − EX)(X − EX)
T
]A
T
.
If we have two random vectors V
,
W, we can define the covariance
cov
(V
,
W)
to be a matrix with (
i, j
)th element
cov
(
V
i
, W
j
). Then
cov
(
A
X
, B
X) =
A cov(X)B
T
.
An important distribution is a multivariate normal distribution.
Definition (Multivariate normal distribution). X has a multivariate normal
distribution if, for every t
∈ R
n
, the random variable t
T
X (i.e. t
·
X) has a
normal distribution. If E[X] = µ and cov(X) = Σ, we write X ∼ N
n
(µ, Σ).
Note that Σ is symmetric and is positive semi-definite because by (∗),
t
T
Σt = var(t
T
X) ≥ 0.
So what is the pdf of a multivariate normal? And what is the moment generating
function? Recall that a (univariate) normal X ∼ N(µ, σ
2
) has density
f
X
(x; µ, σ
2
) =
1
√
2πσ
exp
−
1
2
(x − µ)
2
σ
2
,
with moment generating function
M
X
(s) = E[e
sX
] = exp
µs +
1
2
σ
2
s
2
.
Hence for any t, the moment generating function of t
T
X is given by
M
t
T
X
(s) = E[e
st
T
X
] = exp
t
T
µs +
1
2
t
T
Σts
2
.
Hence X has mgf
M
X
(t) = E[e
t
T
X
] = M
t
T
X
(1) = exp
t
T
µ +
1
2
t
T
Σt
. (†)
Proposition.
(i)
If X
∼ N
n
(
µ,
Σ), and
A
is an
m × n
matrix, then
A
X
∼ N
m
(
Aµ, A
Σ
A
T
).
(ii) If X ∼ N
n
(0, σ
2
I), then
|X|
2
σ
2
=
X
T
X
σ
2
=
X
X
2
i
σ
2
∼ χ
2
n
.
Instead of writing |X|
2
/σ
2
∼ χ
2
n
, we often just say |X|
2
∼ σ
2
χ
2
n
.
Proof.
(i) See example sheet 3.
(ii) Immediate from definition of χ
2
n
.
Proposition. Let X
∼ N
n
(
µ,
Σ). We split X up into two parts: X =
X
1
X
2
,
where X
i
is a n
i
× 1 column vector and n
1
+ n
2
= n.
Similarly write
µ =
µ
1
µ
2
, Σ =
Σ
11
Σ
12
Σ
21
Σ
22
,
where Σ
ij
is an n
i
× n
j
matrix.
Then
(i) X
i
∼ N
n
i
(µ
i
, Σ
ii
)
(ii) X
1
and X
2
are independent iff Σ
12
= 0.
Proof.
(i) See example sheet 3.
(ii) Note that by symmetry of Σ, Σ
12
= 0 if and only if Σ
21
= 0.
From (
†
),
M
X
(t) =
exp
(t
T
µ
+
1
2
t
T
Σt) for each t
∈ R
n
. We write t =
t
1
t
2
.
Then the mgf is equal to
M
X
(t) =
exp
t
T
1
µ
1
+ t
T
2
µ
2
+ t
T
1
Σ
11
t
1
+
1
2
t
T
2
Σ
22
t
2
+
1
2
t
T
1
Σ
12
t
2
+
1
2
t
T
2
Σ
21
t
1
.
From (i), we know that
M
X
i
(t
i
) =
exp
(t
T
i
µ
i
+
1
2
t
T
i
Σ
ii
t
i
). So
M
X
(t) =
M
X
1
(t
1
)M
X
2
(t
2
) for all t if and only if Σ
12
= 0.
Proposition. When Σ is a positive definite, then X has pdf
f
X
(x; µ, Σ) =
1
|Σ|
2
1
√
2π
n
exp
−
1
2
(x − µ)
T
Σ
−1
(x − µ)
.
Note that Σ is always positive semi-definite. The conditions just forbid the
case |Σ| = 0, since this would lead to dividing by zero.
2.5.2 Normal random samples
We wish to use our knowledge about multivariate normals to study univariate
normal data. In particular, we want to prove the following:
Theorem (Joint distribution of
¯
X
and
S
XX
). Suppose
X
1
, ··· , X
n
are iid
N(µ, σ
2
) and
¯
X =
1
n
P
X
i
, and S
XX
=
P
(X
i
−
¯
X)
2
. Then
(i)
¯
X ∼ N(µ, σ
2
/n)
(ii) S
XX
/σ
2
∼ χ
2
n−1
.
(iii)
¯
X and S
XX
are independent.
Proof.
We can write the joint density as X
∼ N
n
(
µ, σ
2
I
), where
µ
=
(µ, µ, ··· , µ).
Let
A
be an
n × n
orthogonal matrix with the first row all 1
/
√
n
(the other
rows are not important). One possible such matrix is
A =
1
√
n
1
√
n
1
√
n
1
√
n
···
1
√
n
1
√
2×1
−1
√
2×1
0 0 ··· 0
1
√
3×2
1
√
3×2
−2
√
3×2
0 ··· 0
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
√
n(n−1)
1
√
n(n−1)
1
√
n(n−1)
1
√
n(n−1)
···
−(n−1)
√
n(n−1)
Now define Y = AX. Then
Y ∼ N
n
(Aµ, Aσ
2
IA
T
) = N
n
(Aµ, σ
2
I).
We have
Aµ = (
√
nµ, 0, ··· , 0)
T
.
So
Y
1
∼ N
(
√
nµ, σ
2
) and
Y
i
∼ N
(0
, σ
2
) for
i
= 2
, ··· , n
. Also,
Y
1
, ··· , Y
n
are
independent, since the covariance matrix is every non-diagonal term 0.
But from the definition of A, we have
Y
1
=
1
√
n
n
X
i=1
X
i
=
√
n
¯
X.
So
√
n
¯
X ∼ N(
√
nµ, σ
2
), or
¯
X ∼ N(µ, σ
2
/n). Also
Y
2
2
+ ··· + Y
2
n
= Y
T
Y − Y
2
1
= X
T
A
T
AX − Y
2
1
= X
T
X − n
¯
X
2
=
n
X
i=1
X
2
i
− n
¯
X
2
=
n
X
i=1
(X
i
−
¯
X)
2
= S
XX
.
So S
XX
= Y
2
2
+ ··· + Y
2
n
∼ σ
2
χ
2
n−1
.
Finally, since Y
1
and Y
2
, ··· , Y
n
are independent, so are
¯
X and S
XX
.
2.6 Student’s t-distribution
Definition (
t
-distribution). Suppose that
Z
and
Y
are independent,
Z ∼ N
(0
,
1)
and Y ∼ χ
2
k
. Then
T =
Z
p
Y/k
is said to have a t-distribution on k degrees of freedom, and we write T ∼ t
k
.
The density of t
k
turns out to be
f
T
(t) =
Γ((k + 1)/2)
Γ(k/2)
1
√
πk
1 +
t
2
k
−(k+1)/2
.
This density is symmetric, bell-shaped, and has a maximum at
t
= 0, which
is rather like the standard normal density. However, it can be shown that
P
(
T > t
)
> P
(
Z > t
), i.e. the
T
distribution has a “fatter” tail. Also, as
k → ∞
,
t
k
approaches a normal distribution.
Proposition. If k > 1, then E
k
(T ) = 0.
If k > 2, then var
k
(T ) =
k
k−2
.
If k = 2, then var
k
(T ) = ∞.
In all other cases, the values are undefined. In particular, the
k
= 1 case has
undefined mean and variance. This is known as the Cauchy distribution.
Notation. We write
t
k
(
α
) be the upper 100
α
% point of the
t
k
distribution, so
that P(T > t
k
(α)) = α.
Why would we define such a weird distribution? The typical application is
to study random samples with unknown mean and unknown variance.
Let
X
1
, ··· , X
n
be iid
N
(
µ, σ
2
). Then
¯
X ∼ N
(
µ, σ
2
/n
). So
Z
=
√
n(
¯
X−µ)
σ
∼
N(0, 1).
Also, S
XX
/σ
2
∼ χ
2
n−1
and is independent of
¯
X, and hence Z. So
√
n(
¯
X − µ)/σ
p
S
XX
/((n − 1)σ
2
)
∼ t
n−1
,
or
√
n(
¯
X − µ)
p
S
XX
/(n − 1)
∼ t
n−1
.
We write
˜σ
2
=
S
XX
n−1
(note that this is the unbiased estimator). Then a 100(1
−α
)%
confidence interval for µ is found from
1 − α = P
−t
n−1
α
2
≤
√
n(
¯
X − µ)
˜σ
≤ t
n−1
α
2
.
This has endpoints
¯
X ±
˜σ
√
n
t
n−1
α
2
.
3 Linear models
3.1 Linear models
Linear models can be used to explain or model the relationship between a
response (or dependent) variable, and one or more explanatory variables (or
covariates or predictors). As the name suggests, we assume the relationship is
linear.
Example. How do motor insurance claim rates (response) depend on the age
and sex of the driver, and where they live (explanatory variables)?
It is important to note that (unless otherwise specified), we do not assume
normality in our calculations here.
Suppose we have
p
covariates
x
j
, and we have
n
observations
Y
i
. We assume
n > p
, or else we can pick the parameters to fix our data exactly. Then each
observation can be written as
Y
i
= β
1
x
i1
+ ··· + β
p
x
ip
+ ε
i
. ((*))
for i = 1, ··· , n. Here
– β
1
, ··· , β
p
are unknown, fixed parameters we wish to work out (with
n > p
)
– x
i1
, ··· , x
ip
are the values of the
p
covariates for the
i
th response (which
are all known).
– ε
1
, ··· , ε
n
are independent (or possibly just uncorrelated) random variables
with mean 0 and variance σ
2
.
We think of the
β
j
x
ij
terms to be the causal effects of
x
ij
and
ε
i
to be a random
fluctuation (error term).
Then we clearly have
– E(Y
i
) = β
1
x
i1
+ ···β
p
x
ip
.
– var(Y
i
) = var(ε
i
) = σ
2
.
– Y
1
, ··· , Y
n
are independent.
Note that (
∗
) is linear in the parameters
β
1
, ··· , β
p
. Obviously the real world
can be much more complicated. But this is much easier to work with.
Example. For each of 24 males, the maximum volume of oxygen uptake in the
blood and the time taken to run 2 miles (in minutes) were measured. We want
to know how the time taken depends on oxygen uptake.
We might get the results
Oxygen 42.3 53.1 42.1 50.1 42.5 42.5 47.8 49.9
Time 918 805 892 962 968 907 770 743
Oxygen 36.2 49.7 41.5 46.2 48.2 43.2 51.8 53.3
Time 1045 810 927 813 858 860 760 747
Oxygen 53.3 47.2 56.9 47.8 48.7 53.7 60.6 56.7
Time 743 803 683 844 755 700 748 775
For each individual
i
, we let
Y
i
be the time to run 2 miles, and
x
i
be the maximum
volume of oxygen uptake,
i
= 1
, ··· ,
24. We might want to fit a straight line to
it. So a possible model is
Y
i
= a + bx
i
+ ε
i
,
where
ε
i
are independent random variables with variance
σ
2
, and
a
and
b
are
constants.
The subscripts in the equation makes it tempting to write them as matrices:
Y =
Y
1
.
.
.
Y
n
, X =
x
11
··· x
1p
.
.
.
.
.
.
.
.
.
x
n1
··· x
np
.
, β =
β
1
.
.
.
β
p
, ε =
ε
1
.
.
.
ε
n
Then the equation becomes
Y = Xβ + ε. (2)
We also have
– E(ε) = 0.
– cov(Y) = σ
2
I.
We assume throughout that
X
has full rank
p
, i.e. the columns are independent,
and that the error variance is the same for each observation. We say this is the
homoscedastic case, as opposed to heteroscedastic.
Example. Continuing our example, we have, in matrix form
Y =
Y
1
.
.
.
Y
24
, X =
1 x
1
.
.
.
.
.
.
1 x
24
, β =
a
b
, ε =
ε
1
.
.
.
ε
24
.
Then
Y = Xβ + ε.
Definition (Least squares estimator). In a linear model Y =
Xβ
+
ε
, the least
squares estimator
ˆ
β of β minimizes
S(β) = ∥Y − Xβ∥
2
= (Y − Xβ)
T
(Y − Xβ)
=
n
X
i=1
(Y
i
− x
ij
β
j
)
2
with implicit summation over j.
If we plot the points on a graph, then the least square estimators minimizes
the (square of the) vertical distance between the points and the line.
To minimize it, we want
∂S
∂β
k
β=
ˆ
β
= 0
for all k. So
−2x
ik
(Y
i
− x
ij
ˆ
β
j
) = 0
for each k (with implicit summation over i and j), i.e.
x
ik
x
ij
ˆ
β
j
= x
ik
Y
i
for all k. Putting this back in matrix form, we have
Proposition. The least squares estimator satisfies
X
T
X
ˆ
β = X
T
Y. (3)
We could also have derived this by completing the square of (Y
−Xβ
)
T
(Y
−
Xβ), but that would be more complicated.
In order to find
ˆ
β
, our life would be much easier if
X
T
X
has an inverse.
Fortunately, it always does. We assumed that X is of full rank p. Then
tX
T
Xt = (Xt)
T
(Xt) = ∥Xt∥
2
> 0
for t
= 0 in
R
p
(the last inequality is since if there were a t such that
∥X
t
∥
= 0,
then we would have produced a linear combination of the columns of
X
that
gives 0). So X
T
X is positive definite, and hence has an inverse. So
ˆ
β = (X
T
X)
−1
X
T
Y, (4)
which is linear in Y .
We have
E(
ˆ
β) = (X
T
X
−1
)X
T
E[Y] = (X
T
X)
−1
X
T
Xβ = β.
So
ˆ
β is an unbiased estimator for β. Also
cov(
ˆ
β) = (X
T
X)
−1
X
T
cov(Y)X(X
T
X)
−1
= σ
2
(X
T
X)
−1
, (5)
since cov Y = σ
2
I.
3.2 Simple linear regression
What we did above was so complicated. If we have a simple linear regression
model
Y
i
= a + bx
i
+ ε
i
.
then we can reparameterise it to
Y
i
= a
′
+ b(x
i
− ¯x) + ε
i
, (6)
where
¯x
=
P
x
i
/n
and
a
′
=
a
+
b¯x
. Since
P
(
x
i
− ¯x
) = 0, this leads to simplified
calculations.
In matrix form,
X =
1 (x
1
− ¯x)
.
.
.
.
.
.
1 (x
24
− ¯x)
.
Since
P
(x
i
− ¯x) = 0, in X
T
X, the off-diagonals are all 0, and we have
X
T
X =
n 0
0 S
xx
,
where S
xx
=
P
(x
i
− ¯x)
2
.
Hence
(X
T
X)
−1
=
1
n
0
0
1
S
xx
So
ˆ
β = (X
T
X
−1
)X
T
Y =
¯
Y
S
xY
S
xx
,
where S
xY
=
P
Y
i
(x
i
− ¯x).
Hence the estimated intercept is ˆa
′
= ¯y, and the estimated gradient is
ˆ
b =
S
xy
S
xx
=
P
i
y
i
(x
i
− ¯x)
P
i
(x
i
− ¯x)
2
=
P
i
(y
i
− ¯y)(x
i
− ¯x)
p
P
i
(x
i
− ¯x)
2
P
i
(y
i
− ¯y)
2
×
r
S
yy
S
xx
(∗)
= r ×
r
S
yy
S
xx
.
We have (
∗
) since
P
¯y
(
x
i
− ¯x
) = 0, so we can add it to the numerator. Then the
other square root things are just multiplying and dividing by the same things.
So the gradient is the Pearson product-moment correlation coefficient
r
times
the ratio of the empirical standard deviations of the
y
’s and
x
’s (note that the
gradient is the same whether the x’s are standardised to have mean 0 or not).
Hence we get
cov
(
ˆ
β
) = (
X
T
X
)
−1
σ
2
, and so from our expression of (
X
T
X
)
−1
,
var(ˆa
′
) = var(
¯
Y ) =
σ
2
n
, var(
ˆ
b) =
σ
2
S
xx
.
Note that these estimators are uncorrelated.
Note also that these are obtained without any explicit distributional assump-
tions.
Example. Continuing our previous oxygen/time example, we have
¯y
= 826
.
5,
S
xx
= 783.5 = 28.0
2
, S
xy
= −10077, S
yy
= 444
2
, r = −0.81,
ˆ
b = −12.9.
Theorem (Gauss Markov theorem). In a full rank linear model, let
ˆ
β
be the
least squares estimator of
β
and let
β
∗
be any other unbiased estimator for
β
which is linear in the Y
i
’s. Then
var(t
T
ˆ
β) ≤ var(t
T
β
∗
).
for all t
∈ R
p
. We say that
ˆ
β
is the best linear unbiased estimator of
β
(BLUE).
Proof. Since β
∗
is linear in the Y
i
’s, β
∗
= AY for some p ×n matrix A.
Since
β
∗
is an unbiased estimator, we must have
E
[
β
∗
] =
β
. However, since
β
∗
=
A
Y,
E
[
β
∗
] =
AE
[Y] =
AXβ
. So we must have
β
=
AXβ
. Since this
holds for any β, we must have AX = I
p
. Now
cov(β
∗
) = E[(β
∗
− β)(β
∗
− β)
T
]
= E[(AY − β)(AY − β)
T
]
= E[(AXβ + Aε − β)(AXβ + Aε − β)
T
]
Since AXβ = β, this is equal to
= E[Aε(Aε)
T
]
= A(σ
2
I)A
T
= σ
2
AA
T
.
Now let β
∗
−
ˆ
β = (A − (X
T
X)
−1
X
T
)Y = BY, for some B. Then
BX = AX − (X
T
X)
−1
X
T
X = I
p
− I
p
= 0.
By definition, we have
A
Y =
B
Y + (
X
T
X
)
−1
X
T
Y, and this is true for all Y.
So A = B + (X
T
X)
−1
X
T
. Hence
cov(β
∗
) = σ
2
AA
T
= σ
2
(B + (X
T
X)
−1
X
T
)(B + (X
T
X)
−1
X
T
)
T
= σ
2
(BB
T
+ (X
T
X)
−1
)
= σ
2
BB
T
+ cov(
ˆ
β).
Note that in the second line, the cross-terms disappear since BX = 0.
So for any t ∈ R
p
, we have
var(t
T
β
∗
) = t
T
cov(β
∗
)t
= t
T
cov(
ˆ
β)t + t
T
BB
T
tσ
2
= var(t
T
ˆ
β) + σ
2
∥B
T
t∥
2
≥ var(t
T
ˆ
β).
Taking t = (0, ··· , 1, 0, ··· , 0)
T
with a 1 in the ith position, we have
var(
ˆ
β
i
) ≤ var(β
∗
i
).
Definition (Fitted values and residuals).
ˆ
Y
=
X
ˆ
β
is the vector of fitted values.
These are what our model says Y should be.
R = Y
−
ˆ
Y
is the vector of residuals. These are the deviations of our model
from reality.
The residual sum of squares is
RSS = ∥R∥
2
= R
T
R = (Y − X
ˆ
β)
T
(Y − X
ˆ
β).
We can give these a geometric interpretation. Note that
X
T
R =
X
T
(Y
−
ˆ
Y
) =
X
T
Y
− X
T
X
ˆ
β
= 0 by our formula for
β
. So R is orthogonal to the
column space of X.
Write
ˆ
Y
=
X
ˆ
β
=
X
(
X
T
X
)
−1
X
T
Y =
P
Y, where
P
=
X
(
X
T
X
)
−1
X
T
.
Then
P
represents an orthogonal projection of
R
n
onto the space spanned by
the columns of
X
, i.e. it projects the actual data Y to the fitted values
ˆ
Y
. Then
R is the part of Y orthogonal to the column space of X.
The projection matrix
P
is idempotent and symmetric, i.e.
P
2
=
P
and
P
T
= P .
3.3 Linear models with normal assumptions
So far, we have not assumed anything about our variables. In particular, we
have not assumed that they are normal. So what further information can we
obtain by assuming normality?
Example. Suppose we want to measure the resistivity of silicon wafers. We
have five instruments, and five wafers were measured by each instrument (so we
have 25 wafers in total). We assume that the silicon wafers are all the same, and
want to see whether the instruments consistent with each other, i.e. The results
are as follows:
Wafer
1 2 3 4 5
Instrument
1 130.5 112.4 118.9 125.7 134.0
2 130.4 138.2 116.7 132.6 104.2
3 113.0 120.5 128.9 103.4 118.1
4 128.0 117.5 114.9 114.9 98.8
5 121.2 110.5 118.5 100.5 120.9
Let
Y
i,j
be the resistivity of the
j
th wafer measured by instrument
i
, where
i, j = 1, ··· , 5. A possible model is
Y
i,j
= µ
i
+ ε
i,j
,
where
ε
ij
are independent random variables such that
E
[
ε
ij
] = 0 and
var
(
ε
ij
) =
σ
2
, and the µ
i
’s are unknown constants.
This can be written in matrix form, with
Y =
Y
1,1
.
.
.
Y
1,5
Y
2,1
.
.
.
Y
2,5
.
.
.
Y
5,1
.
.
.
Y
5,5
, X =
1 0 ··· 0
.
.
.
.
.
.
.
.
.
.
.
.
1 0 ··· 0
0 1 ··· 0
.
.
.
.
.
.
.
.
.
.
.
.
0 1 ··· 0
.
.
.
.
.
.
.
.
.
.
.
.
0 0 ··· 1
.
.
.
.
.
.
.
.
.
.
.
.
0 0 ··· 1
, β =
µ
1
µ
2
µ
3
µ
4
µ
5
, ε =
ε
1,1
.
.
.
ε
1,5
ε
2,1
.
.
.
ε
2,5
.
.
.
ε
5,1
.
.
.
ε
5,5
Then
Y = Xβ + ε.
We have
X
T
X =
5 0 ··· 0
0 5 ··· 0
.
.
.
.
.
.
.
.
.
.
.
.
0 0 ··· 5
Hence
(X
T
X)
−1
=
1
5
0 ··· 0
0
1
5
··· 0
.
.
.
.
.
.
.
.
.
.
.
.
0 0 ···
1
5
So we have
ˆ
µ = (X
T
X)
−1
X
T
Y =
¯
Y
1
.
.
.
¯
Y
5
The residual sum of squares is
RSS =
5
X
i=1
5
X
j=1
(Y
i,j
− ˆµ
i
)
2
=
5
X
i=1
5
X
j=1
(Y
i,j
−
¯
Y
i
)
2
= 2170.
This has
n − p
= 25
−
5 = 20 degrees of freedom. We will later see that
¯σ =
p
RSS/(n − p) = 10.4.
Note that we still haven’t used normality!
We now make a normal assumption:
Y = Xβ + ε, ε ∼ N
n
(0, σ
2
I), rank(X) = p < n.
This is a special case of the linear model we just had, so all previous results hold.
Since Y = N
n
(Xβ, σ
2
I), the log-likelihood is
l(β, σ
2
) = −
n
2
log 2π −
n
2
log σ
2
−
1
2σ
2
S(β),
where
S(β) = (Y − Xβ)
T
(Y − Xβ).
If we want to maximize
l
with respect to
β
, we have to maximize the only term
containing β, i.e. S(β). So
Proposition. Under normal assumptions the maximum likelihood estimator
for a linear model is
ˆ
β = (X
T
X)
−1
X
T
Y,
which is the same as the least squares estimator.
This isn’t coincidence! Historically, when Gauss devised the normal distri-
bution, he designed it so that the least squares estimator is the same as the
maximum likelihood estimator.
To obtain the MLE for σ
2
, we require
∂l
∂σ
2
ˆ
β,ˆσ
2
= 0,
i.e.
−
n
2ˆσ
2
+
S(
ˆ
β)
2ˆσ
4
= 0
So
ˆσ
2
=
1
n
S(
ˆ
β) =
1
n
(Y − X
ˆ
β)
T
(Y − X
ˆ
β) =
1
n
RSS.
Our ultimate goal now is to show that
ˆ
β
and
ˆσ
2
are independent. Then we can
apply our other standard results such as the t-distribution.
First recall that the matrix
P
=
X
(
X
T
X
)
−1
X
T
that projects Y to
ˆ
Y
is
idempotent and symmetric. We will prove the following properties of it:
Lemma.
(i)
If Z
∼ N
n
(0
, σ
2
I
) and
A
is
n × n
, symmetric, idempotent with rank
r
,
then Z
T
AZ ∼ σ
2
χ
2
r
.
(ii) For a symmetric idempotent matrix A, rank(A) = tr(A).
Proof.
(i)
Since
A
is idempotent,
A
2
=
A
by definition. So eigenvalues of
A
are either
0 or 1 (since λx = Ax = A
2
x = λ
2
x).
Since
A
is also symmetric, it is diagonalizable. So there exists an orthogonal
Q such that
Λ = Q
T
AQ = diag(λ
1
, ··· , λ
n
) = diag(1, ··· , 1, 0, ··· , 0)
with r copies of 1 and n − r copies of 0.
Let W =
Q
T
Z. So Z =
Q
W. Then W
∼ N
n
(0
, σ
2
I
), since
cov
(W) =
Q
T
σ
2
IQ = σ
2
I. Then
Z
T
AZ = W
T
Q
T
AQW = W
T
ΛW =
r
X
i=1
w
2
i
∼ χ
2
r
.
(ii)
rank(A) = rank(Λ)
= tr(Λ)
= tr(Q
T
AQ)
= tr(AQ
T
Q)
= tr A
Theorem. For the normal linear model Y ∼ N
n
(Xβ, σ
2
I),
(i)
ˆ
β ∼ N
p
(β, σ
2
(X
T
X)
−1
)
(ii) RSS ∼ σ
2
χ
2
n−p
, and so ˆσ
2
∼
σ
2
n
χ
2
n−p
.
(iii)
ˆ
β and ˆσ
2
are independent.
The proof is not particularly elegant — it is just a whole lot of linear algebra!
Proof.
–
We have
ˆ
β
= (
X
T
X
)
−1
X
T
Y. Call this
C
Y for later use. Then
ˆ
β
has a
normal distribution with mean
(X
T
X)
−1
X
T
(Xβ) = β
and covariance
(X
T
X)
−1
X
T
(σ
2
I)[(X
T
X)
−1
X
T
]
T
= σ
2
(X
T
X)
−1
.
So
ˆ
β ∼ N
p
(β, σ
2
(X
T
X)
−1
).
–
Our previous lemma says that Z
T
A
Z
∼ σ
2
χ
2
r
. So we pick our Z and
A
so
that Z
T
AZ = RSS, and r, the degrees of freedom of A, is n −p.
Let Z = Y
− Xβ
and
A
= (
I
n
− P
), where
P
=
X
(
X
T
X
)
−1
X
T
. We first
check that the conditions of the lemma hold:
Since Y ∼ N
n
(Xβ, σ
2
I), Z = Y − Xβ ∼ N
n
(0, σ
2
I).
Since P is idempotent, I
n
− P also is (check!). We also have
rank(I
n
− P ) = tr(I
n
− P ) = n −p.
Therefore the conditions of the lemma hold.
To get the final useful result, we want to show that the RSS is indeed
Z
T
A
Z. We simplify the expressions of RSS and Z
T
A
Z and show that they
are equal:
Z
T
AZ = (Y − Xβ)
T
(I
n
− P )(Y − Xβ) = Y
T
(I
n
− P )Y.
Noting the fact that (I
n
− P )X = 0.
Writing R = Y −
ˆ
Y = (I
n
− P )Y, we have
RSS = R
T
R = Y
T
(I
n
− P )Y,
using the symmetry and idempotence of I
n
− P .
Hence RSS = Z
T
AZ ∼ σ
2
χ
2
n−p
. Then
ˆσ
2
=
RSS
n
∼
σ
2
n
χ
2
n−p
.
– Let V =
ˆ
β
R
= DY, where D =
C
I
n
− P
is a (p + n) × n matrix.
Since Y is multivariate, V is multivariate with
cov(V ) = Dσ
2
ID
T
= σ
2
CC
T
C(I
n
− P )
T
(I
n
− P )C
T
(I
n
− P )(I
n
− P )
T
= σ
2
CC
T
C(I
n
− P )
(I
n
− P )C
T
(I
n
− P )
= σ
2
CC
T
0
0 I
n
− P
Using
C
(
I
n
−P
) = 0 (since (
X
T
X
)
−1
X
T
(
I
n
−P
) = 0 since (
I
n
−P
)
X
= 0
— check!).
Hence
ˆ
β
and R are independent since the off-diagonal covariant terms are 0.
So
ˆ
β
and
RSS
= R
T
R are independent. So
ˆ
β
and
ˆσ
2
are independent.
From (ii),
E
(
RSS
) =
σ
2
(
n − p
). So
˜σ
2
=
RSS
n−p
is an unbiased estimator of
σ
2
.
˜σ is often known as the residual standard error on n − p degrees of freedom.
3.4 The F distribution
Definition (F distribution). Suppose U and V are independent with U ∼ χ
2
m
and
V ∼ χ
2
n
. The
X
=
U/m
V/n
is said to have an
F
-distribution on
m
and
n
degrees
of freedom. We write X ∼ F
m,n
Since
U
and
V
have mean
m
and
n
respectively,
U/m
and
V/n
are approxi-
mately 1. So F is often approximately 1.
It should be very clear from definition that
Proposition. If X ∼ F
m,n
, then 1/X ∼ F
n,m
.
We write
F
m,n
(
α
) be the upper 100
α
% point for the
F
m,n
-distribution so
that if X ∼ F
m,n
, then P(X > F
m,n
(α)) = α.
Suppose that we have the upper 5% point for all
F
n,m
. Using these in-
formation, it is easy to find the lower 5% point for
F
m,n
since we know that
P
(
F
m,n
<
1
/x
) =
P
(
F
n,m
> x
), which is where the above proposition comes
useful.
Note that it is immediate from definitions of
t
n
and
F
1,n
that if
Y ∼ t
n
, then
Y
2
∼ F
1,n
, i.e. it is a ratio of independent χ
2
1
and χ
2
n
variables.
3.5 Inference for β
We know that
ˆ
β ∼ N
p
(β, σ
2
(X
T
X)
−1
). So
ˆ
β
j
∼ N(β
j
, σ
2
(X
T
X)
−1
jj
).
The standard error of
ˆ
β
j
is defined to be
SE(
ˆ
β
j
) =
q
˜σ
2
(X
T
X)
−1
jj
,
where
˜σ
2
=
RSS/
(
n − p
). Unlike the actual variance
σ
2
(
X
T
X
)
−1
jj
, the standard
error is calculable from our data.
Then
ˆ
β
j
− β
j
SE(
ˆ
β
j
)
=
ˆ
β
j
− β
j
q
˜σ
2
(X
T
X)
−1
jj
=
(
ˆ
β
j
− β
j
)/
q
σ
2
(X
T
X)
−1
jj
p
RSS/((n − p)σ
2
)
By writing it in this somewhat weird form, we now recognize both the numer-
ator and denominator. The numerator is a standard normal
N
(0
,
1), and the
denominator is an independent
q
χ
2
n−p
/(n − p)
, as we have previously shown.
But a standard normal divided by χ
2
is, by definition, the t distribution. So
ˆ
β
j
− β
j
SE(
ˆ
β
j
)
∼ t
n−p
.
So a 100(1
− α
)% confidence interval for
β
j
has end points
ˆ
β
j
± SE
(
ˆ
β
j
)
t
n−p
(
α
2
).
In particular, if we want to test H
0
: β
j
= 0, we use the fact that under H
0
,
ˆ
β
j
SE(
ˆ
β
j
)
∼ t
n−p
.
3.6 Simple linear regression
We can apply our results to the case of simple linear regression. We have
Y
i
= a
′
+ b(x
i
− ¯x) + ε
i
,
where ¯x =
P
x
i
/n and ε
i
are iid N (0, σ
2
) for i = 1, ··· , n.
Then we have
ˆa
′
=
¯
Y ∼ N
a
′
,
σ
2
n
ˆ
b =
S
xY
S
xx
∼ N
b,
σ
2
S
xx
ˆ
Y
i
= ˆa
′
+
ˆ
b(x
i
− ¯x)
RSS =
X
i
(Y
i
−
ˆ
Y
i
)
2
∼ σ
2
χ
2
n−2
,
and (ˆa
′
,
ˆ
b) and ˆσ
2
= RSS/n are independent, as we have previously shown.
Note that
ˆσ
2
is obtained by dividing RSS by
n
, and is the maximum likelihood
estimator. On the other hand,
˜σ
is obtained by dividing RSS by
n − p
, and is
an unbiased estimator.
Example. Using the oxygen/time example, we have seen that
˜σ
2
=
RSS
n − p
=
67968
24 − 2
= 3089 = 55.6
2
.
So the standard error of
ˆ
β is
SE(
ˆ
b) =
q
˜σ
2
(X
T
X)
−1
22
=
r
3089
S
xx
=
55.6
28.0
= 1.99.
So a 95% interval for b has end points
ˆ
b ± SE(
ˆ
b) × t
n−p
(0.025) = 12.9 ± 1.99 ∗ t
22
(0.025) = (−17.0, −8.8),
using the fact that t
22
(0.025) = 2.07.
Note that this interval does not contain 0. So if we want to carry out a size
0
.
05 test of
H
0
:
b
= 0 (they are uncorrelated) vs
H
1
:
b
= 0 (they are correlated),
the test statistic would be
ˆ
b
SE(
ˆ
b)
=
−12.9
1.99
=
−
6
.
48. Then we reject
H
0
because
this is less than −t
22
(0.025) = −2.07.
3.7 Expected response at x
∗
After performing the linear regression, we can now make predictions from it.
Suppose that x
∗
is a new vector of values for the explanatory variables.
The expected response at x
∗
is
E
[Y
|
x
∗
] = x
∗T
β
. We estimate this by x
∗T
ˆ
β
.
Then we have
x
∗T
(
ˆ
β − β) ∼ N(0, x
∗T
cov(
ˆ
β)x
∗
) = N(0, σ
2
x
∗T
(X
T
X)
−1
x
∗
).
Let τ
2
= x
∗T
(X
T
X)
−1
x
∗
. Then
x
∗T
(
ˆ
β − β)
˜στ
∼ t
n−p
.
Then a confidence interval for the expected response x
∗T
β has end points
x
∗T
ˆ
β ± ˜στ t
n−p
α
2
.
Example. Previous example continued:
Suppose we wish to estimate the time to run 2 miles for a man with an
oxygen take-up measurement of 50. Here x
∗T
= (1, 50 − ¯x), where ¯x = 48.6.
The estimated expected response at x
∗T
is
x
∗T
ˆ
β = ˆa
′
+ (50 −48.5) ×
ˆ
b = 826.5 − 1.4 × 12.9 = 808.5,
which is obtained by plugging x
∗T
into our fitted line.
We find
τ
2
= x
∗T
(X
T
X)
−1
x
∗
=
1
n
+
x
∗2
S
xx
=
1
24
+
1.4
2
783.5
= 0.044 = 0.21
2
.
So a 95% confidence interval for E[Y | x
∗
= 50 − ¯x] is
x
∗T
ˆ
β ± ˜στ t
n−p
α
2
= 808.5 ± 55.6 × 0.21 ×2.07 = (783.6, 832.2).
Note that this is the confidence interval for the predicted expected value,
NOT the confidence interval for the actual obtained value.
The predicted response at x
∗
is
Y
∗
= x
∗
β
+
ε
∗
, where
ε
∗
∼ N
(0
, σ
2
), and
Y
∗
is independent of
Y
1
, ··· , Y
n
. Here we have more uncertainties in our prediction:
β and ε
∗
.
A 100(1
− α
)% prediction interval for
Y
∗
is an interval
I
(Y) such that
P
(
Y
∗
∈ I
(Y)) = 1
− α
, where the probability is over the joint distribution of
Y
∗
, Y
1
, ··· , Y
n
. So
I
is a random function of the past data Y that outputs an
interval.
First of all, as above, the predicted expected response is
ˆ
Y
∗
= x
∗T
β
. This is
an unbiased estimator since
ˆ
Y
∗
− Y
∗
= x
∗T
(
ˆ
β − β) −ε
∗
, and hence
E[
ˆ
Y
∗
− Y
∗
] = x
∗T
(β − β) = 0,
To find the variance, we use that fact that x
∗T
(
ˆ
β − β
) and
ε
∗
are independent,
and the variance of the sum of independent variables is the sum of the variances.
So
var(
ˆ
Y
∗
− Y
∗
) = var(x
∗T
(
ˆ
β)) + var(ε
∗
)
= σ
2
x
∗T
(X
T
X)
−1
x
∗
+ σ
2
.
= σ
2
(τ
2
+ 1).
We can see this as the uncertainty in the regression line
σ
2
τ
2
, plus the wobble
about the regression line σ
2
. So
ˆ
Y
∗
− Y
∗
∼ N(0, σ
2
(τ
2
+ 1)).
We therefore find that
ˆ
Y
∗
− Y
∗
˜σ
√
τ
2
+ 1
∼ t
n−p
.
So the interval with endpoints
x
∗T
ˆ
β ± ˜σ
p
τ
2
+ 1t
n−p
α
2
is a 95% prediction interval for
Y
∗
. We don’t call this a confidence interval —
confidence intervals are about finding parameters of the distribution, while the
prediction interval is about our predictions.
Example. A 95% prediction interval for Y
∗
at x
∗T
= (1, (50 − ¯x)) is
x
∗T
± ˜σ
p
τ
2
+ 1t
n−p
α
2
= 808.5 ± 55.6 × 1.02 ×2.07 = (691.1, 925.8).
Note that this is much wider than our our expected response! This is since there
are three sources of uncertainty: we don’t know what
σ
is, what
ˆ
b
is, and the
random ε fluctuation!
Example. Wafer example continued: Suppose we wish to estimate the expected
resistivity of a new wafer in the first instrument. Here x
∗T
= (1
,
0
, ··· ,
0) (recall
that x is an indicator vector to indicate which instrument is used).
The estimated response at x
∗T
is
x
∗T
ˆ
µ = ˆµ
1
= ¯y
1
= 124.3
We find
τ
2
= x
∗T
(X
T
X)
−1
x
∗
=
1
5
.
So a 95% confidence interval for E[Y
∗
1
] is
x
∗T
ˆ
µ ± ˜στt
n−p
α
2
= 124.3 ±
10.4
√
5
× 2.09 = (114.6, 134.0).
Note that we are using an estimate of
σ
obtained from all five instruments. If
we had only used the data from the first instrument, σ would be estimated as
˜σ
1
=
s
P
5
j=1
y
1,j
− ¯y
1
5 − 1
= 8.74.
The observed 95% confidence interval for µ
1
would have been
¯y
1
±
˜σ
1
√
5
t
4
α
2
= 124.3 ± 3.91 × 2.78 = (113.5, 135.1),
which is slightly wider. Usually it is much wider, but in this special case, we
only get little difference since the data from the first instrument is relatively
tighter than the others.
A 95% prediction interval for Y
∗
1
at x
∗T
= (1, 0, ··· , 0) is
x
∗T
ˆ
µ ± ˜σ
p
τ
2
+ 1t
n−p
α
2
= 124.3 ± 10.42 × 1.1 ×2.07 = (100.5, 148.1).
3.8 Hypothesis testing
3.8.1 Hypothesis testing
In hypothesis testing, we want to know whether certain variables influence the
result. If, say, the variable
x
1
does not influence
Y
, then we must have
β
1
= 0.
So the goal is to test the hypothesis
H
0
:
β
1
= 0 versus
H
1
:
β
1
= 0. We will
tackle a more general case, where
β
can be split into two vectors
β
0
and
β
1
,
and we test if β
1
is zero.
We start with an obscure lemma, which might seem pointless at first, but
will prove itself useful very soon.
Lemma. Suppose Z
∼ N
n
(0
, σ
2
I
n
), and
A
1
and
A
2
are symmetric, idempotent
n × n
matrices with
A
1
A
2
= 0 (i.e. they are orthogonal). Then Z
T
A
1
Z and
Z
T
A
2
Z are independent.
This is geometrically intuitive, because
A
1
and
A
2
being orthogonal means
they are concerned about different parts of the vector Z.
Proof. Let X
i
= A
i
Z, i = 1, 2 and
W =
W
1
W
2
=
A
1
A
2
Z.
Then
W ∼ N
2n
0
0
, σ
2
A
1
0
0 A
2
since the off diagonal matrices are σ
2
A
T
1
A
2
= A
1
A
2
= 0.
So W
1
and W
2
are independent, which implies
W
T
1
W
1
= Z
T
A
T
1
A
1
Z = Z
T
A
1
A
1
Z = Z
T
A
1
Z
and
W
T
2
W
2
= Z
T
A
T
2
A
2
Z = Z
T
A
2
A
2
Z = Z
T
A
2
Z
are independent
Now we go to hypothesis testing in general linear models:
Suppose
X
n×p
=
X
0
n×p
0
X
1
n×(p−p
0
)
!
and B =
β
0
β
1
, where
rank
(
X
) =
p, rank(X
0
) = p
0
.
We want to test
H
0
:
β
1
= 0 against
H
1
:
β
1
= 0. Under
H
0
,
X
1
β
1
vanishes
and
Y = X
0
β
0
+ ε.
Under H
0
, the mle of β
0
and σ
2
are
ˆ
ˆ
β
0
= (X
T
0
X
0
)
−1
X
T
0
Y
ˆ
ˆσ
2
=
RSS
0
n
=
1
n
(Y − X
0
ˆ
ˆ
β
0
)
T
(Y − X
0
ˆ
ˆ
β
0
)
and we have previously shown these are independent.
Note that our poor estimators wear two hats instead of one. We adopt the
convention that the estimators of the null hypothesis have two hats, while those
of the alternative hypothesis have one.
So the fitted values under H
0
are
ˆ
ˆ
Y = X
0
(X
T
0
X
0
)
−1
X
T
0
Y = P
0
Y,
where P
0
= X
0
(X
T
0
X
0
)
−1
X
T
0
.
The generalized likelihood ratio test of H
0
against H
1
is
Λ
Y
(H
0
, H
1
) =
1
√
2πˆσ
2
exp
−
1
2ˆσ
2
(Y − X
ˆ
β)
T
(Y − X
ˆ
β)
1
√
2π
ˆ
ˆσ
2
exp
−
1
2
ˆ
ˆσ
2
(Y − X
ˆ
ˆ
β
0
)
T
(Y − X
ˆ
ˆ
β
0
)
=
ˆ
ˆσ
2
ˆσ
2
!
n/2
=
RSS
0
RSS
n/2
=
1 +
RSS
0
− RSS
RSS
n/2
.
We reject H
0
when 2 log Λ is large, equivalently when
RSS
0
−RSS
RSS
is large.
Using the results in Lecture 8, under H
0
, we have
2 log Λ = n log
1 +
RSS
0
− RSS
RSS
,
which is approximately a χ
2
p
1
−p
0
random variable.
This is a good approximation. But we can get an exact null distribution, and
get an exact test.
We have previously shown that RSS = Y
T
(I
n
− P )Y, and so
RSS
0
− RSS = Y
T
(I
n
− P
0
)Y − Y
T
(I
n
− P )Y = Y
T
(P − P
0
)Y.
Now both
I
n
− P
and
P − P
0
are symmetric and idempotent, and therefore
rank(I
n
− P ) = n −p and
rank(P − P
0
) = tr(P − P
0
) = tr(P ) − tr(P
0
) = rank(P ) − rank(P
0
) = p − p
0
.
Also,
(I
n
− P )(P − P
0
) = (I
n
− P )P − (I
n
− P )P
0
= (P − P
2
) − (P
0
− P P
0
) = 0.
(we have
P
2
=
P
by idempotence, and
P P
0
=
P
0
since after projecting with
P
0
,
we are already in the space of P , and applying P has no effect)
Finally,
Y
T
(I
n
− P )Y = (Y − X
0
β
0
)
T
(I
n
− P )(Y − X
0
β
0
)
Y
T
(P − P
0
)Y = (Y −X
0
β
0
)
T
(P − P
0
)(Y − X
0
β
0
)
since (I
n
− P )X
0
= (P − P
0
)X
0
= 0.
If we let Z = Y
−X
0
β
0
,
A
1
=
I
n
−P
,
A
2
=
P −P
0
, and apply our previous
lemma, and the fact that Z
T
A
i
Z ∼ σ
2
χ
2
r
, then
RSS = Y
T
(I
n
− P )Y ∼ χ
2
n−p
RSS
0
− RSS = Y
T
(P − P
0
)Y ∼ χ
2
p−p
0
and these random variables are independent.
So under H
0
,
F =
Y
T
(P − P
0
)Y/(p − p
0
)
Y
T
(I
n
− P )Y/(n − p)
=
(RSS
0
− RSS)/(p −p
0
)
RSS/(n − p)
∼ F
p−p
0
,n−p
,
Hence we reject H
0
if F > F
p−p
0
,n−p
(α).
RSS
0
− RSS
is the reduction in the sum of squares due to fitting
β
1
in
addition to β
0
.
Source of var. d.f. sum of squares mean squares F statistic
Fitted model p − p
0
RSS
0
− RSS
RSS
0
−RSS
p−p
0
(RSS
0
−RSS)/(p−p
0
)
RSS/(n−p)
Residual n − p RSS
RSS
n−p
Total n −p
0
RSS
0
The ratio
RSS
0
−RSS
RSS
0
is sometimes known as the proportion of variance explained
by β
1
, and denoted R
2
.
3.8.2 Simple linear regression
We assume that
Y
i
= a
′
+ b(x
i
− ¯x) + ε
i
,
where ¯x =
P
x
i
/n and ε
i
are N (0, σ
2
).
Suppose we want to test the hypothesis
H
0
:
b
= 0, i.e. no linear relationship.
We have previously seen how to construct a confidence interval, and so we could
simply see if it included 0.
Alternatively, under
H
0
, the model is
Y
i
∼ N
(
a
′
, σ
2
), and so
ˆa
′
=
¯
Y
, and the
fitted values are
ˆ
Y
i
=
¯
Y .
The observed RSS
0
is therefore
RSS
0
=
X
i
(y
i
− ¯y)
2
= S
yy
.
The fitted sum of squares is therefore
RSS
0
−RSS =
X
i
(y
i
− ¯y)
2
−(y
i
− ¯y −
ˆ
b(x
i
− ¯x))
2
=
ˆ
b
2
X
(x
i
− ¯x)
2
=
ˆ
b
2
S
xx
.
Source of var. d.f. sum of squares mean squares F statistic
Fitted model 1 RSS
0
− RSS =
ˆ
b
2
S
XX
ˆ
b
2
S
xx
F =
ˆ
b
2
S
xx
˜σ
2
Residual n −2 RSS =
P
i
(y
i
− ˆy)
2
˜σ
2
.
Total n −1 RSS
0
=
P
i
(y
i
− ¯y)
2
Note that the proposition of variance explained is
ˆ
b
2
S
xx
/S
yy
=
S
2
xy
S
xx
S
yy
=
r
2
,
where r is the Pearson’s product-moment correlation coefficient
r =
S
xy
p
S
xx
S
yy
.
We have previously seen that under
H
0
,
ˆ
b
SE(
ˆ
b)
∼ t
n−2
, where
SE
(
ˆ
b
) =
˜σ/
√
S
xx
.
So we let
t =
ˆ
b
SE(
ˆ
b)
=
ˆ
b
√
S
xx
˜σ
.
Checking whether
|t| > t
n−2
α
2
is precisely the same as checking whether
t
2
= F > F
1,n−2
(α), since a F
1,n−2
variable is t
2
n−2
.
Hence the same conclusion is reached, regardless of whether we use the
t-distribution or the F statistic derived form an analysis of variance table.
3.8.3
One way analysis of variance with equal numb ers in each group
Recall that in our wafer example, we made measurements in groups, and want to
know if there is a difference between groups. In general, suppose
J
measurements
are taken in each of I groups, and that
Y
ij
= µ
i
+ ε
ij
,
where
ε
ij
are independent
N
(0
, σ
2
) random variables, and the
µ
i
are unknown
constants.
Fitting this model gives
RSS =
I
X
i=1
J
X
j=1
(Y
ij
− ˆµ
i
)
2
=
I
X
i=1
J
X
j=1
(Y
ij
−
¯
Y
i.
)
2
on n − I degrees of freedom.
Suppose we want to test the hypothesis
H
0
:
µ
i
=
µ
, i.e. no difference between
groups.
Under
H
0
, the model is
Y
ij
∼ N
(
µ, σ
2
), and so
ˆµ
=
¯
Y
, and the fitted values
are
ˆ
Y
ij
=
¯
Y .
The observed RSS
0
is therefore
RSS
0
=
X
i,j
(y
ij
− ¯y
..
)
2
.
The fitted sum of squares is therefore
RSS
0
− RSS =
X
i
X
j
(y
ij
− ¯y
..
)
2
− (y
ij
− ¯y
i.
)
2
= J
X
i
(¯y
i.
− ¯y
..
)
2
.
Source of var. d.f. sum of squares mean squares F statistic
Fitted model I − 1 J
P
i
(¯y
i
− ¯y
..
)
2
J
P
i
(¯y
i.
−¯y
..
)
2
I−1
J
P
i
(¯y
i.
−¯y
..
)
2
(I−1)˜σ
2
Residual n −I
P
i
P
j
(y
ij
− ¯y
i.
)
2
˜σ
2
Total n − 1
P
i
P
j
(y
ij
− ¯y
..
)
2