Stat 112: Lecture 23 Notes

16
Stat 112: Lecture 23 Notes • Chapter 9.3: Two-way Analysis of Variance • Schedule: – Homework 6 is due on Friday. – Quiz 4 is next Tuesday. – Final homework assignment will be e-mailed this weekend and due next Monday. – Final Project due on Dec. 19th

description

Stat 112: Lecture 23 Notes. Chapter 9.3: Two-way Analysis of Variance Schedule: Homework 6 is due on Friday. Quiz 4 is next Tuesday. Final homework assignment will be e-mailed this weekend and due next Monday. Final Project due on Dec. 19th. Two-way Analysis of Variance. - PowerPoint PPT Presentation

Transcript of Stat 112: Lecture 23 Notes

Page 1: Stat 112: Lecture 23 Notes

Stat 112: Lecture 23 Notes

• Chapter 9.3: Two-way Analysis of Variance

• Schedule: – Homework 6 is due on Friday.– Quiz 4 is next Tuesday.– Final homework assignment will be e-mailed

this weekend and due next Monday. – Final Project due on Dec. 19th

Page 2: Stat 112: Lecture 23 Notes

Two-way Analysis of Variance• We have observations from different groups,

where the groups are classified by two factors.• Goal of two-way analysis of variance: Find out

how the mean response in a group depends on the levels of both factors and find the best combination.

• As with one-way analysis of variance, two-way analysis of variance can be seen as a a special case of multiple regression. For two-way analysis of variance, we have two categorical explanatory variables for the two factors and also include an interaction between the factors.

Page 3: Stat 112: Lecture 23 Notes

Two-way Analysis of Variance Example

• Package Design Experiment: Several new types of cereal packages were designed. Two colors and two styles of lettering were considering. Each combination of lettering/color was used to produce a package, and each of these combinations was test marketed in 12 comparable stores and sales in the stores were recorded.. Two-way analysis of variance in which two factors are color (levels red, green) and lettering (levels block, script).

Page 4: Stat 112: Lecture 23 Notes

Response Sales Effect Tests Source Nparm DF Sum of Squares F Ratio Prob > F Color 1 1 4641.3333 3.1762 0.0816 TypeStyle 1 1 5985.3333 4.0959 0.0491 TypeStyle*Color 1 1 972.0000 0.6652 0.4191 Expanded Estimates Nominal factors expanded to all levels Term Estimate Std Error t Ratio Prob>|t| Intercept 144.91667 5.517577 26.26 <.0001 Color[Green] -9.833333 5.517577 -1.78 0.0816 Color[Red] 9.8333333 5.517577 1.78 0.0816 TypeStyle[Block] -11.16667 5.517577 -2.02 0.0491 TypeStyle[Script] 11.166667 5.517577 2.02 0.0491 TypeStyle[Block]*Color[Green] -4.5 5.517577 -0.82 0.4191 TypeStyle[Block]*Color[Red] 4.5 5.517577 0.82 0.4191 TypeStyle[Script]*Color[Green] 4.5 5.517577 0.82 0.4191 TypeStyle[Script]*Color[Red] -4.5 5.517577 -0.82 0.4191

Estimated Mean for Red Block group = 144.92+9.83-11.17+4.5 = 148.08Estimated Mean for Red Script group = 144.92+9.83+11.17-4.5= 161.42

Page 5: Stat 112: Lecture 23 Notes

Interaction in Two-Way ANOVA

• Interaction between two factors: The impact of one factor on the response depends on the level of the other factor.

• For package design experiment, there would be an interaction between color and typestyle if the impact of color on sales depended on the level of typestyle.

• Formally, there is an interaction if

• LS Means Plot suggests there is not much interaction. Impact of changing color from red to green on mean sales is about the same when the typestyle is block as when the typestyle is script.

LS Means Plot

Sal

esLS

Mea

ns

50

100

150

200

250

BlockScript

Green Red

Color

scriptgreenblockgreenscriptredblockred ,,,,

Page 6: Stat 112: Lecture 23 Notes

Effect Test for Interaction

• A formal test of the null hypothesis that there is no interaction,

for all levels i,j,i’,j’ of factors 1 and 2, versus the alternative hypothesis that there is an interaction is given by the Effect Test for the interaction variable (here Typestyle*Color).

• p-value for Effect Test = 0.4191. No evidence of an interaction.

