### Document

```Repeated Measure Design of
ANOVA
AMS 572 Group 5
Outline
• Jia Chen: Introduction of repeated measures
ANOVA
• Chewei Lu: One-way repeated measures
• Wei Xi: Two-factor repeated measures
• Tomoaki Sakamoto : Three-factor repeated
measures
• How-Chung Liu: Mixed models
• Margaret Brown: Comparison
• Xiao Liu: Conclusion
Introduction of Repeated
Measures ANOVA
Jia Chen
What is it ?
Definition:
- It is a technique used to test the equality of
means.
When To Use It?
• It is used when all members of a random
sample are measured under a number of
different conditions.
• As the sample is exposed to each condition in
turn, the measurement of dependent variable
is repeated.
Introduction of One-Way
Repeated Measures ANOVA
Che-Wei, Lu
Professor:Wei Zhu
One-Way Repeated Measures ANOVA
• Definition
A one-way repeated measures ANOVA instead of
having one score per subject, experiments are
frequently conducted in which multiple score are
gathered for each case.
• Concept of Repeated Measures ANOVA
 One factor with at least two levels, levels are
dependent.
 Dependent means that they share variability in some
way.
 The Repeated Measures ANOVA is extended from
standard ANOVA.
One-Way Repeated Measures ANOVA
• When to Use
 Measuring performance on the same variable over
time
– for example looking at changes in performance during training or
before and after a specific treatment
 The same subject is measured multiple times under
different conditions
– for example performance when taking Drug A and performance
when taking Drug B
 The same subjects provide measures/ratings on
different characteristics
– for example the desirability of red cars, green cars and blue cars
 Note how we could do some RM as regular between
subjects designs
– For example, Randomly assign to drug A or B
One-Way Repeated Measures ANOVA
• Source of Variance in Repeated Measures ANOVA
 SStotal
– Deviation of each individual score from the grand mean
 SSb/t subjects
– Deviation of subjects' individual means (across treatments) from the
grand mean.
– In the RM setting, this is largely uninteresting, as we can pretty much
assume that ‘subjects differ’
 SSw/in subjects: How Ss vary about their own mean,
breaks down into:
– SStreatment
• As in between subjects ANOVA, is the comparison of treatment
means to each other (by examining their deviations from the grand
mean)
• However this is now a partition of the within subjects variation
– SSerror
• Variability of individuals’ scores about their treatment mean
One-Way Repeated Measures ANOVA
• Partition of Sum of Square
Repeated Measures ANOVA

/

/

Standard ANOVA

/
/
One-Way Repeated Measures ANOVA
• Standard ANOVA Table
Variation
Between
Within
Total
SS
Df

( − )2
−1

( −  )
2
=1 =1

( − )
2
MS
F
a-1
MSA=
N-a
MSE=

−1

F=

−
N-1
=1 =1
• Repeated Measures ANOVA Table
SS
Df
MS
(  )2  2
−

(  )2
2
−

a-1
MSA=
s-1
-Error
(  )2  2
−

−
Total
+ ℎ
N-A
Between
Within
-Subjects
F

−1
N-a
MSE=

(−1)(−1)

F=

One-Way Repeated Measures ANOVA
• Example:
Researchers want to test a new anti-anxiety medication. They
measure the anxiety of 7 participants three times: once before
taking the medication, once one week after taking the
medication, and once two weeks after taking medication.
Anxiety is rated on a scale of 1-10,with 10 being ”high anxiety”
and 1 being “low anxiety”. Are there any difference between the
three condition using significant level  = 0.05?
Participants
Before
Week1
Week2
1
9
7
4
2
8
6
3
3
7
6
2
4
8
7
3
5
8
8
4
6
9
7
3
7
8
6
2
One-Way Repeated Measures ANOVA
Participants
Before
Week1
Week2
1
9
7
4
2
8
6
3
3
7
6
2
4
8
7
3
5
8
8
4
6
9
7
3
7
8
6
2
• Define Null and Alternative Hypotheses
0 :  = 1 = 2
: 0
One-Way Repeated Measures ANOVA
Participants
Before
Week1
Week2
1
9
7
4
2
8
6
3
3
7
6
2
4
8
7
3
5
8
8
4
6
9
7
3
7
8
6
2
• Define Degrees of Freedom
N=21
s=7
=  − 1 = 3 − 1 = 2
ℎ =  −  = 21 − 3 = 18
=  − 1 = 7 − 1 = 6
= ℎ - =18-6=12
=  − 1 = 21 − 1 = 20
One-Way Repeated Measures ANOVA
Participants
Before
Week1
Week2
1
9
7
4
2
8
6
3
3
7
6
2
4
8
7
3
5
8
8
4
6
9
7
3
7
8
6
2
• Analysis of Variance
(  )2  2
=
−
, where  = ,

=    ℎ
2
(

)

ℎ =
2 −

(  )2  2
=
− , ℎ =  ℎ

One-Way Repeated Measures ANOVA
• Analysis of Variance(ANOVA Table)
SS
Df
MS
F
Between
98.67
2
49.34
224.27
Within
10.29
18
-Subjects
7.62
6
-Error
2.67
12
Total
108.96
20
0.22
Error=within-Subjects=10.29-7.62=2.67
Total=Beteen+Within=98.67+10.29=108.96
• Test Statistic:
0 =

=

ℎ

98.67
= 2.67
2
12
=244.27
One-Way Repeated Measures ANOVA
SS
Df
MS
F
Between
98.67
2
49.34
224.27
Within
10.29
18
-Subjects
7.62
6
-Error
2.67
12
Total
108.96
20
0.22
• Critical Region
0   ℎ  2,12,0.05
= 3.88,   ℎℎ.
Now, the 0 = 224.26 >
3.88. ℎ,   0 ℎ
ℎ ℎ
One-Way Repeated Measures ANOVA
• SAS Code
In here, we don’t have
CLASS statement
because our data set
does not have an
independent variable
The Before, Week1,
DATA REPEAT;
INPUT SUBJ BEFORE WEEK1 WEEK2; and Week2 are the
time level at each
DATALINES;
participants.
1974
2863
3762
4873
The NOUNI(no univariate)
5884
is a request not to conduct
6973
a separate analysis for
7862
each of the three times
;
variables.
PROC ANOVA DATA=REPEAT;
TITLE "One-Way ANOVA using the
repeated Statment";
MODEL BEFORE WEEK1 WEEK2= / NOUNI;
REPEATED TIME 3 (1 2 3);
This indicates the labels we
RUN;
want to printed for each level
of times
One-Way Repeated Measures ANOVA
• SAS Result
Wei Xi
Stating of the Hypothesis
Within-Subjects Main Effect
Between-Subjects Main Effect
Between-Subjects Interaction Effect
Within-Subjects By Between-Subjects Interaction
Effects
Two-Factor ANOVA with Repeated
Measures on One Factor
Hypothesis
ANOVA TABLE
Source
DF
SS
MS
F
Factor A
a-1
SSA
SSA/(a-1)
MSA/MSWA ～ F(a-1),n(a-1)
Factor B
b-1
SSB
SSB/(b-1)
AB Interaction
(a-1)(b-1)
SSAB SSAB/(a-1)(b-1)
Subjects within A
(n-1)a
SSW
A
SSWA/(n-1)a
Error
(n-1)a(b-1)
SSE
SSE/((n-1)a(b-1)
Total
nab-1
SST
～
F(b-1),n(a-1)(b-1)
MSAB/MSE ～
F(a-1)(b-1,n(a-1)(b-1)
MSB/MSE
Example
• The shape variable is the repeated variable. This produces an ANOVA with
one between-subjects factor. If you were to examine the expected mean
squares for this setup, you would find that the appropriate error term for
the test of calib is subject|calib. The appropriate error term for shape and
shape#calib is shape#subject|calib (which is the residual error since we do
not include the term in the model).
SAS Code
Data Q1;
set pre.Q1;
run;
proc anova data=Q1;
title' Two-way Anova with a Repeated Measure on
One Factor';
class calib;
model shape_1 shape_2 shape_3 shape_4 =
calib/nouni;
Analysis of SAS Output
MANOVA Test Criteria and Exact F Statistics for the Hypothesis of no shape Effect
H = Anova SSCP Matrix for shape
E = Error SSCP Matrix
S=1
M=0.5
N=0
Statistic
Wilks' Lambda
Value
0.02529573
F Value
25.69
Num DF
3
Den DF
2
Pr > F
0.0377
Pillai's Trace
0.97470427
25.69
3
2
0.0377
Hotelling-Lawley Trace
38.53236607
25.69
3
2
0.0377
Roy's Greatest Root
38.53236607
25.69
3
2
0.0377
At α=0.05,we reject the hypothesis and conclude that there is shape Effect
MANOVA Test Criteria and Exact F Statistics for the Hypothesis of no shape*calib Effect
H = Anova SSCP Matrix for shape*calib
E = Error SSCP Matrix
S=1
M=0.5
N=0
Statistic
Wilks' Lambda
Value
0.16750795
F Value
3.31
Num DF
3
Den DF
2
Pr > F
0.2404
Pillai's Trace
0.83249205
3.31
3
2
0.2404
Hotelling-Lawley Trace
4.96986607
3.31
3
2
0.2404
Roy's Greatest Root
4.96986607
3.31
3
2
0.2404
At α=0.05,we cannot reject the hypothesis and conclude that there is no
shape*calib Effect
Tests of Hypotheses for Between Subjects Effects
Source
calib
Error
DF
1
Anova SS
51.04166667
Mean Square
51.04166667
4
17.16666667
4.29166667
F Value
11.89
Pr > F
0.0261
Univariate Tests of Hypotheses for Within Subject Effects
Source
shape
DF
3
Anova SS
47.45833333
Mean Square
15.81944444
F Value
12.80
Pr > F
0.0005
G-G
0.0099
H-F
0.0011
shape*calib
3
7.45833333
2.48611111
2.01
0.1662
0.2152
0.1791
Error(shape)
12
14.83333333
1.23611111
Two-Factor ANOVA with Repeated
Measures on both Factors
ANOVA TABLE
Source
DF
SS
MS
F
Subjects
n-1
SSS
SSS/I-1
MSS/MSE
Factor A
a-1
SSA
SSA/(a-1)
MSA/MSA*S ～ F(a-1),(n-1)(a-1)
Factor B
b-1
SSB
SSB/(b-1)
MSB/MSB*S ～ F(b-1),(n-1)(b-1)
AB Interaction
(a-1)(b-1)
SSAB
SSAB/((a-1)(b1))
MSAB/MSE ～ F(a-1)(b-1),(n-1)(a1)(b-1)
A*Subjects
(n-1)(a-1)
SSA*S
SSWA/((n-1)a)
SSA*S/MSE
F(a-1)(n-1),(n-1)(a-1)(b-1)
B*Subjects
(n-1)(b-1)
SSB*S
SSWB/((n-1)b)
SSA*S/MSE
F(n-1)(b-1),(n-1)(a-1)(b-1)
SSE/((n-1)(a1)(b-1))
Error
(n-a)(a-1)(b-1)
SSE
Total
nab-1
SST
Example
 Three subjects, each with nine accuracy scores on all combinations of the three
different dials and three different periods. With subject a random factor and
both dial and period fixed factors, the appropriate error term for the test of dial
is the dial#subject interaction. Likewise, period#subject is the correct error term
for period, and period#dial#subject (which we will drop so that it becomes
residual error) is the appropriate error term for period#dial.
•
•
•
•
•
•
•
•
•
•
•
•
•
•
SAS Code
Data Q2;
Input Mins1-Mins9;
Datalines;
45 53 60 40 52 57 28 37 46
35 41 50 30 37 47 28 32 41
60 65 75 58 54 70 40 47 50
;
ODS RTF STYLE=BarrettsBlue;
Proc anova data=Q2;
Model Mins1-Mins9=/nouni;
Repeated period 3, dail 3/nom;
Run;
ods rtf close;
SAS Output
Univariate Tests of Hypotheses for Within Subject Effects
Source
period
Error(period)
DF
Anova SS
2 1072.666667
4
148.444444
Mean Square F Value Pr > F G - G
H-F
536.333333
14.45 0.0148 0.0563 0.0394
37.111111
Greenhouse-Geisser Epsilon
0.5364
Huynh-Feldt Epsilon
0.6569
At α=0.05,we reject the hypothesis and conclude that there is period Effect
Source
dail
Error(dail)
DF
2
4
Anova SS
978.6666667
38.4444444
Mean Square
489.3333333
9.6111111
F Value Pr > F
50.91 0.0014
G-G
H-F
0.0169 0.0115
Greenhouse-Geisser Epsilon
0.5227
Huynh-Feldt Epsilon
0.5952
At α=0.05,we reject the hypothesis and conclude that there is dail Effect
Source
period*dail
Error(period*dail)
DF
4
Anova SS Mean Square F Value Pr > F G - G H - F
8.66666667
2.16666667
0.30 0.8715 0.6603 0.7194
8 58.22222222
Greenhouse-Geisser Epsilon
0.2827
Huynh-Feldt Epsilon
0.4006
7.27777778
At α=0.05,we cannot reject the hypothesis and conclude the there is no
period*dail Effect
Three-factor Experiments
with a repeated measure
T. Sakamoto
Example of a marketing experiment
 Case of this example
• A company which produces some Liquid Crystal
Display wants to examine the characteristics of its
prototype products.
 Experiment
 The subjects who belong to a region X or Y see the
Liquid Crystal Display A, B, or C.
 Each type of LCD is seen twice; once in the light and
the other in the dark.
 The preferences of the LCD are measured by the
subjects, on a scale from 1 to 5 (1= lowest,
5=highest).
35/87
Experimental Design and Data
 Three factors
 Type of LCD
 Regions to which the specimens belong
 In the light / In the dark
 Repeted measure factor : In the light / In the dark
Type of LCD
A
X
REGION
Y
B
C
subj
light
dark
subj
light
dark
subj
light
dark
1
5
4
11
4
4
21
5
5
2
4
2
12
5
6
22
5
3
3
5
4
13
3
4
23
3
3
4
3
5
14
5
4
24
4
4
5
5
3
15
4
6
25
4
3
6
4
4
16
5
5
26
3
5
7
3
5
17
4
3
27
4
3
8
4
3
18
5
3
28
5
2
9
2
5
19
5
5
29
3
4
10
5
4
20
4
4
30
4
36/87 3
SAS PROGRAM
data lcd;
input subj type \$ region \$ light dark @@;
datalines;
1a542a423a544a355a53
6 a 4 4 7 a 3 5 8 a 4 3 9 a 2 5 10 a 5 4
11 b 4 4 12 b 5 6 13 b 3 4 14 b 5 4 15 b 4 6
16 b 5 5 17 b 4 3 18 b 5 3 19 b 5 5 20 b 4 4
21 c 5 5 22 c 5 3 23 c 3 3 24 c 4 4 25 c 4 3
26 c 3 5 27 c 4 3 28 c 5 2 29 c 3 4 30 c 4 3
;
run;
proc anova data=lcd;
title ’Three-way ANOVA with a Repeated Measure';
class type region;
model light dark = type | region /nouni;
repeated light_dark;
means type | region;
run;
37/87
OUTPUT(Part 1/4):
OUTPUT(Part 2/4):
OUTPUT(Part 3/4):
40/81
OUTPUT(Part 4/4):
Mixed Effect Models
How-Chang Liu
Mixed Models
• When we have a model that contains random
effect as well as fixed effect, then we are
dealing with a mixed model.
• From the above definition, we see that mixed
models must contain at least two factors. One
having fixed effect and one having random
effect.
Why use mixed models?
• When repeated measurements are made on
the same statistical units, it would not be
realistic to assume that these measurements
are independent.
• We can take this dependence into account by
specifying covariance structures using a mixed
model
Definition
• A mixed model can be represented in matrix
notation by:
= 0  + 1  +
•  is the vector of observations
• 0 is the vector of fixed effects
• 1 is the vector of random effects
•  is the vector of I.I.D. error terms
•  and  are matrices relating 0 and 1 to
Assumptions
1 ~Normal 0, G
~Normal 0, R
R and G are constants
We also assume that 1 and  are
independent
• We get V = ZGZ' + R, where V is the variance of
y
•
•
•
•
How to estimate 0 and 1 ?
If R and G are given: Using Henderson’s Mixed
Model equation, we have:
′ −1

′ −1
′ −1

′ −1  +  −1
0
′ −1
= ′ −1

1
So
0 = ( ′  −1  )−1 X′y
And
1 = ′ −1 (y − X0 )
What if G and R are unknown?
• We know that both 1 and  are normally
distributed, so the best approach is to use
likelihood based methods
• There are two methods used by SAS:
• 1)Maximum likelihood (ML)
• 2)Restricted/residual maximum likelihood
(REML)
Example
Below is a table of growth measurements for 11
girls and 16 boys at ages 8, 10, 12, 14:
Person
1
2
3
4
5
6
7
8
9
10
11
12
13
14
gender
F
F
F
F
F
F
F
F
F
F
F
M
M
M
age8 age10 age12
21.0 20.0
21.5
21.0 21.5
24.0
20.5 24.0
24.5
23.5 24.5
25.0
21.5 23.0
22.5
20.0 21.0
21.0
21.5 22.5
23.0
23.0 23.0
23.5
20.0 21.0
22.0
16.5 19.0
19.0
24.5 25.0
28.0
26.0 25.0
29.0
21.5 22.5
23.0
23.0 22.5
24.0
age14
23.0
25.5
26.0
26.5
23.5
22.5
25.0
24.0
21.5
19.5
28.0
31.0
26.5
27.5
Person
15
16
17
18
19
20
21
22
23
24
25
26
27
gender
M
M
M
M
M
M
M
M
M
M
M
M
M
age8 age10 age12
25.5 27.5 26.5
20.0 23.5 22.5
24.5 25.5 27.0
22.0 22.0 24.5
24.0 21.5 24.5
23.0 20.5 31.0
27.5 28.0 31.0
23.0 23.0 23.5
21.5 23.5 24.0
17.0 24.5 26.0
22.5 25.5 25.5
23.0 24.5 26.0
22.0 21.5 23.5
age14
27.0
26.0
28.5
26.5
25.5
26.0
31.5
25.0
28.0
29.5
26.0
30.0
25.0
Using SAS
data pr;
input Person Gender \$ y1 y2 y3 y4;
y=y1; Age=8; output;
y=y2; Age=10; output;
y=y3; Age=12; output;
y=y4; Age=14; output;
drop y1-y4;
datalines;
1 F 21.0 20.0 21.5 23.0
2 F 21.0 21.5 24.0 25.5
…
;
Run;
Using SAS
proc mixed data=pr method=ml covtest;
class Person Gender;
model y = Gender Age Gender*Age / s;
repeated / type=un subject=Person r;
run;
Results
Model Information
Data Set
WORK.PR
Dependent Variable
y
Covariance Structure
Unstructured
Subject Effect
Person
Estimation Method
ML
Residual Variance Method
None
Fixed Effects SE Method
Model-Based
Degrees of Freedom Method
Between-Within
As one can see, the covariance matrix is unstructured, as we are going to estimate
it using the maximum likelihood method
Class Level Information
Class
Person
Gender
Levels Values
27 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25 26 27
2 FM
Dimensions
Covariance Parameters
10
Columns in X
6
Columns in Z
0
Subjects
27
Max Obs Per Subject
4
As one can see, we do not have a Z matrix for this model
Number of Observations
108
Number of Observations Used
108
Number of Observations Not Used
0
Iteration History
Iteration
Evaluations
-2 Log Like
Criterion
0
1
478.24175986
1
2
419.47721707
0.00000152
2
1
419.47704812
0.00000000
Convergence criteria met.
the convergence of the Newton-Raphson algorithm means that we have found the
maximum likelihood estimates
Covariance Parameter Estimates
Cov Parm
Subject
Estimate
Standard Error
Z Value
Pr Z
UN(1,1)
Person
5.1192
1.4169
3.61
0.0002
UN(2,1)
Person
2.4409
0.9835
2.48
0.0131
UN(2,2)
Person
3.9279
1.0824
3.63
0.0001
UN(3,1)
Person
3.6105
1.2767
2.83
0.0047
UN(3,2)
Person
2.7175
1.0740
2.53
0.0114
UN(3,3)
Person
5.9798
1.6279
3.67
0.0001
UN(4,1)
Person
2.5222
1.0649
2.37
0.0179
UN(4,2)
Person
3.0624
1.0135
3.02
0.0025
UN(4,3)
Person
3.8235
1.2508
3.06
0.0022
UN(4,4)
Person
4.6180
1.2573
3.67
0.0001
The table lists the 10 estimated covariance parameters
in order. In other words, these are the estimates for R,
the variance of
Solution for Fixed Effects
Effect
Gender
Intercept
Gender
F
Gender
M
Age
Age*Gender
F
Age*Gender
M
Estimate
Standard Error
DF
t Value
Pr > |t|
15.8423
0.9356
25
16.93
<.0001
1.5831
1.4658
25
1.08
0.2904
0
.
.
.
.
0.8268
0.07911
25
10.45
<.0001
-0.3504
0.1239
25
-2.83
0.0091
0
.
.
.
.
From this table, we see that the boys intercept is at 15.8423,
whole the girls intercept is at 15.8423+1.5831=17.42.
The estimate of the boys’ slope is at 0.827, while the girls’ slpe is
at 0.827-0.350=0.477
So the girls’ starting point is higher than the girls but their
growth rate is only about half of that of the boys
Type 3 Tests of Fixed Effects
Effect
Num DF
Den DF
F Value
Pr > F
Gender
1
25
1.17
0.2904
Age
1
25
110.54
<.0001
Age*Gender
1
25
7.99
0.0091
This is probably the most important table from our results:
The gender row tests the null hypothesis that girls and boys have a
common intercept.
As we can see we cannot reject that hypothesis
The Age tests the null hypothesis that age does not affect the growth
rate.
As we can see, we reject the null hypothesis as the F-value is large.
The Age*gender tests reveals that there is a difference in slope at the
1% significance level.
Repeated Measures ANOVA vs.
Independent Measures ANOVA
Magarate Brown
• Can we just use standard ANOVA with
repeated measures data?
• No, Independent Measures (standard) ANOVA
assumes the data are independent.
• Data from a repeated measures experiment
 not independent
How are standard ANOVA and
repeated measures ANOVA the same?
• Independent measures ANOVA: an extension
of the pooled variance t-test
• Repeated Measures ANOVA: an extension of
the paired sample t-test
How are standard ANOVA and
repeated measures ANOVA the same?
• Independent measures ANOVA: assumes the
population variances are equal (homogeneity
of variance)
• Repeated Measures ANOVA: sphericity
assumption that the population variances of
all the differences are equal
How are standard ANOVA and
repeated measures ANOVA the same?
• Both assume Normality of the population
Measures
• Limited number of subjects available
• Prefer to limit the number of subjects
• Less variability (finger tapping with caffeine
example)
• Can examine effects over time
Drawbacks
• Practice effect
• Example: subjects get better at performing a task
each time with “practice”
• Differential transfer: “This occurs when the
effects of one condition persist and affect
participants’ experiences during subsequent
conditions.” (format:
http://www.psychmet.com/id16.html)
• Example: medical treatments
Resources (to be formatted)
• http://www.psychmet.com/id16.html
• http://www.utexas.edu/courses/schwab/sw38
8r7_spring_2007/SolvingProblemsInSPSS/Solv
ing%20Repeated%20Measures%20ANOVA%2
0Problems.pdf
• http://en.wikipedia.org/wiki/Repeated_measu
res
• http://www.mhhe.com/socscience/psycholog
y/shaugh/ch07_summary.html
```