################################################### ### chunk number 1: preliminaries ################################################### options(width=85, show.signif.stars = FALSE, str = strOptions(strict.width = "cut")) library(ggplot2) ################################################### ### chunk number 2: slr ################################################### y ~ x ################################################### ### chunk number 3: slr1 ################################################### y ~ 1 + x ################################################### ### chunk number 4: regthr0 ################################################### y ~ 0 + x ################################################### ### chunk number 5: regthr0alt ################################################### y ~ x - 1 ################################################### ### chunk number 6: mlr ################################################### y ~ 1 + x + z + u ################################################### ### chunk number 7: polyreg ################################################### y ~ x + I(x^2) + I(x^3) ################################################### ### chunk number 8: polyfunc ################################################### y ~ poly(x, 3) ################################################### ### chunk number 9: one-way ################################################### y ~ f ################################################### ### chunk number 10: two-way-additive ################################################### y ~ f + g ################################################### ### chunk number 11: two-way-additive-rev ################################################### y ~ g + f ################################################### ### chunk number 12: two-way-interaction ################################################### y ~ f + g + f:g ################################################### ### chunk number 13: two-way-interaction-alt ################################################### y ~ f * g ################################################### ### chunk number 14: three-factor-interaction ################################################### y ~ f * g * h ################################################### ### chunk number 15: ancova ################################################### y ~ f + x ################################################### ### chunk number 16: ancovafull ################################################### y ~ f * x ################################################### ### chunk number 17: ancovafullalt ################################################### y ~ f + x + f:x ################################################### ### chunk number 18: zerodose ################################################### y ~ x + f:x ################################################### ### chunk number 19: carbplot ################################################### print(qplot(carb,optden,data=Formaldehyde,xlab="Carbohydrate amount (ml)", ylab="Optical density")+geom_smooth(method="lm",se=FALSE)) ################################################### ### chunk number 20: lm1 ################################################### summary(lm1 <- lm(optden ~ 1 + carb, Formaldehyde)) ################################################### ### chunk number 21: lm1a ################################################### coef(summary(lm1a <- lm(optden ~ 0 + carb, Formaldehyde))) ################################################### ### chunk number 22: lm1lm1acomp ################################################### anova(lm1a,lm1) ################################################### ### chunk number 23: lm1bshow eval=FALSE ################################################### ## coef(summary(lm1b <- lm(optden ~ 1 + carb + I(carb^2), Formaldehyde))) ################################################### ### chunk number 24: lm1b ################################################### printCoefmat(coef(summary(lm1b <- lm(optden ~ 1 + carb + I(carb^2), Formaldehyde)))) ################################################### ### chunk number 25: lm1cshow eval=FALSE ################################################### ## coef(summary(lm1c <- lm(optden ~ poly(carb, 2), Formaldehyde))) ################################################### ### chunk number 26: lm1c ################################################### printCoefmat(coef(summary(lm1c <- lm(optden ~ poly(carb, 2), Formaldehyde)))) ################################################### ### chunk number 27: treesplot ################################################### print(qplot(Girth,Volume,data=trees,xlab="Girth of tree (inches)", ylab=expression("Volume of usable timber (ft"^3*")")) + geom_smooth(method="lm",se=FALSE), TRUE, vp=viewport(0.25,0.5,0.5,1.0)) print(qplot(Girth,Volume,data=trees,log="xy",xlab="Girth of tree (inches)", ylab=expression("Volume of usable timber (ft"^3*")")) + geom_smooth(method="lm",se=FALSE), FALSE, vp=viewport(0.75,0.5,0.5,1.0)) ################################################### ### chunk number 28: lm2show eval=FALSE ################################################### ## coef(summary(lm2 <- lm(log(Volume) ~ log(Girth), trees))) ################################################### ### chunk number 29: lm2 ################################################### printCoefmat(coef(summary(lm2 <- lm(log(Volume) ~ log(Girth), trees)))) ################################################### ### chunk number 30: lm2ashow eval=FALSE ################################################### ## coef(summary(lm2a <- lm(log(Volume) ~ log(Girth) + log(Height), trees))) ################################################### ### chunk number 31: lm2a ################################################### printCoefmat(coef(summary(lm2a <- lm(log(Volume) ~ log(Girth) + log(Height), trees)))) ################################################### ### chunk number 32: lm2aconf ################################################### confint(lm2a) ################################################### ### chunk number 33: lm2c ################################################### lm2c <- lm(log(Volume) ~ 1 + offset(2*log(Girth) + log(Height)), trees) ################################################### ### chunk number 34: anovalm2 ################################################### anova(lm2c,lm2a) ################################################### ### chunk number 35: spraysplot ################################################### print(qplot(reorder(spray,count), count, data=InsectSprays, geom="boxplot", xlab="Spray", ylab="Insect count") + coord_flip(), TRUE, vp=viewport(0.5,0.75,1,0.5)) print(qplot(reorder(spray,count), sqrt(count), data=InsectSprays, geom="boxplot", xlab="Spray", ylab=expression(sqrt("count"))) + coord_flip(), FALSE, vp=viewport(0.5,0.25,1,0.5)) ################################################### ### chunk number 36: av1 ################################################### summary(av1 <- aov(sqrt(count) ~ spray, InsectSprays)) ################################################### ### chunk number 37: av1eff ################################################### model.tables(av1) ################################################### ### chunk number 38: av1eff2 ################################################### model.tables(av1, type="means") ################################################### ### chunk number 39: strOrchard ################################################### str(OrchardSprays) ################################################### ### chunk number 40: av2 ################################################### summary(av2 <- aov(decrease ~ factor(rowpos) + factor(colpos) + treatment, OrchardSprays)) ################################################### ### chunk number 41: breaksplot ################################################### print(qplot(tension, breaks, data=warpbreaks, geom="boxplot", xlab="Tension setting", ylab="Breaks per loom") + coord_flip() + facet_grid(wool~.), TRUE, vp=viewport(0.5,0.75,1,0.5)) print(qplot(tension, breaks, data=warpbreaks, geom="boxplot", xlab="Tension setting", ylab="Breaks per loom") + scale_y_recip() + coord_flip() + facet_grid(wool~.), FALSE, vp=viewport(0.5,0.25,1,0.5)) ################################################### ### chunk number 42: xtabsbreaks ################################################### xtabs(~ wool + tension, warpbreaks) ################################################### ### chunk number 43: av3 ################################################### summary(av3 <- aov(breaks ~ wool * tension, warpbreaks)) ################################################### ### chunk number 44: av3a ################################################### summary(av3a <- aov(1/breaks ~ wool * tension, warpbreaks)) ################################################### ### chunk number 45: av3b ################################################### summary(av3b <- aov(1/breaks ~ tension + wool, warpbreaks)) ################################################### ### chunk number 46: av3c ################################################### summary(av3c <- aov(1/breaks ~ tension, warpbreaks)) ################################################### ### chunk number 47: breaksplot2 ################################################### print(qplot(tension, breaks, data=warpbreaks, geom="boxplot", xlab="Tension setting", ylab="Breaks per loom") + scale_y_recip() + coord_flip()) ################################################### ### chunk number 48: orderedtension ################################################### str(warpbreaks <- within(warpbreaks, tension <- ordered(tension))) ################################################### ### chunk number 49: av3d ################################################### summary(av3d <- aov(1/breaks ~ tension, warpbreaks)) ################################################### ### chunk number 50: av3dcoefshow eval=FALSE ################################################### ## coef(summary.lm(av3d)) ################################################### ### chunk number 51: av3dcoef ################################################### printCoefmat(coef(summary.lm(av3d))) ################################################### ### chunk number 52: classlm2 ################################################### class(lm2) ################################################### ### chunk number 53: methodslm ################################################### methods(class="lm") ################################################### ### chunk number 54: classaov ################################################### class(av3) ################################################### ### chunk number 55: methodsaov ################################################### methods(class="aov")