1 ANOVA Homework Solutions EPP 245/298 Statistical Analysis of Laboratory Data
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 2 Exercise 6.1 > library(ISwR) Loading required package: survival Loading required package: splines > data(zelazo) > zelazo $active [1] $passive [1] $none [1] $ctr.8w [1]
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 3 > age.walk <- c(zelazo$active,zelazo$passive,zelazo$none,zelazo$ctr.8w) > group <- rep(c("active","passive","none","ctr.8w"),c(6,6,6,5)) > group <- as.factor(group) > group [1] active active active active active active passive passive passive [10] passive passive passive none none none none none none [19] ctr.8w ctr.8w ctr.8w ctr.8w ctr.8w Levels: active ctr.8w none passive > anova(lm(age.walk ~ group)) Analysis of Variance Table Response: age.walk Df Sum Sq Mean Sq F value Pr(>F) group Residuals > plot(age.walk ~ group)
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 4
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 5 > mgroup <- rep(c("active","passive","none"),c(6,6,11)) > mgroup <- as.factor(mgroup) > anova(lm(age.walk ~ mgroup)) Analysis of Variance Table Response: age.walk Df Sum Sq Mean Sq F value Pr(>F) mgroup Residuals Signif. codes: 0 `***' `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1 > t.test(zelazo$active,c(zelazo$none,zelazo$ctr.8w)) Welch Two Sample t-test data: zelazo$active and c(zelazo$none, zelazo$ctr.8w) t = , df = 9.327, p-value = alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: sample estimates: mean of x mean of y
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 6 Exercise 6.2 Lung data set has columns –volume = measured lung volume –method = method of measurement –subject = subject Compare the methods. Are they different? Which ones differ?
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 7 > attach(lung) > lm(volume ~ method + subject) Call: lm(formula = volume ~ method + subject) Coefficients: (Intercept) methodB methodC subject2 subject3 subject subject5 subject > lung.lm <- lm(volume ~ method + subject) > anova(lung.lm) Analysis of Variance Table Response: volume Df Sum Sq Mean Sq F value Pr(>F) method * subject * Residuals Signif. codes: 0 `***' `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 8 > tapply(volume,method,mean) A B C > tapply(volume,subject,mean) > diff(sort(tapply(volume,method,mean))) B C > plot(volume ~ method) > plot(lung.lm) Hit to see next plot: > help(plot.lm) > plot(lung.lm$resid ~ method)
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 9
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 10
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 11
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 12
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 13
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 14
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 15
November 10, 2004EPP 245 Statistical Analysis of Laboratory Data 16 > anova(lung.lm) Analysis of Variance Table Response: volume Df Sum Sq Mean Sq F value Pr(>F) method * subject * Residuals > diff(sort(tapply(volume,method,mean))) B C