2Principal componentsThe Principal components method summarizes data by finding the major correlations in linear combinations of the obervations.Little information lost in process, usuallyMajor application: Correlated variables are transformed into uncorrelated variables
3Olympic Heptathlon Data 7 events: Hurdles, Highjump, Shot, run200m, longjump, javelin, run800mThe scores for these events are all on different scalesA relatively high number could be good or bad depending on the event25 Olympic competitors
4R Commands Reorder the scores so that a high number means a good score heptathlon$hurdles <- max(heptathlon$hurdles) – heptathlon$hurdlesHurdles, Run200m, Run800m requires reordering
5Basic plot to look at data R Commandsscore <- which(colnames(heptathlon) == “score”)“which” searches the column names of the heptathlon data.frame for “score” and stores it in a variable “score” aboveplot(heptathlon[, -score])Scatterplot matrix, excluding the score column
7Interpretation The data looks correlated except for the javelin event. The book speculates the javelin is a ‘technical’ event, whereas the others are all ‘power’ events
8To get numerical correlation values: round(cor(heptathlon[, -score]), 2)The cor(data.frame) function finds the actual correlation valuesThe cor(data.frame) function is in agreement with this interpretationhurdles highjump shot run200m longjump javelin run800mhurdleshighjumpshotrun200mlongjumpjavelinrun800m
9Running a Principal Component analysis heptathlon_pca <- prcomp(heptathlon[, -score], scale = TRUE)print(heptathlon_pca)Standard deviations:Rotation:PC PC PC PC PC PC PC7hurdleshighjumpshotrun200mlongjumpjavelinrun800m
10a1 <- heptathlon_pca$rotation[, 1] This shows the coefficients for the first principal component y1Y1 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
12Interpretation 200m and long jump is the most important factor Javelin result is less important
13Data Analysis using the first principal component center <- heptathlon_pca$centerThis 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$scaleThis 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 scoredrop(scale(hm, center = center, scale = scale) %*% heptathlon_pca$rotation[, 1])rescales the raw heptathlon data to the Principal component scaleperforms matrix multiplication on the coefficients of the linear combination for the first principal component (Y1)Drop() prints the resulting matrix
15An easier way predict(heptathlon_pca)[, 1] Accomplishes the same thing as the previous set of commands
16Principal Components Proportion of Sample Variances The first component contributes the vast majority of total sample varianceJust looking at the first two (uncorrelated!) principal components will account for most of the overall sample variance (~81%)plot(heptathlon_pca)
17First two Principal Components biplot(heptathlon_pca,col=c("gray","black"))
18InterpretationThe Olympians with the highest score seem to be at the bottom left of the graph, whileThe javelin event seems to give the scores a more fine variation and award the competitors a slight edge.
19How well does it fit the Scoring? The correlation between Y1 and the scoring looks very strong.cor(heptathlon$score, heptathlon_pca$x[,1])
20Homework! (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 toRun 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 1st principle component and the yieldWhat 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)!