Professional Documents
Culture Documents
a X
X b X
r 2 a
X 2 3
X 2
Yijk − Y¯··· = r·b· Y¯i·· − Y¯··· +r · a · Y¯·j· − Y¯···
i=1 j=1 k=1 i=1 j=1
| {z } | {z } | {z }
SST otal SSA SSB
a X
X b 2 a X
X b X
r 2
+r × Y¯ij· − Y¯i·· − Y¯·j· + Y¯··· + Yijk − Y¯ij·
i=1 j=1 i=1 j=1 k=1
| {z } | {z }
SSA×B SSwithin
ANOVA Table
Example Suppose you want to determine whether the brand of laundry detergent used and the temperature affects the amount
of dirt removed from your laundry. To this end, you buy two different brand of detergent (“ Super” and “Best”) and choose
three different temperature levels (“cold”, “warm”, and “hot”). Then you divide your laundry randomly into 6 × r piles of equal
size and assign each r piles into the combination of (“Super” and “Best”) and (”cold”,”warm”, and “hot”). In this example, we
are interested in testing Null Hypotheses
H0D : The amount of dirt removed does not depend on the type of detergent
H0T : The amount of dirt removed does not depend on the temperature
One says the experiment has two factors (Factor Detergent, Factor Temperature) at a = 2(Super and Best) and b = 3(cold,warm
and hot) levels. Thus there are ab = 3 × 2 = 6 different combinations of detergent and temperature. With each combination
you wash r = 4 loads. r is called the number of replicates. This sums up to n = abr = 24 loads in total. The amounts Yijk of
dirt removed when washing sub pile k (k = 1, 2, 3, 4) with detergent i (i = 1, 2) at temperature j (j = 1, 2, 3) are recorded in
Table 1.
Solution :
X 3 X
2 X 4 2
SSwithin = Yijk − Y¯ij·
i=1 j=1 k=1
1
= (4 − 5)2 + (5 − 5)2 + (6 − 5)2 + (5 − 5)2
+(7 − 9)2 + (9 − 9)2 + (8 − 9)2 + (12 − 9)2
······
+(12 − 12)2 + (13 − 12)2 + (10 − 12)2 + (13 − 12)2
= 38
dfwithin = (r − 1) ∗ a ∗ b = 3 ∗ 2 ∗ 3 = 18
.
M Swithin = SSwithin dfwithin = 38/18 = 2.1111
• F-Test
.
M Sdetergent M Swithin ∼ F dfdetergent , dfwithin
.
M Stemperature M Swithin ∼ F dftemperature , dfwithin
.
M Sinteraction M Swithin ∼ F dfinteraction , dfwithin
2
> tapply(wash,water,mean)
1 2 3
5.00 11.00 11.25
> tapply(wash,deter,mean)
1 2
8.166667 10.000000
> tapply(wash,deter:water,mean)
1:1 1:2 1:3 2:1 2:2 2:3
5.0 9.0 10.5 5.0 13.0 12.0
> anova(lm.deter)
Analysis of Variance Table
Response: wash
Df Sum Sq Mean Sq F value Pr(>F)
deter 1 20.167 20.167 9.8108 0.005758 **
water 2 200.333 100.167 48.7297 5.44e-08 ***
deter:water 2 16.333 8.167 3.9730 0.037224 *
Residuals 18 37.000 2.056
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> matrix(round(fitted(lm.deter),1),byrow=T,nrow=2)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[1,] 5 5 5 5 9 9 9 9 10.5 10.5 10.5 10.5
[2,] 5 5 5 5 13 13 13 13 12.0 12.0 12.0 12.0
> matrix(round(residuals(lm.deter),1),byrow=T,nrow=2)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[1,] -1 0 1 0 -2 0 -1 3 -0.5 1.5 0.5 -1.5
[2,] 1 1 -1 -1 0 2 -1 -1 0.0 1.0 -2.0 1.0
> matrix(round(residuals(lm.deter),1)ˆ2,byrow=T,nrow=2)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[1,] 1 0 1 0 4 0 1 9 0.25 2.25 0.25 2.25
[2,] 1 1 1 1 0 4 1 1 0.00 1.00 4.00 1.00
interaction.plot(water,deter,wash)
deter
12
2
1
10
mean of wash
8
6
1 2 3
water