Skip to content

Instantly share code, notes, and snippets.

@arthurwuhoo
Created June 9, 2016 15:26
Show Gist options
  • Save arthurwuhoo/202d4981e87b3b8c8f6499fc6fd348cc to your computer and use it in GitHub Desktop.
Save arthurwuhoo/202d4981e87b3b8c8f6499fc6fd348cc to your computer and use it in GitHub Desktop.
# =====================================================================================================================
# 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