Chapter 4

ST 370 - Factorial and ANOVA

Readings: Chapter 13.1-13.2, Chapter 14.1-14.4

Recap: So far we’ve learned: • Why we want a ‘random’ sample and how to achieve it ( Scheme) • How to use , , and control/ to create a valid experi- ment. • Now well look at a specific type of and how to investigate which factors are important. Motivating Example: Mentos and Coke Consider an experiment where we want to determine the effect of initial volume (591 ml, 1000 ml, or 2000ml) on the % of coke expelled when Mentos (the freshmaker) are dropped in. A CRD was used. What is the response? Factor(s)? Level(s)? Treatments?

What parameters might answer our question?

30 Suppose we collect . Consider the following two hypothetical sets of boxplots for the data:

Which set of boxplots gives more evidence that the true differ?

Although we’ll never know the true values of the parameters, we can use our sample data to estimate them.

31 How to use these estimates to make a claim? One-Way Analysis of (ANOVA) Model (Used to analyze a CRD): Consider the data below

We ‘fit’ the following model to this completely randomized design:

32 Is the factor important in our One-Way ANOVA model?

How can we estimate each treatment ?

If these sample means differ by enough, what would this imply?

- the difference(s) in the mean response when the factor goes from one level to another.

Here, we would have two elements of our main effect. Write down their true values and their estimates.

If the differences are not

33 Ok, so now we can estimate the treatment means for the Mentos and Coke example. Does there appear to be evidence the factor is important? What information would help?

One-Way ANOVA model in statcrunch

34 Remember: Statistics is all about Variation!

Total amount of variation in the data:

ANOVA () table splits up this total variation into different sources to help determine which sources are statistically significant.

The ANOVA table generally has 6 columns • Source:

• SS:

• Df: Degrees of Freedom

• MS:

• F-stat:

• P-value:

35 In One-Way ANOVA we only have 2 sources we care about (recall sources of variation from the section!): • Treatment Effect • Error

Source: Treatment Effect • SS(Trt) =

• DF: For t treatments, we have

• Often called

• MS(Trt) =

Source: Error • SS(E) =

• DF: For N total observations and t treatments, we have

• Often called

• MS(E) =

36 Table for balanced one-way ANOVA: Source DF SS MS F SS(T ) MS(T ) Treatments t − 1 SS(T ) MS(T ) = (t−1) F = MS(E) SS(E) Error t(n − 1) SS(E) MS(E) = (N−t) Total nt − 1 SS(TOT ) where

t n t X X 2 X 2 SS(T ) = (¯yi• − y¯••) = n (¯yi• − y¯••) i=1 j=1 i=1 t n X X 2 SS(E) = (yij − y¯i•) i=1 j=1 t n X X 2 SS(T ot) = (yij − y¯••) i=1 j=1 Notes: SS(T) is also called SS(Between) and SS(E) is also called SS(Within). Treatment DF + Error DF = Total DF SS(Trt) + SS(E) = SS(Tot)

More on the F-ratio and P-value

37 Recall Boxplot idea: Consider the following two hypothetical sets of boxplots for the data:

We use the p-value to determine if the F-ratio is ‘large’ enough. If p-value is less than a pre-specified value (usually 0.05) we say have evidence that the main effect(s) are not all 0.

That is

Idea of a P-value • P-values are

• Here, p-value represents

• P-value for Initial Volume = 0.0148. Small!

Goals of One-Way ANOVA • Determine if the factor is related to the response. • If so, estimate the main effects (factor level differences)

38 One-Way ANOVA Example: (some description taken from Goosen, 2014)

Consider having 24 pieces of cheese. Color of the cheese is important in terms of consumer satisfaction. We have interest in how the color differs for 4 different types of corn syrup (26, 42, 55, and 62) (4 treatments). A CRD design is decided upon and we randomly assign each corn syrup type to 6 pieces of cheese (6 replicates for each treatment).

As a response, we measure the color using a 3 part CIE L*a*b* Color System. • ‘L’ reflects the lightness of a sample, from black (L = 0) to white (L = 100) and runs from top to bottom. • ‘a’ defines the shades from red (positive values) to green (negative values). • ‘b’ defines the shades from yellow (positive values) to blue (negative values). All three of these could be treated as responses (and analyzed together), but for our purposes we will only look at the ‘L’ response variable.

Again, we will focus on the means of the population. How might we make inference here?

Define

• µ1 = mean ‘L’ score for all pieces of cheese that with corn syrup 26.

• µ2 = mean ‘L’ score for all pieces of cheese that with corn syrup 42.

• µ3 = mean ‘L’ score for all pieces of cheese that with corn syrup 55.