''','0 : jiijjiijH

Effect Tests Source Nparm DF Sum of Squares F Ratio Prob > F Color 1 1 4641.3333 3.1762 0.0816 TypeStyle 1 1 5985.3333 4.0959 0.0491 TypeStyle*Color 1 1 972.0000 0.6652 0.4191

Page 7: Stat 112: Lecture 23 Notes

Implications of No Interaction

• When there is no interaction, the two factors can be looked in isolation, one at a time.

• When there is no interaction, best group is determined by finding best level of factor 1 and best level of factor 2 separately.

• For package design experiment, suppose there are two separate groups: one with an expertise in lettering and the other with expertise in coloring. If there is no interaction, groups can work independently to decide best letter and color. If there is an interaction, groups need to get together to decide on best combination of letter and color.

Page 8: Stat 112: Lecture 23 Notes

Model when There is No Interaction

• When there is no evidence of an interaction, we can drop the interaction term from the model for parsimony and more accurate estimates:Response Sales Effect Tests Source Nparm DF Sum of Squares F Ratio Prob > F Color 1 1 4641.3333 3.2000 0.0804 TypeStyle 1 1 5985.3333 4.1266 0.0481 Expanded Estimates Nominal factors expanded to all levels Term Estimate Std Error t Ratio Prob>|t| Intercept 144.91667 5.497011 26.36 <.0001 Color[Green] -9.833333 5.497011 -1.79 0.0804 Color[Red] 9.8333333 5.497011 1.79 0.0804 TypeStyle[Block] -11.16667 5.497011 -2.03 0.0481 TypeStyle[Script] 11.166667 5.497011 2.03 0.0481

Mean for red block group = 144.92+9.83-11.17=143.58Mean for red script group = 144.92+9.83+11.17=165.92

Page 9: Stat 112: Lecture 23 Notes

Tests for Main Effects When There is No Interaction

• Effect test for color: Tests null hypothesis that group mean does not depend on color versus alternative that group mean is different for at least two levels of color. p-value =0.0804, moderate but not strong evidence that group mean depends on color.

• Effect test for TypeStyle: Tests null hypothesis that group mean does not depend on TypeStyle versus alternative that group mean is different for at least two levels of TypeStyle. p-value = 0.0481, evidence that group mean depends on TypeStyle.

• These are called tests for “main effects.” These tests only make sense when there is no interaction.

Response Sales Effect Tests Source Nparm DF Sum of Squares F Ratio Prob > F Color 1 1 4641.3333 3.2000 0.0804 TypeStyle 1 1 5985.3333 4.1266 0.0481 Expanded Estimates Nominal factors expanded to all levels Term Estimate Std Error t Ratio Prob>|t| Intercept 144.91667 5.497011 26.36 <.0001 Color[Green] -9.833333 5.497011 -1.79 0.0804 Color[Red] 9.8333333 5.497011 1.79 0.0804 TypeStyle[Block] -11.16667 5.497011 -2.03 0.0481 TypeStyle[Script] 11.166667 5.497011 2.03 0.0481

Page 10: Stat 112: Lecture 23 Notes

Example with an Interaction

• Should the clerical employees of a large insurance company be switched to a four-day week, allowed to use flextime schedules or kept to the usual 9-to-5 workday?

• The data set flextime.JMP contains percentage efficiency gains over a four week trial period for employees grouped by two factors: Department (Claims, Data Processing, Investment) and Condition (Flextime, Four-day week, Regular Hours).

Page 11: Stat 112: Lecture 23 Notes

Response Improve Effect Tests Source Nparm DF Sum of Squares F Ratio Prob > F Department 2 2 154.3087 8.0662 0.0006 Condition 2 2 0.5487 0.0287 0.9717 Condition*Department 4 4 5588.2004 146.0566 <.0001 There is strong evidence of an interaction. Interaction Profiles

-15

-5

5

15

25

Impr

ove

-15

-5

5

15

25

Impr

ove

Department

Flex

FourDayRegular

Cla

ims

DP

Inve

stClaimsDPInvest

Condition

Fle

x

Fou

rDay

Reg

ular

Departm

entC

ondition

Which schedule is best appears to differ by department.Four day is best for investment employees, but worst for data processing employees.

Page 12: Stat 112: Lecture 23 Notes

Which Combinations Works Best?

• For which pairs of groups is there strong evidence that the groups have different means – is there strong evidence that one combination works best?

• We combine the two factors into one factor (Combination) and use Tukey’s HSD, to compare groups pairwise, adjusting for multiple comparisons.

Page 13: Stat 112: Lecture 23 Notes

Oneway Analysis of Improve By Combination Means Comparisons Comparisons for all pairs using Tukey-Kramer HSD Level Mean DPFlex A 16.89091 InvestFourDay A 16.87273 InvestRegular B 9.38182 ClaimsFlex C 4.32727 ClaimsRegular C 4.20000 ClaimsFourDay C 3.12727 DPRegular C 2.21818 DPFourDay D -4.74545 InvestFlex D -5.65455 Levels not connected by same letter are significantly different For Data Processing employees, there is strong evidence that flextime is best. For Investment employees, there is strong evidence that Four Day is best. For claims employees, there is not strong evidence that any of the schedules have different means.

Page 14: Stat 112: Lecture 23 Notes

Checking Assumptions

• As with one-way ANOVA, two-way ANOVA is a special case of multiple regression and relies on the assumptions: – Linearity: Automatically satisfied– Constant variance: Spread within groups is the same

for all groups.– Normality: Distribution within each group is normal.

• To check assumptions, combine two factors into one factor (Combination) and check assumptions as in one-way ANOVA.

Page 15: Stat 112: Lecture 23 Notes

Checking Assumptions

• Check for constant variance: (Largest standard deviation of group/Smallest standard deviation of group)

=(44.85/33.51) <2. Constant variance OK.• Check for normality: Look at normal

quantile plots for each combination (not shown). For all normal quantile plots, the points fall within the 95% confidence bands. Normality assumption OK.

Means and Std Deviations Level Number Mean Std Dev Std Err Mean Lower 95% Upper 95% GreenBlo 12 119.417 37.4929 10.823 95.59 143.24 GreenScr 12 150.750 33.5129 9.674 129.46 172.04 RedBlock 12 148.083 44.8461 12.946 119.59 176.58 RedScrip 12 161.417 36.1272 10.429 138.46 184.37

Page 16: Stat 112: Lecture 23 Notes

Two way Analysis of Variance: Steps in Analysis

1. Check assumptions (constant variance, normality, independence). If constant variance is violated, try transformations.

2. Use the effect test (commonly called the F-test) to test whether there is an interaction.

3. If there is no interaction, use the main effect tests to whether each factor has an effect. Compare individual levels of a factor by using t-tests with Bonferroni correction for the number of comparisons being made.

4. If there is an interaction, use the interaction plot to visualize the interaction. Create combination of the factors and use Tukey’s HSD procedure to investigate which groups are different, taking into account the fact multiple comparisons are being done.