Docsity

Principal Component Analysis, Summaries of Statistics

Toggle sidebar
bg1
Principal Component Analysis
STAT 147 - Intro to Multivariate Analysis
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")
# install.packages("ggfortify")
# install.packages("gridExtra")
# install.packages("carData")
# install.packages("car")
# install.packages("factoextra")
# install.packages("corrplot")
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)
## X100m Long.jump Shot.put High.jump X400m X110m.hurdle Discus
## SEBRLE 11.04 7.58 14.83 2.07 49.81 14.69 43.75
## CLAY 10.76 7.40 14.26 1.86 49.37 14.05 50.72
## BERNARD 11.02 7.23 14.25 1.92 48.93 14.99 40.87
## YURKOV 11.34 7.09 15.19 2.10 50.42 15.31 46.26
## ZSIVOCZKY 11.13 7.30 13.48 2.01 48.62 14.17 45.67
## McMULLEN 10.83 7.31 13.76 2.13 49.91 14.38 44.41
## Pole.vault Javeline X1500m
## SEBRLE 5.02 63.19 291.7
1
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Principal Component Analysis and more Summaries Statistics in PDF only on Docsity!

Principal Component Analysis

STAT 147 - Intro to Multivariate Analysis

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")

install.packages("ggfortify")

install.packages("gridExtra")

install.packages("carData")

install.packages("car")

install.packages("factoextra")

install.packages("corrplot")_

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)

X100m Long.jump Shot.put High.jump X400m X110m.hurdle Discus

SEBRLE 11.04 7.58 14.83 2.07 49.81 14.69 43.

CLAY 10.76 7.40 14.26 1.86 49.37 14.05 50.

BERNARD 11.02 7.23 14.25 1.92 48.93 14.99 40.

YURKOV 11.34 7.09 15.19 2.10 50.42 15.31 46.

ZSIVOCZKY 11.13 7.30 13.48 2.01 48.62 14.17 45.

McMULLEN 10.83 7.31 13.76 2.13 49.91 14.38 44.

Pole.vault Javeline X1500m

SEBRLE 5.02 63.19 291.

## CLAY 4.92 60.15 301.

## BERNARD 5.32 62.77 280.

## YURKOV 4.72 63.44 276.

## ZSIVOCZKY 4.42 55.37 268.

McMULLEN 4.42 56.37 285.

Exploratory Data Analysis

In order to provide the model, a summary of data is required. The variables (sport disciplines) descriptions are as follows:

  1. X100m - 100 metres results expressed in seconds
  2. Long.jump - long jump results expressed in metres
  3. Shot.put - shot put results expressed in metres
  4. High.jump - high jump results expressed in metres
  5. X400m - 400 metres results expressed in seconds
  6. X110m.hurdle - 110 metres hurdle race results expressed in seconds
  7. Discus - discus throw results expressed in metres
  8. Pole.vault - pole vault results expressed in metres
  9. Javeline - javeline throw results expressed in metres
  10. X1500m - 1500 metres results expressed in seconds

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)

X100m Long.jump Shot.put High.jump

Min. :10.44 Min. :6.800 Min. :12.68 Min. :1.

1st Qu.:10.84 1st Qu.:7.165 1st Qu.:14.17 1st Qu.:1.

Median :10.97 Median :7.310 Median :14.65 Median :2.

Mean :11.00 Mean :7.350 Mean :14.62 Mean :2.

3rd Qu.:11.23 3rd Qu.:7.525 3rd Qu.:15.14 3rd Qu.:2.

Max. :11.64 Max. :7.960 Max. :16.36 Max. :2.

X400m X110m.hurdle Discus Pole.vault

Min. :46.81 Min. :13.97 Min. :37.92 Min. :4.

1st Qu.:48.95 1st Qu.:14.17 1st Qu.:43.74 1st Qu.:4.

Median :49.40 Median :14.37 Median :44.75 Median :4.

Mean :49.43 Mean :14.53 Mean :45.16 Mean :4.

3rd Qu.:50.02 3rd Qu.:14.94 3rd Qu.:46.93 3rd Qu.:5.

Max. :51.16 Max. :15.67 Max. :51.65 Max. :5.

Javeline X1500m

Min. :52.33 Min. :262.

1st Qu.:55.40 1st Qu.:268.

Median :57.44 Median :278.

Mean :59.11 Mean :277.

3rd Qu.:62.98 3rd Qu.:283.

