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.
The reason that the data must be scaled is because the columns in the data set have different ranges. A column with a higher range is going to dominate the PCA because of the larger variance.
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?
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.
Looking at the PC1 and PC2 columns of the decathlon data set the medalists have a negative PC1 and a positive PC2. This means that the quadrant that they will be in is the II quadrant.
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(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Yes the medalists are in the II quadrant after looking at the plot.
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.
Add his point to the scatterplot.
Do you think his 2020 performance would have won a medal if it had happened in 2024?
warner_df <-data.frame(Name ="Damian Warner (2020)",PC1 = warner_PC[1],PC2 = warner_PC[2],Medalist ="Warner 2020")ggplot(decathlon, aes(x = PC1, y = PC2, label = Athlete, color = Medalist)) +geom_point(size =3) +geom_text_repel() +geom_point(data = warner_df,aes(x = PC1, y = PC2, color = Medalist),size =4,shape =17,inherit.aes =FALSE ) +geom_text_repel(data = warner_df,aes(x = PC1, y = PC2, label = Name),fontface ="bold",inherit.aes =FALSE ) +scale_color_manual(values =c("Medalist"="gold","Non-medalist"="grey","Warner 2020"="red" )) +theme_minimal() +labs(title ="PC1 vs PC2 with Warner",x ="PC1",y ="PC2",color ="Legend" )
No, Warner wouldn’t have gotten gold in 2024 based off his 2020 performance. The reason for this is after looking at the plot his performance is not close to the plots of the medalists in 2024.
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?
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ lubridate 1.9.4 ✔ tibble 3.3.0
✔ purrr 1.1.0 ✔ tidyr 1.3.1
✔ readr 2.1.5
── 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
Looking at the plot of Claude A it seems to be very linear. The plot is showing a variability far better than 55%. Same thing with Claude B. The plot is very linear and most likely explains more than 75% variability. Looking at Claude C the plot is extremely linear. Almost 100% variability. The goal was 90% but this plot seems to be doing better than 90%.
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.
After computing the variability for the three data sets it can be seen that the variability is all above 90%. This is way above what the variability was supposed to be.