Principal Component Analysis Olympic Heptathlon Ch. 13
Principal components The Principal components method summarizes data by finding the major correlations in linear combinations of the obervations. –Little information lost in process, usually –Major application: Correlated variables are transformed into uncorrelated variables
Olympic Heptathlon Data 7 events: Hurdles, Highjump, Shot, run200m, longjump, javelin, run800m –The scores for these events are all on different scales –A relatively high number could be good or bad depending on the event 25 Olympic competitors
R Commands Reorder the scores so that a high number means a good score –heptathlon$hurdles <- max(heptathlon$hurdles) – heptathlon$hurdles Hurdles, Run200m, Run800m requires reordering
Basic plot to look at data R Commands –score <- which(colnames(heptathlon) == “score”) “which” searches the column names of the heptathlon data.frame for “score” and stores it in a variable “score” above –plot(heptathlon[, -score]) Scatterplot matrix, excluding the score column
a1 <- heptathlon_pca$rotation[, 1] a1 This shows the coefficients for the first principal component y1 Y1 is the linear combination of observations that maximizes the sample variance as a portion of the overall sample variance. Y2 is the linear combination that maximizes out of the remaining portion of sample variance, with the added constraint of being uncorrelated with Y1
Interpretation 200m and long jump is the most important factor Javelin result is less important
Data Analysis using the first principal component center <- heptathlon_pca$center –This is the center or mean of the variables, it can also be a flag in the prcomp() function that sets the center at 0. scale <- heptathlon_pca$scale –This is also a flag in the prcomp() function that can scale the variables to fit between 0 and 1, as it is, its just storing the current scale. –hm <- as.matrix(heptathlon[, -score]) This coerces the data.frame heptathlon into a matrix and excludes score –drop(scale(hm, center = center, scale = scale) %*% heptathlon_pca$rotation[, 1]) rescales the raw heptathlon data to the Principal component scale performs matrix multiplication on the coefficients of the linear combination for the first principal component (Y1) Drop() prints the resulting matrix
An easier way predict(heptathlon_pca)[, 1] –Accomplishes the same thing as the previous set of commands
Principal Components Proportion of Sample Variances The first component contributes the vast majority of total sample variance –Just looking at the first two (uncorrelated!) principal components will account for most of the overall sample variance (~81%) plot(heptathlon_pca)
First two Principal Components biplot(heptathlon_pca,col=c("gray","black"))
Interpretation The Olympians with the highest score seem to be at the bottom left of the graph, while The javelin event seems to give the scores a more fine variation and award the competitors a slight edge.
How well does it fit the Scoring? The correlation between Y1 and the scoring looks very strong. cor(heptathlon$score, heptathlon_pca$x[,1]) – -0.9910978
Homework! (Ch.13) Use the “meteo” data on page 225 and create scatterplots to check for correlation (don’t recode/reorder anything, and remember not to include columns in the analysis that don’t belong! –Is there correlation? Don’t have R calculate the numerical values unless you really want to Run PCA using the long way or the shorter “predict” command (remember not to include the unneccesary column!) Create a biplot, but use colors other than gray and black! Create a scatterplot like on page 224 of the 1 st principle component and the yield –What is the numerical value of the correlation? Don’t forget to copy and paste your commands into word and print it out for me (and include the scatterplot)!