Max. :70.52 Max. :301.

  • rescaling the variance to 1 unit;
  • data standarization needed due to the fact that variables are measured in different scales.

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)

Standard deviations (1, .., p=10):

[1] 2.0308159 1.3559244 1.1131668 0.9052294 0.8375875 0.6502944 0.

[8] 0.5238988 0.3939758 0.

Rotation (n x k) = (10 x 10):

PC1 PC2 PC3 PC4 PC

X100m -0.418859080 -0.13230683 -0.27089959 0.03708806 -0.

Long.jump 0.391064807 0.20713320 0.17117519 -0.12746997 0.

Shot.put 0.361388111 0.06298590 -0.46497777 0.14191803 -0.

High.jump 0.300413236 -0.34309742 -0.29652805 0.15968342 0.

X400m -0.345478567 0.21400770 -0.25470839 0.47592968 0.

X110m.hurdle -0.376265119 -0.01824645 -0.40325254 -0.01866477 0.

Discus 0.365965721 0.03662510 -0.15857927 0.43636361 -0.

Pole.vault -0.106985591 0.59549862 -0.08449563 -0.37447391 -0.

Javeline 0.210864329 0.28475723 -0.54270782 -0.36646463 0.

X1500m 0.002106782 0.57855748 0.19715884 0.49491281 0.

PC6 PC7 PC8 PC9 PC

X100m -0.054398099 -0.16604375 -0.19988005 -0.76924639 0.

Long.jump 0.051865558 -0.28056361 -0.75850657 -0.13094589 0.

Shot.put 0.368739186 -0.01797323 0.04649571 0.12129309 0.

High.jump 0.437716883 0.05118848 0.16111045 -0.28463225 -0.

X400m 0.075796432 0.52012255 -0.44579641 0.20854176 -0.

X110m.hurdle -0.004048005 -0.67276768 -0.01592804 0.41058421 -0.

Discus -0.305315353 -0.25946615 -0.07550934 0.03391600 -0.

Pole.vault 0.503563524 -0.01889413 0.06282691 -0.06540692 -0.

Javeline -0.556821016 0.24281145 0.10086127 -0.10268134 -0.

X1500m -0.064663250 -0.20245828 0.37119711 -0.25950868 0.

summary (res.pca)

Importance of components:

PC1 PC2 PC3 PC4 PC5 PC6 PC

Standard deviation 2.0308 1.3559 1.1132 0.90523 0.83759 0.65029 0.

Proportion of Variance 0.4124 0.1839 0.1239 0.08194 0.07016 0.04229 0.

Cumulative Proportion 0.4124 0.5963 0.7202 0.80213 0.87229 0.91458 0.

PC8 PC9 PC

Standard deviation 0.52390 0.39398 0.

Proportion of Variance 0.02745 0.01552 0.

Cumulative Proportion 0.97228 0.98780 1.

eig.val<- get_eigenvalue (res.pca) eig.val

eigenvalue variance.percent cumulative.variance.percent

Dim.1 4.1242133 41.242133 41.

Dim.2 1.8385309 18.385309 59.

Dim.3 1.2391403 12.391403 72.

Dim.4 0.8194402 8.194402 80.

Dim.5 0.7015528 7.015528 87.

Dim.6 0.4228828 4.228828 91.

Dim.7 0.3025817 3.025817 94.

Dim.8 0.2744700 2.744700 97.

Dim.9 0.1552169 1.552169 98.

Dim.10 0.1219710 1.219710 100.

fviz_eig (res.pca, col.var="blue")

0

10

20

30

40

1 2 3 4 5 6 7 8 9 10

Dimensions

Percentage of explained variances

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

  1. As far as scatter plot is concerned, first eigenvalue explains 41.24% of the variation, second is 18.385%, and the third one is 12.39%. Therefore, a total of 72.018% of the variation is explained by the first three eigenvalues together, which is a proper indicator for further analysis.

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 − Quality of representation

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

  • “ gold ”, high co2 values - “ darkorange ”. Positively correlated variables are grouped together, whereas negatively correlated variables are positioned on opposite sides of the plot origin. The distance between variables and the origin measures the quality of the variables on the factor map. Variables that are away from the origin are well represented on the factor map.

fviz_pca_var (res.pca, col.var = "cos2", # Color by the quality of representation gradient.cols = c ("darkorchid4", "gold", "darkorange"), repel = TRUE )