SAC: Chapter 9: Problems 18 and 22

So your problem was with the .98 number on 18…



########################## Problem 9.18
A1 = c(12.4, 10.7, 11.9, 11, 12.4, 12.3, 13, 12.5, 11.2, 13.1)
A2 = c(9.1, 11.5, 11.3, 9.7, 13.2, 10.7, 10.6, 11.3, 11.1, 11.7)
A3 = c(8.5, 11.6, 10.2, 10.9, 9, 9.6, 9.9, 11.3, 10.5, 11.2)
A4 = c(12.7, 13.2, 11.8, 11.9, 12.2, 11.2, 13.7, 11.8, 12.2, 11.7)
S = c(8.7, 9.3, 8.2, 8.3, 9, 9.4, 9.2, 12.2, 8.5, 9.9)


y = c(A1, A2, A3, A4, S)
factor = c(rep(1, length(A1)), rep(2, length(A2)), rep(3, length(A3)), 
    rep(4, length(A4)), rep(5, length(S)))

lm(y ~ as.factor(factor))
## 
## Call:
## lm(formula = y ~ as.factor(factor))
## 
## Coefficients:
##        (Intercept)  as.factor(factor)2  as.factor(factor)3  
##              12.05               -1.03               -1.78  
## as.factor(factor)4  as.factor(factor)5  
##               0.19               -2.78  
## 
anova(lm(y ~ as.factor(factor)))
## Analysis of Variance Table
## 
## Response: y
##                   Df Sum Sq Mean Sq F value  Pr(>F)    
## as.factor(factor)  4   61.6   15.40    15.7 4.2e-08 ***
## Residuals         45   44.2    0.98                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

I also input 9.22 for you for your comparison.. Notice that this is an unbalanced design so your Type I sums of squares will not equal your Type II or Type III.

######################### Problem 9.22
gr1 = c(19.4, 32.6, 27, 32.1, 33)
gr2 = c(18.2, 24.6, 25.5, 19.4, 21.7, 20.8)
gr3 = c(20.7, 21, 20.5, 18.8, 18.6, 20.1, 21.3)
c(gr1, gr2, gr3)
##  [1] 19.4 32.6 27.0 32.1 33.0 18.2 24.6 25.5 19.4 21.7 20.8 20.7 21.0 20.5
## [15] 18.8 18.6 20.1 21.3
y = c(gr1, gr2, gr3)
factor = rep(1, length(gr1))
rep(1, length(gr1))
## [1] 1 1 1 1 1
c(rep(1, length(gr1)), rep(2, length(gr2)), rep(3, length(gr3)))
##  [1] 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3
factor = c(rep(1, length(gr1)), rep(2, length(gr2)), rep(3, length(gr3)))
lm(y ~ factor)
## 
## Call:
## lm(formula = y ~ factor)
## 
## Coefficients:
## (Intercept)       factor  
##       31.90        -4.18  
## 
anova(lm(y ~ factor))
## Analysis of Variance Table
## 
## Response: y
##           Df Sum Sq Mean Sq F value Pr(>F)   
## factor     1    206   205.9    15.5 0.0012 **
## Residuals 16    213    13.3                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

length(gr1)
## [1] 5
length(gr2)
## [1] 6
length(gr3)
## [1] 7

library(car)
## Loading required package: MASS
## Loading required package: nnet
Anova((lm(y ~ factor)))
## Anova Table (Type II tests)
## 
## Response: y
##           Sum Sq Df F value Pr(>F)   
## factor       206  1    15.5 0.0012 **
## Residuals    213 16                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1