





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Principal Component Analysis (PCA) is a statistical tool that reduces dimensionality. PCA extracts relevant information from a multivariate data table and expresses it as a small set of new variables known as principal components. The purpose of PCA is to discover directions that can be visually represented with little loss of information.
Data and Data Processing
We will be using the dataset decathlon2 from the factoextra package. The data describes athletes’ performance during two sporting events (Desctar and OlympicG). It contains 27 individuals (athletes) de- scribed by 13 variables (sport disciplines). For further analysis, we will subset active individuals (rows 1:23) and active variables (columns 1:10) from decathlon2 dataset, thus we will create new dataset called decathlon2.active to conduct the principal component analysis. the decathlon2.active dataset consists of 23 observations and 10 variables.
_# install.packages("ggplot2")
library (ggplot2) library (ggfortify) library (gridExtra) library (carData) library (car) library (factoextra) library (corrplot)
data (decathlon2) decathlon2.active <- decathlon2[1 : 23, 1 : 10] head (decathlon2.active)
Exploratory Data Analysis
In order to provide the model, a summary of data is required. The variables (sport disciplines) descriptions are as follows:
The summary statistics and histograms below show the distribution of observations in all numeric variables. Horizontal axis represents the values of observations, while the vertical axis “count” shows the amount of certain observations for each value.
summary (decathlon2.active)
Additionally, the eigenvalues are extracted by get_eigenvalue() function. Eigenvalues measure the amount of variation held by each principal component (PC). They are evaluated to determine the number of principal components to be considered.
res.pca <- prcomp (decathlon2.active, scale = TRUE) print (res.pca)
summary (res.pca)
eig.val<- get_eigenvalue (res.pca) eig.val
fviz_eig (res.pca, col.var="blue")
0
10
20
30
40
1 2 3 4 5 6 7 8 9 10
Scree plot
On the basis of importance of components, is it visible that first three PCs have the highest values for proportion of variance. This statement is also proved by eigenvalues measure. They are large for the first PCs and small for the subsequent PCs, which means that the first PCs corresponds to the directions with the maximum amount of variation in the data set. The sum of all the eigenvalues gives a total variance of
Dim.1Dim.2Dim.3Dim.4Dim.5Dim.6Dim.7Dim.8Dim.9Dim.
X100m
Long.jump
Shot.put
High.jump
X400m
X110m.hurdle
Discus
Pole.vault
Javeline
X1500m
fviz_cos2 (res.pca, choice = "var", axes = 1 : 2)
X100m Long.jumpPole.vault X1500mHigh.jump X110m.hurdle
X400m Discus Shot.put Javeline
Cos2 of variables to Dim−1−
Additionally, the quality of representation of variables can be draw on the factor map, where cos2 values differ by gradient colors. Variables with low cos2 values will be colored “ darkorchid4 ”, medium cos2 values
fviz_pca_var (res.pca, col.var = "cos2", # Color by the quality of representation gradient.cols = c ("darkorchid4", "gold", "darkorange"), repel = TRUE )