• µ4 = mean ‘L’ score for all pieces of cheese that with corn syrup 62. 1. What is our factor and what are the levels of that factor?

2. What hypothesis do we want to test?

39 3. The data are given below. Fill in the label column (labeling the observations in terms of y’s) Data and labeling:

Corn Syrup Replicate # ‘L’ measurement Response Label 26 1 51.89 26 2 51.52 26 3 52.69 26 4 52.06 26 5 51.63 26 6 52.73 42 1 47.21 42 2 48.57 42 3 47.57 42 4 46.85 42 5 48.64 42 6 47.49 55 1 41.43 55 2 42.31 55 3 42.31 55 4 41.49 55 5 42.12 55 6 42.65 62 1 45.99 62 2 46.66 62 3 47.35 62 4 45.83 62 5 46.77 62 6 47.88

40 4. (from SAS) and a boxplot of the data is given below. Based on these summary measures, does there appear to be a relationship between the ‘L’ score and corn syrup amount? Justify your answer.

41 Analysis of this data can be done in SAS using the following code: (assume data is read in as cheese)

proc anova data=cheese; class syrup; model L = syrup; means syrup/tukey; run;

5. Why do we have 3 degrees of freedom for the model (aka treatment)?

6. What is the number 313.39 and what does that value represent for this data?

42 7. If the value for SS(Trt) were missing but you had SS(Tot) and SS(E), how could ou find SS(Trt)?

8. What is the relationship between the Mean square values and the F-ratio?

9. What does the MSE value of 0.41378 represent?

10. Based on the p-value what is your conclusion about the ‘hypothesis’ we are testing?

11. What does the p-value mean in words for this experiment?

12. Since we have a significant factor, we would want to estimate the main effects. Give an estimate of the main effect of syrup 42 vs syrup 26 and also for syrup 55 vs syrup 26.

43 Factorial designs • This idea of modeling can be extended to when we look at more than one factor at a time. • Factorial experiment:

• Full factorial design (henceforth factorial design):

Example: Gardner wants to look at water and fertilizer on crop yield. • factor A: Water (levels= Low, High) • factor B: Fertilizer (levels = Nitrogen, Phosphate) Treatments?

Note: In general, no need to look at all treatment combinations. However, we will only consider the full experiments.

Why do we want to look at more than one variable at a time?

44 Notation for factorial design • 2x2 factorial design = • 3x4 factorial design = • 2x3x4 factorial design = Total # of treatments is found by multiplying the #s of levels. How many treatments for each design above?

Recall: Goals of One-Way ANOVA • Determine if the factor is related to the response. • If so, estimate the main effects (factor level differences) Goals of factorial data analysis? •

Basically, which factors are important and then estimation of the appropriate effects.

45 2x2 ANOVA example: Back to Mentos and Coke Example

A CRD is run, the response is still percent of coke expelled, but consider a second factor in this experiment. • Factor A: initial volume (591 ml, 1000 ml, or 2000ml) • Factor B: # of mentos (4 or 8) What type of factorial design is this? How many total treatments?

What are the parameters of interest now?

We might assume the factors act independently of one another, called an additive (or main effects only) model.

46 Two-Way (additive) ANOVA Model

First, consider a different parametrization of the One-Way ANOVA Model.

Back to Two-Way (additive) ANOVA model Assuming the factors act independently the two-way additive ANOVA model is

47 Now we can get the ‘treatment means’ with these parameters:

• µ11 = Mean for 591 ml/4 mentos group =

• µ21 = Mean for 1000 ml/4 mentos group =

• µ31 = Mean for 2000 ml/4 mentos group =

• µ12 = Mean for 591 ml/8 mentos group =

• µ22 = Mean for 1000 ml/8 mentos group =

• µ32 = Mean for 2000 ml/8 mentos group = How can we estimate each treatment mean?

• µˆ11 =

• µˆ21 =

• µˆ31 =

• µˆ12 =

• µˆ22 =

• µˆ32 =

How to determine if the Factors are Important? If the sample means involving the same level of factor B differ by enough, then we would say factor A is important!

If the sample means involving the same level of factor A differ by enough, then we would say factor B is important

These are investigations of the main effects!

48 Let’s estimate the treatment means and main effects for this example.

49 How to fit Two-Way (additive) ANOVA model in Statcrunch?

50 More about the P-values in this model

Probability of getting our sample estimates or further apart assuming there is no effect from that factor. • P-value for # Mentos = 0.5777

• P-value for initial Volume = 0.0183

Interactions - We’ve been assuming factors act independently.

51 If the lines are , there is no visual evidence of inter- action.

If the lines are , there is visual evidence of interac- tion.

Why?

Creating plots 1. Calculate a table of

2. On the X-axis put

