




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















This topic will cover
The response variable Y is continuous.
There are now two categorical explanatory variables (factors). Call them factor A and factor B instead of X 1 and X 2. (We will have enough subscripts as it is!)
In Chapter 19, we for now assume equal sample size in each treatment combination (ni,j = n > 1; nT = abn). This is called a balanced design. In later chapters we will deal with unequal sample sizes, but it is more complicated.
Notation
For Yi,j,k the subscripts are interpreted as follows:
i = 1,... , a levels of factor A j = 1,... , b levels of factor B k = 1,... , n observations in cell (i, j)
Read the data
data bread; infile ’h:\System\Desktop\CH19TA07.DAT’; input sales height width; proc print data=bread;
Obs sales height width 1 47 1 1 2 43 1 1 3 46 1 2 4 40 1 2 5 62 2 1 6 68 2 1 7 67 2 2 8 71 2 2 9 41 3 1 10 39 3 1 11 42 3 2 12 46 3 2
We assume that the response variable observations are independent, and normally distributed with a mean that may depend on the levels of the factors A and B, and a variance that does not (is constant).
Yi,j,k = μi,j + i,j,k where
There are ab + 1 parameters of the model: μi,j , for i = 1 to a and j = 1 to b; and σ^2.
means statement height × width
Level of Level of ------------sales------------ height width N Mean Std Dev 1 1 2 45.0000000 2. 1 2 2 43.0000000 4. 2 1 2 65.0000000 4. 2 2 2 69.0000000 2. 3 1 2 40.0000000 1. 3 2 2 44.0000000 2.
Code the factor levels and plot
(We’re just doing this for a nice plot; it is not necessary for the analysis.)
data bread; set bread; if height eq 1 and width eq 1 then hw=’1_BR’; if height eq 1 and width eq 2 then hw=’2_BW’; if height eq 2 and width eq 1 then hw=’3_MR’; if height eq 2 and width eq 2 then hw=’4_MW’; if height eq 3 and width eq 1 then hw=’5_TR’; if height eq 3 and width eq 2 then hw=’6_TW’; title2 ’Sales vs. treatment’; symbol1 v=circle i=none; proc gplot data=bread; plot sales*hw;
Put the means in a new dataset
proc means data=bread; var sales; by height width;
output out=avbread mean=avsales; proc print data=avbread;
Obs height width TYPE FREQ avsales 1 1 1 0 2 45 2 1 2 0 2 43 3 2 1 0 2 65 4 2 2 0 2 69 5 3 1 0 2 40 6 3 2 0 2 44
Plot the means
Recall the plotting syntax to get two separate lines for the two width levels. We can also do a plot of sales vs width with three lines for the three heights.
This type of plot is called an “interaction plot” for reasons that we will see later.
symbol1 v=square i=join c=black; symbol2 v=diamond i=join c=black; symbol3 v=circle i=join c=black; proc gplot data=avbread; plot avsalesheight=width; plot avsaleswidth=height;
The Interaction plots
Questions
Does the height of the display affect sales? If yes, compare top with middle, top with bottom, and middle with bottom. Does the width of the display affect sales? Does the effect of height on sales depend on the width? Does the effect of width on sales depend on the height? If yes to the last two, that is an interaction. Notice that these questions are not straightforward to answer using the cell means model.
Zero-sum Constraints
As in the one-way model, we now have too many parameters and need now several con- straints:
α. =
i
αi = 0
β. =
j
βj = 0
(αβ).j =
i
(αβ)i,j = 0 ∀j (for all j)
(αβ)i. =
j
(αβ)i,j = 0 ∀i (for all i)
Estimates for Factor-effects model
ˆμ = Y¯... =
i,j,k Yi,j,k abn μ ˆi. = Y¯i.. and μˆ.j = Y¯.j. α ˆi = Y¯i.. − Y¯... and βˆj = Y¯.j. − Y¯... (αβ^ ˆ) i,j =^ Y¯i,j.^ −^ Y¯i..^ −^ Y¯.j.^ + Y¯...
SS for ANOVA Table
i,j,k αˆ
2 i =^
i,j,k( Y¯i.. − Y¯...)^2 = nb ∑ i( Y¯i.. − Y¯ )^2 factor A sum of squares SSB =
i,j,k βˆ^2 j =^
i,j,k( Y¯.j.^ −^ Y¯...)
(^2) = na ∑ j ( Y¯.j.^ −^ Y¯^ )
(^2) factor B sum of squares
SSAB =
i,j,k (αβˆ)^2 i,j =^ n^
i,j (αβˆ)^2 i,j AB^ interaction sum of squares SSE =
i,j,k(Yi,j,k^ −^ Y¯i,j.)
i,j,k e
2 i,j,k error sum of squares SST =
i,j,k(Yi,j,k^ −^ Y¯...)^2 total sum of squares SSM = SSA + SSB + SSAB = SST − SSE model sum of squares SST = SSA + SSB + SSAB + SSE = SSM + SSE
df for ANOVA Table
dfA = a − 1 dfB = b − 1 dfAB = (a − 1)(b − 1) dfE = ab(n − 1) dfT = abn − 1 = nT − 1 dfM = a − 1 + b − 1 + (a − 1)(b − 1) = ab − 1
MS for ANOVA Table
(no surprises)
M SA = SSA/dfA M SB = SSB/dfB M SAB = SSAB/dfAB M SE = SSE/dfE M ST = SST /dfT M SM = SSM/dfM
Test for Factor A Effect
H 0 : αi = 0 for all i Ha : αi 6 = 0 for at least one i
The F statistic for this test is FA = M SA/M SE and under the null hypothesis this follows an F distribution with dfA, dfE.
Test for Factor B Effect
H 0 : βj = 0 for all j Ha : βj 6 = 0 for at least one j
The F statistic for this test is FB = M SB/M SE and under the null hypothesis this follows an F distribution with dfB , dfE.
Test for Interaction Effect
H 0 : (αβ)i,j = 0 for all (i, j) Ha : (αβ)i,j 6 = 0 for at least one (i, j)
The F statistic for this test is FAB = M SAB/M SE and under the null hypothesis this follows an F distribution with dfAB , dfE.
F -statistics for the tests
Notice that the denominator is always M SE and the denominator df is always dfE ; the numerators change depending on the test. This is true as long as the effects are fixed. That is to say that the levels of our variables are of intrinsic interest in themselves - they are fixed by the experimenter and not considered to be a sample from a larger population of factor levels. For random effects we would need to do something different (more later).
Other output
R-Square Coeff Var Root MSE sales Mean 0.962241 6.303040 3.214550 51.
Interpretation
Additional Analyses
Yi,j,k = μi,j + i,j,k, where
For the bread example, estimate the μi,j with Y¯i,j. which we can get from the means height*width statement:
μˆ 1 , 1 = Y¯ 1 , 1. = 45 μˆ 1 , 2 = Y¯ 1 , 2. = 43 μˆ 2 , 1 = Y¯ 2 , 1. = 65 μˆ 2 , 2 = Y¯ 2 , 2. = 69 μˆ 3 , 1 = Y¯ 3 , 1. = 40 μˆ 3 , 2 = Y¯ 3 , 2. = 44
As usual, σ^2 is estimated by M SE.
μi,j = μ + αi + βj + (αβ)i,j , where
Overall Mean
The overall mean is estimated as ˆμ = Y¯... = 51 under the zero-sum constraining. (This is sales mean in the glm output). You can get a whole dataset of this value by using a model statement with no right hand side, e.g. model sales=; and storing the predicted values.
Doing this in SAS
Unlike proc reg, you are only allowed one model statement per call to glm. But this at least saves you doing the arithmetic by hand.
proc glm data=bread; class height width; model sales=; output out=pmu p=muhat; proc glm data=bread; class height width; model sales=height; output out=pA p=Amean; proc glm data=bread; class height width; model sales=width; output out=pB p=Bmean; proc glm data=bread; class height width; model sales=height*width; output out=pAB p=ABmean; data parmest; merge bread pmu pA pB pAB; alpha = Amean - muhat; beta = Bmean - muhat; alphabeta = ABmean - (muhat+alpha+beta); proc print data=parmest;
Obs sales height width muhat Amean Bmean ABmean alpha beta alphabeta 1 47 1 1 51 44 50 45 -7 -1 2 2 43 1 1 51 44 50 45 -7 -1 2 3 46 1 2 51 44 52 43 -7 1 - 4 40 1 2 51 44 52 43 -7 1 - 5 62 2 1 51 67 50 65 16 -1 - 6 68 2 1 51 67 50 65 16 -1 - 7 67 2 2 51 67 52 69 16 1 1 8 71 2 2 51 67 52 69 16 1 1 9 41 3 1 51 42 50 40 -9 -1 - 10 39 3 1 51 42 50 40 -9 -1 - 11 42 3 2 51 42 52 44 -9 1 1 11 46 3 2 51 42 52 44 -9 1 1
α. =
i
αi = 0
β. =
j
βj = 0
(αβ).j =
i
(αβ)i,j = 0 ∀j (for all j)
(αβ).i =
i
(αβ)i,j = 0 ∀i (for all i)
All of these constraints are satisfied by the above estimates. Notice how these main and interaction effects fit together to give back the treatment means:
45 = 51 − 7 − 1 + 2 43 = 51 − 7 + 1 − 2 65 = 51 + 16 − 1 − 1 69 = 51 + 16 + 1 + 1 40 = 51 − 9 − 1 − 1 44 = 51 − 9 + 1 + 1
As usual, SAS has to do its constraints differently. As in one-way ANOVA, it sets the parameter for the last category equal to zero.
αa = 0 (1 constraint) βb = 0 (1 constraint) (αβ)a,j = 0 for all j (b constraints) (αβ)i,b = 0 for all i (a constraints)
The total is 1 + 1 + a + b − 1 = a + b + 1 constraints (the constraint (αβ)a,b is counted twice above).
Parameters and constraints
The cell means model has ab parameters for the means. The factor effects model has (1 + a + b + ab) parameters.
Means
The estimated treatment means are ˆμi,j = ˆμ + ˆαi + βˆj + (αβˆ)i,j.
height width N Mean 1 1 2 45.0000000 = 44 - 1 - 4 + 6 1 2 2 43.0000000 = 44 - 1 + 0 + 0 2 1 2 65.0000000 = 44 + 25 - 4 + 0 2 2 2 69.0000000 = 44 + 25 + 0 + 0 3 1 2 40.0000000 = 44 + 0 - 4 + 0 3 2 2 44.0000000 = 44 + 0 + 0 + 0
Source df SS MS F A a − 1 SSA M SA M SA/M SE B b − 1 SSB M SB M SB/M SE AB (a − 1)(b − 1) SSAB M SAB M SAB/M SE Error ab(n − 1) SSE M SE Total abn − 1 SST O M ST
E(M SE) = σ^2
E(M SA) = σ^2 +
nb a − 1
i
α^2 i
E(M SB) = σ^2 +
na b − 1
j
β^2 j
E(M SAB) = σ^2 +
n (a − 1)(b − 1)
i,j
(αβ)^2 i,j
Here, αi, βj , and (αβ)i,j are defined with the usual zero-sum constraints.
What if AB interaction is not significant?
If the AB interaction is not statistically significant, you could rerun the analysis without the interaction (see discussion of pooling KNNL Section 19.10). This will put the SS and df for AB into Error. Results of main effect hypothesis tests could change because M SE
and denominator df have changed (more impact with small sample size). If one main effect is not significant...
If neither main effect is significant...
For a main effect with more than two levels that is significant, use the means statement with the Tukey multiple comparison procedure. Contrasts and linear combinations can also be examined using the contrast and estimate statements.
If AB interaction is significant but not important
If AB interaction is significant and important
The interaction effect is so large and/or pervasive that main effects cannot be interpreted on their own. Options include the following:
Tukey Output
Mean N height
A 67.000 4 2
B 44.000 4 1 B B 42.000 4 3
As we noticed from the plot, the middle shelf is significantly different (better in terms of sales if we look at the plot) from the other two.
Contrast/Estimate Example
For the bread example, suppose we want to compare the average of the two height = middle cells with the average of the other four cells; i.e. look at “eye-level” vs. “not eye-level” (for the average person). With this approach, the contrast should correspond to a research question formulated before examining the data. First, formulate the question as a contrast in terms of the cell means model:
(μ 2 , 1 + μ 2 , 2 ) 2
(μ 1 , 1 + μ 1 , 2 + μ 3 , 1 + μ 3 , 2 ) 4
or L = 0, where
L = − 0. 25 μ 1 , 1 − 0. 25 μ 1 , 2 + 0. 5 μ 2 , 1 + 0. 5 μ 2 , 2 − 0. 25 μ 3 , 1 − 0. 25 μ 3 , 2
Then translate the contrast into the factor effects model using μi,j = μ + αi + βj + (αβ)i,j
− 0. 25 μ 1 , 1 = − 0 .25(μ + α 1 + β 1 + αβ 1 , 1 ) − 0. 25 μ 1 , 2 = − 0 .25(μ + α 1 + β 2 + αβ 1 , 2 )
L = (− 0. 5 α 1 + α 2 − 0. 5 α 3 ) +(− 0. 25 αβ 1 , 1 − 0. 25 αβ 1 , 2 + 0. 5 αβ 2 , 1 + 0. 5 αβ 2 , 2 − 0. 25 αβ 3 , 1 − 0. 25 αβ 3 , 2 )
Note the β’s do not appear in this contrast because we are looking at height only and averaging over width (this would not necessarily be true in an unbalanced design).
proc glm with contrast and estimate
(nknw864.sas)
proc glm data=bread; class height width; model sales=height width heightwidth; contrast ’middle vs others’ height -.5 1 -. heightwidth -.25 -.25 .5 .5 -.25 -.25; estimate ’middle vs others’ height -.5 1 -. heightwidth -.25 -.25 .5 .5 -.25 -.25; means heightwidth;
Output
Contrast DF Contrast SS Mean Square F Value Pr > F middle vs others 1 1536.000000 1536.000000 148.65 <.
Standard Parameter Estimate Error t Value Pr > |t| middle vs others 24.0000000 1.96850197 12.19 <.
Check with means
1 1 45 1 2 43 2 1 65 2 2 69 3 1 40 3 2 44
Sometimes a factor can be interpreted as either categorical or quantitative. For example, “low, medium, high” or actual height above floor. If there are replicates for a quantitative factor we could use either regression or ANOVA. Recall that GLM will treat a factor as