/
principal-components.Rmd
86 lines (73 loc) · 3.18 KB
/
principal-components.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
title: "Glaucoma staging study"
date: "`r Sys.Date()`"
---
```{r knitr-init, echo=F}
library(knitr)
## Global options
options(digits = 4)
opts_chunk$set(echo=F, cache=T, prompt=F, tidy=T, comment=NA, message=F, warning=F, dev="png", dev.args=list(type="cairo"), dpi=300)
```
```{r data-loading, results='hide'}
source("data-loading.R")
```
```{r packages, results='hide'}
.packages <- c("FactoMineR", "factoextra", "gridExtra")
.installed <- .packages %in% installed.packages()
if (length(.packages[!.installed])>0) install.packages(.packages[!.installed])
lapply(.packages, require, character.only=T)
```
# Principal components analysis
```{r principal-components}
# Principal components healthy and glaucoma eyes
result.pca <- PCA(data[, c(varRims)], scale.unit = F, graph=F)
# eigenvalues <- get_eigenvalue(result.pca)
# Explained variability by principal components
fviz_eig(result.pca,
main = "Explained variability by principal components",
ylab = "% of the total variability",
xlab = "Principal components (dimensions)") +
theme(plot.title = element_text(hjust = 0.5))
ggsave("img/explained-variability-principal-components.pdf", width = 7, height = 5)
# Correlation of variables with first principal component
fviz_cos2(result.pca,
choice = "var",
axes=1,
title="Correlation of the variables with the first principal component",
) +
ylab("Coef. of determination r²") +
theme(plot.title = element_text(hjust = 0.5))
ggsave("img/correlation-pca.pdf", width = 7, height = 5)
# Contribution of variables to first principal component
p1 <- fviz_contrib(result.pca, choice="var", axes=1, top = 10) +
theme(plot.title = element_text(hjust = 0.5))
ggsave("img/contribution-variables-pca-dim1.pdf", width = 7, height = 5)
# Contribution of variables to second principal component
p2 <- fviz_contrib(result.pca, choice="var", axes=2, top = 10) +
theme(plot.title = element_text(hjust = 0.5))
ggsave("img/contribution-variables-pca-dim2.pdf", width = 7, height = 5)
# Contribution of variables to third principal component
p3 <- fviz_contrib(result.pca, choice="var", axes=3, top = 10) +
theme(plot.title = element_text(hjust = 0.5))
ggsave("img/contribution-variables-pca-dim3.pdf", width = 7, height = 5)
grid.arrange(p1, p2, p3, nrow = 1)
```
The principal components analysis shows that the first principal component explains almost 60% of the total variability, while the second one only 11%.
The variables most correlated with the first principal component are the global sector and the TI sector of BMO and RNFL rims.
```{r map-eyes-principal-components}
palette <- c("#00FF00", "#FF0000")
# Plot eyes on the two first principal components
fviz_pca_ind(
result.pca,
geom = c("point"),
axes = c(1, 2),
habillage = data$Glaucoma,
palette = palette,
ddEllipses = T,
ellipse.type = "t",
title = "Map of healthy and glaucoma eyes on the first two principal components"
) +
theme(legend.position = "top", plot.title = element_text(hjust = 0.5))
ggsave("img/pca-map.pdf", width = 7, height = 5)
```
The map shows a clear separation, with a small overlapping area, between healthy and glaucoma eyes along the firs principal component, while there is no separation at all along the second one.