Created
June 9, 2016 15:26
-
-
Save arthurwuhoo/4d3bd7d55815404d32dc6587d6d8fef8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ===================================================================================================================== | |
# TRANSFORMATIONS | |
# ===================================================================================================================== | |
# Focus our attention on a subset of the baseball data. | |
# | |
baseball = select(baseball, Name, Atbatc:Walksc) | |
# Box plots. | |
# | |
par(mfrow = c(1, 6), mar = c(4, 3, 3, 1) + 0.1) | |
for (n in 2:7) { | |
boxplot(baseball[,n], xlab = colnames(baseball)[n], col = "lightgreen") | |
} | |
# Histograms. | |
# | |
par(mfrow = c(1, 6), mar = c(4, 3, 3, 1) + 0.1) | |
for (n in 2:7) { | |
hist(baseball[,n], main = colnames(baseball)[n], col = "lightblue") | |
} | |
atbatc.sqrt <- sqrt(baseball[,2]) | |
atbatc.log <- log10(baseball[,2]) | |
# | |
boxcox = BoxCoxTrans(baseball[,2]) | |
atbatc.boxcox <- predict(boxcox, baseball[,2]) | |
# Let's focus on one variable. | |
# | |
par(mfrow = c(1, 4), mar = c(4, 3, 3, 1) + 0.1) | |
hist(baseball[,2], col = "lightblue", main = "Atbatc") | |
hist(atbatc.sqrt, col = "lightblue", main = "sqrt()") | |
hist(atbatc.log, col = "lightblue", main = "log10()") | |
hist(atbatc.boxcox, col = "lightblue", main = "Box-Cox") | |
shapiro.test(baseball[,2]) | |
shapiro.test(atbatc.sqrt) | |
shapiro.test(atbatc.log) | |
shapiro.test(atbatc.boxcox) | |
qqnorm(atbatc.boxcox) | |
qqline(atbatc.boxcox) | |
qqnorm(baseball[,2]) | |
qqline(baseball[,2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment