-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_pca
More file actions
43 lines (36 loc) · 1.02 KB
/
Copy path3_pca
File metadata and controls
43 lines (36 loc) · 1.02 KB
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
# Perform scaled PCA: pr.out
pr.out <- prcomp(pokemon, scale = T)
# Inspect model output
summary(pr.out)
#
#
biplot(pr.out)
#
#
# Variability of each principal component: pr.var
pr.var <- pr.out$sdev ^ 2
# Variance explained by each principal component: pve
pve <- pr.var / sum(pr.var)
#
#
# Plot variance explained for each principal component
plot(pve, xlab = "Principal Component",
ylab = "Proportion of Variance Explained",
ylim = c(0, 1), type = "b")
# Plot cumulative proportion of variance explained
plot(cumsum(pve), xlab = "Principal Component",
ylab = "Cumulative Proportion of Variance Explained",
ylim = c(0, 1), type = "b")
#
#
# Mean of each variable
colMeans(pokemon)
# Standard deviation of each variable
apply(pokemon, 2, sd)
# PCA model with scaling: pr.with.scaling
pr.with.scaling <- prcomp(pokemon, scale = T)
# PCA model without scaling: pr.without.scaling
pr.without.scaling <- prcomp(pokemon, scale= F)
# Create biplots of both for comparison
biplot(pr.with.scaling)
biplot(pr.without.scaling)