3. The Y-axis represents

4. Draw a point for each treatment mean. 5. Connect treatment means that have the

52 Lets recreate the interaction plots for the Mentos experiment.

Note: To get the interaction plots in statcrunch, simply check the box.

If you hit Next you can then put the plots side by side if you like

53 Recap: • To investigate the interactions in the interaction plots: – Factors A and B interact when the effect of factor A depends on the levels of factor B. – So we look for parallelism (or lack thereof). – There appears to be an interaction in the mentos and coke interaction plots, but remember this is just a visual check! — • We can also visually look at main effects using the interaction plots:

54 Modeling Interactions in Two-Way ANOVA More general than the additive model, we may consider a model with interaction effects: • call our factors factor A” and factor B” • we need to model:

Back to the Mentos and Coke Example Same 6 parameters of interest! Now we just model them differently.

• µ = overall mean % volume lost

• α1, α2, α3, β1, β2 sames as before

• (αβ)11 = interaction effect for 591 ml and 4 mentos

• (αβ)12 = interaction effect for 591 ml and 8 mentos

• (αβ)21 = interaction effect for 1000 ml and 4 mentos

• (αβ)22 = interaction effect for 1000 ml and 8 mentos

• (αβ)31 = interaction effect for 2000 ml and 4 mentos

• (αβ)32 = interaction effect for 2000 ml and 8 mentos

If no interaction then all (αβ)ij = 0, we get back the additive model!

55 To fit the interaction model in statcrunch, uncheck the box that says additive model.

Interpreting the p-value on the interaction:

56 What to report when you have an interaction and when you don’t

57 More on the ANOVA table in the Two-Factor Model

To construct the ANOVA table, we will still take the total sum of squares and split it up. Now we split it into a few more parts than previous: ANOVA table for a×b (balanced) factorial experiment

Source df Sum of Squares (SS) Mean Square (MS) F-stat A a − 1 SS(A) MS(A)=SS(A)/(a-1) MS(A)/MS(E) B b − 1 SS(B) MS(B)=SS(B)/(b-1) MS(B)/MS(E) AB (a − 1)(b − 1) SS(AB) MS(AB)=SS(AB)/((a-1)(b-1)) MS(AB)/MS(E) Error ab(n − 1) SS(E) MS(E)=SS(E)/(ab(n-1)) Total N − 1 SS(T ot)

58 Steps for Investigating Two-Way ANOVA

When fitting a model with interactions 1. First check if the interaction is significant • If significant, then both factors are important. • We should report simple effects. 2. If interaction not significant, look at main effects of each factor. • For each main effect that is significant, report the fitted main effects Example - An entomologist records energy expended (Y ) by N = 18 honeybees at a = 3 temperature (A) levels (20, 30, 40oC) consuming liquids with b = 2 levels of sucrose concen- tration (B)(20%, 40%) in a balanced, completely randomized crossed 3 × 2 design. The data are given below: Temp Suc Sample 20 20 y111=3.1 y112=3.7 y113=4.7 20 40 y121=5.5 y122=6.7 y123=7.3 30 20 y211=6 y212=6.9 y213=7.5 30 40 y221=11.5 y222=12.9 y223=13.4 40 20 y311=7.7 y312=8.3 y313=9.5 40 40 y321=15.7 y322=14.3 y323=15.9

proc glm data=ent; class Temp Suc; model Energy=Temp|Suc; *Vertical Bar fits all combinations of Temp and Suc (main effects and interactions); run;

59 1. What are the factor(s), levels, and treatments?

2. Construct an interaction plot for this experiment.

3. Which factors are important and why? State the hypothesis you are testing.

4. Report the appropriate effects given your response to the previous question.

5. What does the MSE represent for this model?

60 Example: Tomato Yield Yields on 36 tomato crops from balanced, complete, crossed design with a = 3 varieties (A) at b = 4 planting densities (B):

Variety Density k/hectare Sample 1 10 7.9 9.2 10.5 2 10 8.1 8.6 10.1 3 10 15.3 16.1 17.5 1 20 11.2 12.8 13.3 2 20 11.5 12.7 13.7 3 20 16.6 18.5 19.2 1 30 12.1 12.6 14.0 2 30 13.7 14.4 15.4 3 30 18.0 20.8 21.0 1 40 9.1 10.8 12.5 2 40 11.3 12.5 14.5 3 40 17.2 18.4 18.9 proc glm data=tomato; class variety density; model Yield=Variety|Density; run;

1. What are the factor(s), levels, and treatments?

61 2. Which factors are important and why? State the hypothesis(es) you are testing.

3. Report the appropriate effects given your response to the previous question.

4. What does the MSE represent for this model?

62