topic 29: three-way anova - purdue universitybacraig/notes512/topic_29.pdf · data for three-way...
TRANSCRIPT
![Page 1: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/1.jpg)
Topic 29: Three-Way
ANOVA
![Page 2: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/2.jpg)
Outline
• Three-way ANOVA
–Data
–Model
– Inference
![Page 3: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/3.jpg)
Data for three-way
ANOVA• Y, the response variable
• Factor A with levels i = 1 to a
• Factor B with levels j = 1 to b
• Factor C with levels k = 1 to c
• Yijkl is the lth observation in cell (i,j,k),
l = 1 to nijk
• A balanced design has nijk=n
![Page 4: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/4.jpg)
KNNL Example
• KNNL p 1005
• Y is exercise tolerance, minutes until fatigue on a bicycle test
• A is sex, a=2 levels: male, female
• B is percent body fat, b=2 levels: high, low
• C is smoking history, c=2 levels: light, heavy
• n=3 persons aged 25-35 per (i,j,k) cell
![Page 5: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/5.jpg)
Read and check the data
data a1;
infile 'c:\...\CH24TA04.txt';
input extol sex fat smoke;
proc print data=a1;
run;
![Page 6: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/6.jpg)
Obs extol sex fat smoke1 24.1 1 1 12 29.2 1 1 13 24.6 1 1 14 20.0 2 1 15 21.9 2 1 16 17.6 2 1 17 14.6 1 2 18 15.3 1 2 19 12.3 1 2 110 16.1 2 2 111 9.3 2 2 112 10.8 2 2 113 17.6 1 1 2. . . 24 6.1 2 2 2
![Page 7: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/7.jpg)
Define variable for a plotdata a1; set a1;
if (sex eq 1)*(fat eq 1)*(smoke eq 1)
then gfs='1_Mfs';
if (sex eq 1)*(fat eq 2)*(smoke eq 1)
then gfs='2_MFs';
if (sex eq 1)*(fat eq 1)*(smoke eq 2)
then gfs='3_MfS';
if (sex eq 1)*(fat eq 2)*(smoke eq 2)
then gfs='4_MFS';
if (sex eq 2)*(fat eq 1)*(smoke eq 1)
then gfs='5_Ffs';
if (sex eq 2)*(fat eq 2)*(smoke eq 1)
then gfs='6_FFs';
if (sex eq 2)*(fat eq 1)*(smoke eq 2)
then gfs='7_FfS';
if (sex eq 2)*(fat eq 2)*(smoke eq 2)
then gfs='8_FFS';
run;
![Page 8: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/8.jpg)
Obs extol sex fat smoke gfs
1 24.1 1 1 1 1_Mfs
2 29.2 1 1 1 1_Mfs
3 24.6 1 1 1 1_Mfs
4 17.6 1 1 2 3_MfS
5 18.8 1 1 2 3_MfS
6 23.2 1 1 2 3_MfS
7 14.6 1 2 1 2_MFs
8 15.3 1 2 1 2_MFs
9 12.3 1 2 1 2_MFs
10 14.9 1 2 2 4_MFS
11 20.4 1 2 2 4_MFS
12 12.8 1 2 2 4_MFS
![Page 9: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/9.jpg)
Plot the data
title1 'Plot of the data';
symbol1 v=circle i=none c=black;
proc gplot data=a1;
plot extol*gfs/frame;
run;
![Page 10: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/10.jpg)
![Page 11: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/11.jpg)
Find the means
proc sort data=a1;
by sex fat smoke;
proc means data=a1;
output out=a2 mean=avextol;
by sex fat smoke;
![Page 12: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/12.jpg)
Define fat*smokedata a2; set a2;
if (fat eq 1)*(smoke eq 1)
then fs='1_fs';
if (fat eq 1)*(smoke eq 2)
then fs='2_fS';
if (fat eq 2)*(smoke eq 1)
then fs='3_Fs';
if (fat eq 2)*(smoke eq 2)
then fs='4_FS';
![Page 13: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/13.jpg)
Obs sex fat smoke FR avextol fs
1 1 1 1 3 25.97 1_fs
2 2 1 1 3 19.83 1_fs
3 1 1 2 3 19.87 2_fS
4 2 1 2 3 12.13 2_fS
5 1 2 1 3 14.07 3_Fs
6 2 2 1 3 12.07 3_Fs
7 1 2 2 3 16.03 4_FS
8 2 2 2 3 10.20 4_FS
![Page 14: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/14.jpg)
Plot the means
proc sort data=a2; by fs;
title1 'Plot of the means';
symbol1 v='M' i=join c=black;
symbol2 v='F' i=join c=black;
proc gplot data=a2;
plot avextol*fs=sex/frame;
run;
![Page 15: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/15.jpg)
![Page 16: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/16.jpg)
Cell means model
• Yijkl = μijk + εijkl
–where μijk is the theoretical mean
or expected value of all
observations in cell (i,j,k)
– the εijkl are iid N(0, σ2)
–Yijkl ~ N(μijk, σ2), independent
![Page 17: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/17.jpg)
Estimates
• Estimate μijk by the mean of the observations in cell (i,j,k),
• For each (i,j,k) combination, we can get an estimate of the variance
• We need to combine these to get an estimate of σ2
ijk ijk ijkl ijklˆ Y n Y
ijkY
2
2
ijk ijkl ijk ijklY n 1s Y
![Page 18: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/18.jpg)
Pooled estimate of σ2
• We pool the sijk2, giving weights
proportional to the df, nijk -1
• The pooled estimate is
2 2
ijk ijk ijkijk ijkn 1 n 1s s
![Page 19: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/19.jpg)
Factor effects model
• Model cell mean as
μijk = μ + αi + βj + γk + (αβ)ij + (αγ)ik + (βγ)jk + (αβγ)ijk
• μ is the overall mean
• αi, βj, γk are the main effects of A, B, and C
• (αβ)ij, (αγ)ik, and (βγ)jk are the two-way
interactions (first-order interactions)
• (αβγ)ijk is the three-way interaction
(second-order interaction)
• Extension of the usual constraints apply
![Page 20: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/20.jpg)
ANOVA table
• Sources of model variation are the three main effects, the three two-way interactions, and the one three-way interaction
• With balanced data the SS and DF add to the model SS and DF
• Still have Model + Error = Total
• Each effect is tested by an F statistic with MSE in the denominator
![Page 21: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/21.jpg)
Run proc glm
proc glm data=a1;
class sex fat smoke;
model extol=sex fat smoke
sex*fat sex*smoke
fat*smoke sex*fat*smoke;
means sex*fat*smoke;
run;
![Page 22: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/22.jpg)
Run proc glm
proc glm data=a1;
class sex fat smoke;
model extol=sex|fat|smoke;
means sex*fat*smoke;
run;
Shorthand way to
express model
![Page 23: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/23.jpg)
SAS Parameter Estimates
• Solution option on the model statement
gives parameter estimates for the glm
parameterization
• These are as we have seen before; any
main effect or interaction with a
subscript of a, b, or c is zero
• These reproduce the cell means in the
usual way
![Page 24: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/24.jpg)
ANOVA Table
Source DF
Sum of
Squares Mean Square F Value Pr > F
Model 7 588.582917 84.0832738 9.01 0.0002
Error 16 149.366667 9.3354167
Corrected Total 23 737.949583
Type I and III SS
the same here
![Page 25: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/25.jpg)
Factor effects output
Source DF Type I SS Mean Square F Value Pr > F
sex 1 176.58375 176.5837500 18.92 0.0005
fat 1 242.57042 242.5704167 25.98 0.0001
sex*fat 1 13.650417 13.6504167 1.46 0.2441
smoke 1 70.383750 70.3837500 7.54 0.0144
sex*smoke 1 11.0704167 11.0704167 1.19 0.2923
fat*smoke 1 72.453750 72.4537500 7.76 0.0132
sex*fat*smoke 1 1.8704167 1.8704167 0.20 0.6604
![Page 26: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/26.jpg)
Analytical Strategy• First examine interactions…highest order to
lowest order
• Some options when one or more interactions are
significant
– Interpret the plot of means
– Run analyses for each level of one factor, eg
run A*B by C (lsmeans with slice option)
– Run as a one-way with abc levels
– Define a composite factor by combining two
factors, eg AB with ab levels
– Use contrasts
![Page 27: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/27.jpg)
Analytical Strategy
• Some options when no interactions
are significant
–Use a multiple comparison
procedure for the main effects
–Use contrasts
–When needed, rerun without the
interactions
![Page 28: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/28.jpg)
Example Interpretation
•Since there appears to be a
fat by smoke interaction,
let’s run a two-way ANOVA (no
interaction-note:pooling not
necessary here) using the
fat*smoke variable
•Note that we could also use
the interaction plot to
describe the interaction
![Page 29: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/29.jpg)
Run glm
proc glm data=a1;
class sex fs;
model extol=sex fs;
means sex fs/tukey;
run;
![Page 30: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/30.jpg)
ANOVA Table
Source DF
Sum of
Squares Mean Square F Value Pr > F
Model 4 561.99167 140.4979167 15.17 <.0001
Error 19 175.95792 9.2609430
Corrected Total 23 737.94958
![Page 31: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/31.jpg)
Factor effects output
Source DF Type I SS
Mean
Square F Value Pr > F
sex 1 176.58375 176.5837500 19.07 0.0003
fs 3 385.40792 128.4693056 13.87 <.0001
Both are significant as
expected…compare means
![Page 32: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/32.jpg)
Means for sex
Mean N sex
A 18.983 12 1
B 13.558 12 2
![Page 33: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/33.jpg)
Tukey comparisons for fs
Mean N fsA 22.900 6 1_fs
B 16.000 6 2_fSBB 13.117 6 4_FSBB 13.067 6 3_Fs
![Page 34: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/34.jpg)
Conclusions
• sex difference with males having a
roughly 5.5 minute higher exercise
tolerance – beneficial to add CI here
• There was a smoking history by body
fat level interaction where those who
were low body fat and had a light
smoking history had a significantly
higher exercise tolerance than the
other three groups
![Page 35: Topic 29: Three-Way ANOVA - Purdue Universitybacraig/notes512/Topic_29.pdf · Data for three-way ANOVA •Y, the response variable •Factor A with levels i = 1 to a •Factor B with](https://reader035.vdocuments.net/reader035/viewer/2022062223/5f02701d7e708231d404439e/html5/thumbnails/35.jpg)
Last slide
• Read NKNW Chapter 24
• We used program topic29.sas to
generate the output for today