Home‎ > ‎Schedule‎ > ‎

Plotting commands for homework 5

####
# using "unclass" to assign multiple colors
# in plotting
#
# We reuse Hinton's data on a teacher's ratings
# of how well some girls and boys paid attention in class

hinton.attention = data.frame(child = c("susan", "linda", "john", "mary", "peter", "ian", "trevor", "andrew", "helen", "christine"), rating = c(67, 55, 26, 70, 36, 57, 32, 65, 59, 24))

# adding in gender as a factor
hinton.attention$gender = as.factor(c("g", "g", "b", "g", "b", "b", "b", "b", "g", "g"))

# plotting the teacher's ratings in pink and blue
plot(hinton.attention$rating, col = c("lightblue", "pink")[unclass(hinton.attention$gender)])

####
# using boxplots to inspect principal components
# coming out of principal component analysis
#
# we again use the PCA analysis of affixes in different texts
# that we have used before
library(languageR)
affixes.pr = prcomp(affixProductivity[,1:(ncol(affixProductivity)-3)])

# where does the first principal component tend to put books
# from different registers?
boxplot(affixes.pr$x[,1] ~ affixProductivity$Registers)

####
# does the first principal component capture something
# about the degree to which 'ly' is used productively?
plot(affixProductivity$ly, affixes.pr$x[,1], type = "p",
     xlab = "productivity for '-ly'", ylab = "value on PC1")
# adding a smoother to the impressively straight line
lines(lowess(affixProductivity$ly, affixes.pr$x[,1]))

Comments