--- title: "cancer" author: "Chris Parrish" date: "January 19, 2016" output: pdf_document --- cancer reference: - Cannon, et al., Stat2, chapter 05, example 5.8 Import the data. ```{r} data <- read.csv("CancerSurvival.CSV", header=TRUE) head(data, 3) dim(data) ``` View the data. ```{r fig.width=6, fig.height=4.5} old.par <- par(mar=c(4, 8, 4, 4)) plot(Survival ~ Organ, data=data, horizontal=TRUE, col=terrain.colors(6), las=1, ylab="Survival time", xlab="") par(old.par) ``` Group statistics. ```{r} n <- with(data, tapply(Survival, Organ, length)) mean <- with(data, round(tapply(Survival, Organ, mean), 3)) sd <- with(data, round(tapply(Survival, Organ, sd), 3)) cancer.statistics <- cbind(n, mean, sd) cancer.statistics grand.mean <- cbind(n = length(data\$Survival), mean = mean(data\$Survival), sd = sd(data\$Survival)) rownames(grand.mean) <- c("Total") grand.mean <- round(grand.mean, 3) grand.mean ``` First model: ANOVA with `aov` ```{r} cancer.aov1 <- aov(Survival ~ Organ, data=data) cancer.aov1 options(show.signif.stars=FALSE) summary(cancer.aov1) ``` Residuals. ```{r} plot(predict(cancer.aov1), resid(cancer.aov1), pch=20, col="darkred") qqnorm(resid(cancer.aov1), col="cadetblue") qqline(resid(cancer.aov1), col="orange") library(lattice) dotplot(Survival ~ Organ, data=data, jitter=TRUE) old.par <- par(mar=c(4, 6, 4, 3)) stripchart(Survival ~ Organ, data=data, pch=20, las=1, col="darkred", method="stack") par(old.par) std.dev <- cancer.statistics[ , 3] std.dev ratio <- max(std.dev) / min(std.dev) ratio ``` Second model: ANOVA with `aov` and \$\log\$ transformation ```{r} cancer.aov2 <- aov(log(Survival) ~ Organ, data=data) cancer.aov2 summary(cancer.aov2) cancer.aov2\$coefficients ``` Compare with `lm` `aov` is a wrapper for `lm`, but its results are displayed differently. ```{r} cancer.lm2 <- lm(log(Survival) ~ Organ, data=data) summary(cancer.lm2) ``` Residuals. ```{r} qqnorm(resid(cancer.aov2), col="palevioletred") qqline(resid(cancer.aov2), col="orange") plot(predict(cancer.aov2), resid(cancer.aov2), pch=20, col="darkred") ``` Group statistics. ```{r} n <- with(data, tapply(log(Survival), Organ, length)) mean <- with(data, round(tapply(log(Survival), Organ, mean), 3)) sd <- with(data, round(tapply(log(Survival), Organ, sd), 3)) cancer.statistics <- cbind(n, mean, sd) cancer.statistics grand.mean <- cbind(n = length(data\$Survival), mean = mean(log(data\$Survival)), sd = sd(log(data\$Survival))) rownames(grand.mean) <- c("Total") grand.mean <- round(grand.mean, 3) grand.mean std.dev <- cancer.statistics[ , 3] std.dev ratio <- max(std.dev) / min(std.dev) ratio ```