Section 1
Section 1
Craig Anderson
Course info
Lecturer
2/86
Recommended textbooks
3/86
Aims and intended learning outcomes
Aims
To introduce students to Gaussian linear mixed effects
modelling in general and to the active use of modern mixed
effects modelling software.
4/86
Intended learning outcomes
5/86
Intended learning outcomes
6/86
Course outline
Topics
7/86
Revision
One-way ANOVA
One-way analysis of variance describes how the mean of a
continuous response variable depends on a categorical
explanatory variable.
Goal: to estimate the population group means µ1 , . . . , µI
and to test the hypothesis that all means are equal.
H0 : µ1 = · · · = µI
H1 : not all the µi are equal.
Note: some of the µi could be equal under H1 .
Main questions of interest:
1. Are there any differences in the I population means?
2. If yes, which of the means differ?
8/86
Revision
Data
yij is the jth observation of the ith sample. (i = 1, . . . , I and
j = 1, . . . , ni ).
9/86
Terminology
Factor
Any categorical variable such as treatment (trt1 , . . . , trtI ).
Levels
The categories of a factor, e.g. trt2 is one particular level of the
treatment factor.
Effects
The differences in the mean of the response variable among
different levels of a factor.
10/86
Analysis of variance
11/86
Analysis of variance
Model assumptions
yij = µ + αi + eij
12/86
Identifiability
13/86
Hypothesis testing
Hypotheses
H 0 : µ1 = · · · = µI
H1 : not all the µi are equal
14/86
Analysis of variance
Notation
I
P
Total number of observations: N = ni
i=1
ni
1
P
ith sample mean: ȳi· = ni
yij
j=1
ni
I P
1
P
Overall mean: ȳ = N
yij
i=1 j=1
15/86
Analysis of variance
Sums of squares
ni
I P
(yij − ȳ)2 measures the total variability in Y.
P
SST =
i=1 j=1
This can be rewritten as
X ni
I X ni
I X
X
2
SST = (ȳi· − ȳ) + (yij − ȳi· )2
i=1 j=1 i=1 j=1
I
X ni
I X
X
= ni (ȳi· − ȳ)2 + (yij − ȳi· )2 = SSB + SSE
i=1 i=1 j=1
16/86
Analysis of variance
ANOVA table
Source SS df MS F
SSB MSB
Between-group SSB I−1 MSB =
I−1 MSE
SSE
Within-group (Error) SSE N−I MSE =
N−I
17/86
Sources of variability
18/86
F-test
Test Statistic
MSB
F= MSE
Numerator
I
E(MSB) = σ 2 + ni (µi − µ̄)2 /(I − 1),
P
i=1
Denominator
E(MSE) = σ 2
19/86
F-test
Note that rejecting H0 tells us that not all the µi are equal,
but it does not specify which of the µi values differ.
20/86
Medicine Dosage for Ill Rabbits
21/86
Example
22/86
Example
ANOVA table
Source SS df MS F
Between-group (Breed) 249.9 3 83.3 8.5
Within-group (Error) 350.9 36 9.7
Total 600.8 39
23/86
Estimation
Point Estimate
µ̂i = ȳi
Variance
σ2
Var (ȳi ) = ni
, where σ̂ 2 = MSE.
Confidence Interval
ȳi ± t0.975 (N − I) √σ̂ni .
24/86
Estimating linear combinations
Point Estimate
I
P I
P
ci µ̂i = ci ȳi
i=1 i=1
Variance
I
I
c2i /ni σ2.
P P
Var ci ȳi =
i=1 i=1
25/86
Estimating linear combinations - Example
Difference in Means
µ̂1 − µ̂2 = ȳ1 − ȳ2 = 25.9 − 22.2 = 3.7
Variance
Var (µ̂1 − µ̂2 ) = ( 101 + 1
10
)σ̂ 2 = 0.2 × 9.7 = 1.9.
26/86
Multiple comparisons
27/86
Multiple comparison procedures
Bonferroni adjustment
28/86
Multiple comparison procedures
Scheffé’s method
29/86
Multiple comparison procedures
30/86
Multiple comparison procedures
Differences in Means
Graphical representation
31/86
Two-way ANOVA
One-way ANOVA
Two-way ANOVA
Two factors
Compare mean response across the levels of factor 1 and
factor 2.
32/86
Two-way ANOVA
Questions of interest
33/86
Linear models
ANOVA as a linear model
34/86
Linear models
Model formulation
Thus the ANOVA model Yij = µi + eij can be expressed as
with
µ1 =β0 + β1
µ2 =β0 + β2
..
.
µI =β0
35/86
Linear models
36/86
Fixed or random?
Fixed effects
Random effects
37/86
Examples
Factory machine output
Drug study
38/86
Examples
Drug study
39/86
Random, fixed, and mixed effects models
40/86
One-factor random effects model
41/86
Example - Factory machine output
Data
Model
Question of interest
43/86
Variance components
Under this model Var (Yij ) = σA2 + σE2 (the Yij share a
common variance).
However, the Yij are no longer independent.
Cov Yi1 j , Yi2 j = 0 (different workers are independent of
each other).
Within the same level the Yij are not independent of each
other:
44/86
Intraclass correlation
45/86
Repeatability and Reproducibility
46/86
Estimation
Assume for simplicity that we have an equal number of
observations, J, for each level of factor A.
Decomposing the variation
I
X
SSA = J (ȳi· − ȳ)2 ,
i=1
I X
X J
SSE = (yij − ȳi· )2 .
i=1 j=1
47/86
Estimation
ANOVA table
Source SS df MS F
SSA MSA
A SSA I−1 MSA =
I−1 MSE
SSE
Error SSE I(J − 1) MSE =
I(J − 1)
Total SST IJ − 1
48/86
Distributional results
Distribution of SSE
I X
X J
SSE = (yij − ȳi· )2
i=1 j=1
I X
X J
= (eij − ei· )2 ∼ σE2 χ2 (I[J − 1])
i=1 j=1
49/86
Distributional results
Distribution of SSA
I
X
SSA = J (ȳi· − ȳ)2
i=1
XI
=J (ai − a· + ei· − e·· )2
i=1
σE2
X
2 2
=J (gi − ḡ) ∼ J σA + χ2 (I − 1)
J
50/86
Distributional results
51/86
Distributional results
Proof of independence
P P
j eij j eij
Cov eij − ei· , ei· = Cov eij − ,
J J
Var (eij )
= − Var (ei· )
J
σE2 σ2
= − E = 0.
J J
52/86
Hypothesis Test
F-statistic
MSA
F=
MSE
SSA/(I − 1)
=
SSE/(N − I)
∼ F(I − 1, N − I)
53/86
Estimation of variance components
Method of moments
Since
E(MSE) = σE2
E(MSA) = σE2 + JσA2 ,
we can take
54/86
Method of moments estimators
55/86
Example
Nitrogen concentrations in Mississippi river
We have data about 37 nitrogen concentrations at six randomly
selected influents of the Mississippi river. This is an unbalanced
dataset as the number of observations is not the same for all
levels of the factor influent.
This dataset comes from Littel, R. C., Milliken, G. A., Stroup, W. W., and Wolfinger, R. D.
(1996), SAS System for Mixed Models, SAS Institute (Data Set 4.2).
56/86
Nitrogen data
40
Nitrogen concentration
30
20
10
1 2 3 4 5 6
Influent
57/86
Example
58/86
Example
ANOVA table
Source SS DF MS F p
Influent 1925.19 5 385.04 9.04 < 0.0001
Error 1319.78 31
Total 3244.97 36
F-test
59/86
Variance component estimates
1319.779
σ̂E2 = = 42.57.
31
Unbalanced data → E(MSA) = σE2 + J̃σA2 where
PI
n− i=1 n2i /n
J̃ = = 6.0973.
I−1
Method of moments estimator of σA2 :
1925.194/5 − σ̂E2
σ̂A2 = = 56.17.
6.0793
60/86
Two-factor random effects model
for i = 1, . . . , I, j = 1, . . . , J and k = 1, . . . , K.
61/86
Sums of squares - Factor A
Factor A
I
X
SSA = JK (ȳi·· − ȳ)2 .
i=1
We have
ȳi·· = µ + ai + b· + (ab)i· + ei··
ȳ = µ + a· + b· + (ab)·· + e···
so the sum of squares can be expressed as
I
X
SSA = JK (gi − ḡ)2 where gi = ai + (ab)i· + ei·· .
i=1
62/86
Sums of squares
Factor A
2
σAB σ2
SSA ∼ JKVar (gi ) χ2 (I − 1) with Var (gi ) = σA2 + + E.
J JK
This gives
2
σE2
2
2 σAB χ (I − 1)
E(MSA) = JK σA + + E
J JK I−1
2 2
σ σ
= JK σA2 + AB + E .
J JK
63/86
Sums of squares
Factor B
Similarly
σ2 σ2
SSB ∼ IK σB2 + AB + E χ2 (J − 1)
I IK
and
2
σE2
2
σAB χ (J − 1)
E(MSB) = IK +σB2 + E
I IK J−1
2 2
σ σ
= IK σB2 + AB + E .
I IK
64/86
Sums of squares
Error
I X
X J X
K
SSE = (yijk − ȳij· )2
i=1 j=1 k=1
I X
X J X
K
= (eijk − eij· )2
i=1 j=1 k=1
65/86
Mean sums of squares
66/86
Interaction term
I X
X J X
K
((ab)ij − (ab)i· − (ab)·j + (ab)·· + eijk − ei·· − e·j· + e··· )2
i=1 j=1 k=1
2
E(MSAB) = KσAB + σE2 .
67/86
ANOVA table
ANOVA table
Source MS E(MS) F
SSA MSA
A MSA = σE2 + KσAB
2
+ JKσA2 FA =
I−1 MSAB
SSB MSB
B MSB = σE2 + KσAB
2
+ IKσB2 FB =
J−1 MSAB
SSAB MSAB
AB MSAB = σE2 + KσAB
2
FAB =
(I − 1)(J − 1) MSE
SSE
Error MSE = σE2
IJ(K − 1)
68/86
Test statistics for hypothesis tests
Under HA : σA2 = 0
MSA
FA = ∼ F(I − 1, (I − 1)(J − 1))
MSAB
Under HB : σB2 = 0
MSB
FB = ∼ F(J − 1, (I − 1)(J − 1))
MSAB
2
Under HAB : σAB =0
MSAB
FAB = ∼ F((I − 1)(J − 1), IJ(K − 1))
MSE
69/86
Example
Assessment of heart X-rays: observer error
Two randomly selected radiologists at the Western
Infirmary in Glasgow calculated the diagnostic ratio (ratio
of width of the heart to width of the thorax).
Each radiologist assessed the heart X-rays of 15 patients
on two separate occasions.
X-rays were presented to the observers in random order.
The purpose of the study was to investigate the variability
in the assessments made by the different observers.
70/86
Example
Data Source
The data are taken from J. Aitchison, J.W. Kay and I.J. Lauder’s
text Statistical Concepts and Applications in Clinical Medicine,
2004.
Question of interest
Would it be safe to make the assessments using different
observers, or should a single observer be used to make all
assessments of this type?
71/86
Interaction plot of heart X-ray data
1
0.55
2 2 Observer
2
2 2
2
2
1 1
1
0.50
2
2 1 2 2 1
2
1 1
mean of DR
1 2
1 2 1
1 1
2
2
0.45
1 1
1
2
1
2 1
1
2 2
0.40
2 1 1
2
1 2
1
1 2
1
1
2
1
1
0.35
1 2 3 4 5 6 7 8 9 10 12 14
Case
72/86
Random effects model
Fit a model for the diagnostic ratio with case and observer
included as random factors.
Each level of the factor case appears with every level of the
observer factor. Such factors are known as crossed effects.
73/86
ANOVA table
ANOVA table
Source DF SS MS F p
Case 14 0.1569397 0.011210 33.19 < 0.0001
74/86
Variance component estimation
Method of moments (unbiased estimates)
2
MSA − K σ̂AB − σ̂E2 MSA − MSAB
σ̂A2 = =
JK JK
MSB − MSAB
σ̂B2 =
IK
2 MSAB − MSE
σ̂AB =
K
σ̂E2 = MSE
75/86
Variance component estimation
Observer 0.000070
Case:Observer 0.000112
Error 0.000114
76/86
Diagnostic plots
4
13 ● 13 ●
Standardized residuals
● ●
2
0.01
● ● ●●
●●
Residuals
● ● ● ●
●●● ● ● ●●●●●
● ●● ● ●
● ● ●
● ●
●●●●
●● ●●●
● ●●● ● ● ●●
●
●
●●
●●
●
●
● ●● ●
●●
●●
●●
●
0
● ● ●
● ●
●●
●
●●● ● ●
●
●●
●●
●●
●
●●
●
−0.01
● ● ● ●● ●●
●●
● ●●●●
●
●●
● 30
−2
● 30
−0.03
14 ●
● 14
77/86
Nested designs
78/86
Example
Silicon wafers
Questions
79/86
Example
Silicon wafers
80/86
Example
Model
for i = 1, . . . , 8, j = 1, 2, 3 and k = 1, 2, 3.
In the above notation, brackets denote nesting.
There is no random noise term in the model because no
replicate measurements were taken.
Consider the general model with i = 1, . . . , I, j = 1, . . . , J
and k = 1, . . . , K.
81/86
Sums of squares
Factor A
I
X
SSA = JK (yi·· − ȳ)2
i=1
where
yi·· = µ + ai + b·(i) + c·(i·)
and
ȳ = µ + a· + b·(·) + c·(··) ,
so
I
X
SSA = JK (ai· − a·· + b·(i) − b·(·) + c·(i·) − c·(··) )2 .
i=1
82/86
Sums of squares
and !
2 2
σB(A) σC(AB)
E(MSA) = JK σA2 + +
J JK
with degrees of freedom equal to I − 1.
83/86
Sums of squares
Factor B
84/86
Sums of squares
Factor C
E(MSE) = σE2
Degrees of freedom = IJ(K − 1)
We can think of this term as a measure of the variation
among k’s given i and j.
85/86
Hypothesis testing
ANOVA table
Source DF SS MS F p
A 7 9025.319 1289.331 10.73 < 0.0001
B(A) 16 1922.667 120.167 9.56 < 0.0001
C(B) 48 603.333 12.569
86/86