--- title: "diamonds" author: "Chris Parrish" date: "January 19, 2016" output: pdf_document --- diamonds references: - Cannon, et al., Stat2, chapter 05, example 5.2 Import the data. ```{r} data <- read.csv("Diamonds2.csv", header=TRUE) head(data, 4) dim(data) ``` Scatterplot matrix. ```{r} pairs(~ TotalPrice + Carat + Color + Clarity + Depth + PricePerCt, data=data, col="darkred") ``` Group statistics: Carat ~ Color. ```{r} n <- with(data, tapply(Carat, Color, length)) mean <- with(data, round(tapply(Carat, Color, mean), 3)) sd <- with(data, round(tapply(Carat, Color, sd), 3)) diamond.statistics <- cbind(n, mean, sd) diamond.statistics grand.mean <- cbind(n = length(data\$Carat), mean = mean(data\$Carat), sd = sd(data\$Carat)) rownames(grand.mean) <- c("Total") grand.mean <- round(grand.mean, 3) grand.mean ``` First model: ANOVA with `aov` ```{r} diamond.aov1 <- aov(Carat ~ Color, data=data) diamond.aov1 options(show.signif.stars=FALSE) summary(diamond.aov1) ``` Residuals. ```{r} qqnorm(resid(diamond.aov1), col="cadetblue") qqline(resid(diamond.aov1), col="orange") library(lattice) dotplot(Carat ~ Color, data=data, jitter=TRUE) stripchart(Carat ~ Color, data=data, pch=20, col="darkred", method="stack") ``` Second model: ANOVA with `aov` and \$\log\$ transformation ```{r} diamond.aov2 <- aov(log(Carat) ~ Color, data=data) diamond.aov2 summary(diamond.aov2) ``` Residuals. ```{r} qqnorm(resid(diamond.aov2), col="palevioletred") qqline(resid(diamond.aov2), col="orange") plot(predict(diamond.aov2), resid(diamond.aov2), pch=20, col="darkred") std.dev <- diamond.statistics[ , 3] std.dev ratio <- max(std.dev) / min(std.dev) ratio ```