> ## sec 2.6 Wear Exp't > # > data<-read.table("wear.dat", h=T, skip=2) > data[2,3] <- "D" # fix a typo: lower case d shound be upper case D > data row col material wear 1 1 1 C 235 2 1 2 D 236 3 1 3 B 218 4 1 4 A 268 5 2 1 A 251 6 2 2 B 241 7 2 3 D 227 8 2 4 C 229 9 3 1 D 234 10 3 2 C 273 11 3 3 A 274 12 3 4 B 226 13 4 1 B 195 14 4 2 A 270 15 4 3 C 230 16 4 4 D 225 > g<- lm(wear ~ as.factor(row) + as.factor(col) + material, data = data) > anova(g) # table 2.20 Analysis of Variance Table Response: wear Df Sum Sq Mean Sq F value Pr(>F) as.factor(row) 3 986.5 328.8 5.3687 0.0390130 * as.factor(col) 3 1468.5 489.5 7.9918 0.0161685 * material 3 4621.5 1540.5 25.1510 0.0008498 *** Residuals 6 367.5 61.3 --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 > summary(g) # part of table 2.21 Call: lm(formula = wear ~ as.factor(row) + as.factor(col) + material, data = data) Residuals: Min 1Q Median 3Q Max -9.750 -2.250 0.250 3.687 8.000 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 254.750 6.187 41.174 1.37e-08 *** as.factor(row)2 -2.250 5.534 -0.407 0.698423 as.factor(row)3 12.500 5.534 2.259 0.064657 . as.factor(row)4 -9.250 5.534 -1.671 0.145658 as.factor(col)2 26.250 5.534 4.743 0.003180 ** as.factor(col)3 8.500 5.534 1.536 0.175454 as.factor(col)4 8.250 5.534 1.491 0.186608 materialB -45.750 5.534 -8.267 0.000169 *** materialC -24.000 5.534 -4.337 0.004892 ** materialD -35.250 5.534 -6.370 0.000703 *** --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 Residual standard error: 7.826 on 6 degrees of freedom Multiple R-Squared: 0.9506, Adjusted R-squared: 0.8766 F-statistic: 12.84 on 9 and 6 DF, p-value: 0.002828 > > g<- lm(wear ~ material, data = data) > anova(g) # table 2.22 Analysis of Variance Table Response: wear Df Sum Sq Mean Sq F value Pr(>F) material 3 4621.5 1540.5 6.5495 0.007155 ** Residuals 12 2822.5 235.2 --- Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1