For the purposes of this question, assume we have 10-dimensional data - that is, ignore the Overall column.
A)
Explain why we need to scale this data set before performing PCA.
We need to scale this data set before performing PCA because PCA maximizes the variance, and the decathlon use totally different units, unscaled data lets high variance events dominate so z scaling puts PCA on the correlation.
B)
Use svd() to find the first 2 principal component scores and their loadings. Full credit will only be granted if you use the svd() ingredients u, d, and v. What percent of the overall variability do the first two PCs explain?
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 4.0.0 ✔ tibble 3.2.1
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.0.4
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
PC1 explains 30.3%. PC2 explains 20.7%. So, it explains about 51% of the overall variability.
C)
Find and print the loadings. Based on the loadings alone, if the first two PCs are plotted in a 2D plane as shown below, which of the four quadrants will the medalists be in? Explain your reasoning.
Quadrant I will be the medalist be in because PC1 is positive for throws so medalists get high PC1. PC2 favors speed over endurance. Medalists are stronger on speed, so they get high PC2.
Positive PC1 + Positive PC2 = Quadrant I
D)
Add the PCs to the decathlon data set and create a scatterplot of these PCs, with the points labeled by the athletes’ names. Color-code the points on whether or not the athlete was a medalist. Use the ggrepel package for better labeling. Verify that your intuition from C) is correct.
library(ggplot2)library(ggrepel)X <-scale(data.matrix(decathlon[, -(1:4)]), center =TRUE, scale =TRUE)s <-svd(X)scores <- s$u %*%diag(s$d)decathlon$PC1 <- scores[, 1]decathlon$PC2 <- scores[, 2]decathlon$Medalist <-ifelse(decathlon$Medal =="None", "No Medal", "Medalist")labs_medal <- decathlon[decathlon$Medalist =="Medalist", ]ggplot(decathlon, aes(PC1, PC2, color = Medalist)) +geom_point(size =3) + ggrepel::geom_text_repel(data = labs_medal, aes(label = Athlete), show.legend =FALSE) +scale_color_manual(values =c("Medalist"="#F6A", "No Medal"="#3F51B5")) +labs(x ="PC1", y ="PC2", color ="Group") +theme_minimal(base_size =12)
E)
Canadian Damian Warner won the gold medal in the decathlon in the 2020 Tokyo games. He began the 2024 decathlon but bowed out after three straight missed pole vault attempts.
Would this have won a medal if it had happened in 2024? To answer this, we will compute his PCs with respect to the 2024 athletes and add it to the plot to see where his 2020 gold-medal performance compares to the 2024 athletes. To do this:
Find the mean vector from the 2024 athletes. Call it mean_vec_24.
Find the standard deviation vector from the 2024 athletes. Call it sd_vec_24.
Standardize Warner’s 2020 results with respect to the 2024 athletes: (warner-mean_vec_24)/sd_vec_24
Find Warner’s PC coordinates using the 2024 loadings.
Do you think his 2020 performance would have won a medal if it had happened in 2024?
I don’t think his 2020 performance would have won a medal if it had happened in 2024 because his 2020 point is below the medalist and is close to the non-medal group.
Question 2
Below is a screenshot of a conversation between me and chatbot Claude:
After looking at the graphs, I grew skeptical. So I said:
Behold, Claude’s three data sets which I’ve called claudeA, claudeB, and claudeC:
Each data set has an X and a Y column which represent 2-dimensional variables that we need to rotate.
A)
Scale each data set and plot them side-by-side using the patchwork package. Make sure the aspect ratio of each graph is 1 (i.e., make the height and width of each graph equal). At this point, explain why you think I was skeptical. Specifically, do you think the percent variability explained by the first PC of each data set appears to exceed or fall short of the variability I asked it to?
Claude A (55%) is higher than 55% Claude B (75%) is higher than 75% Claude C (90%) is around 90% You were skeptical because A and B looks linear for the targets.
B)
Use SVD to find the first PC for each data set, and find the actual percent of total variability explained by each PC using aggregation methods.