Bulan x1 x2 x3 x4 x5
Januari 27.3 48.8 1010 81 4.6
Februari 28 72.8 1011 78 4.2
Maret 27.8 64.4 1010.8 81 3.8
April 27.6 66.6 1010.4 83 3.8
Mei 27.3 64.2 1009.4 87 3.5
Juni 26 33.9 1011.5 90 3.3
Juli 25.9 40.6 1010.9 90 3.3
Agustus 25.7 43 1011.5 91 3.5
September 26.4 60.9 1009.7 88 3.5
Oktober 27 62.4 1008.7 86 3.6
November 27 64.9 1008.4 85 3.6
Desember 26.8 45 1006.3 85 3.6
Algoritma
Flow chart
Fungsi R untuk analisis komponen utama :
Input Data
x1<-c(27.3,28,27.8,27.6,27.3,26,25.9,25.7,26.4,27,27,26.8)
x2<-c(48.8,72.8,64.4,66.6,64.2,33.9,40.6,43,60.9,62.4,64.9,45)
x3<-c(1010,1011,1010.8,1010.4,1009.4,1011.5,1010.9,1011.5,1009.7,1008.7,1008.4,1006.3)
x4<-c(81,78,81,83,87,90,90,91,88,86,85,85)
x5<-c(4.6,4.2,3.8,3.8,3.5,3.3,3.3,3.5,3.5,3.6,3.6,3.6)
data=[Link](x1,x2,x3,x4,x5)
summary(data)
x1 x2 x3 x4 x5
Min. :25.70 Min. :33.90 Min. :1006 Min. :78.00 Min. :3.300
1st Qu.:26.30 1st Qu.:44.50 1st Qu.:1009 1st Qu.:82.50 1st Qu.:3.500
Median :27.00 Median :61.65 Median :1010 Median :85.50 Median :3.600
Mean :26.90 Mean :55.62 Mean :1010 Mean :85.42 Mean :3.692
3rd Qu.:27.38 3rd Qu.:64.53 3rd Qu.:1011 3rd Qu.:88.50 3rd Qu.:3.800
Max. :28.00 Max. :72.80 Max. :1012 Max. :91.00 Max. :4.600
Mencari Matriks Korelasi
cor(data)
x1 x2 x3 x4 x5
x1 1.0000000 0.8068091 -0.1544019 -0.9264711 0.6626523
x2 0.8068091 1.0000000 -0.1310059 -0.6549232 0.3528668
x3 -0.1544019 -0.1310059 1.0000000 0.1055175 0.0300610
x4 -0.9264711 -0.6549232 0.1055175 1.0000000 -0.8291973
x5 0.6626523 0.3528668 0.0300610 -0.8291973 1.0000000
Mencari Matriks Varians-Kovarians
cov(data)
x1 x2 x3 x4 x5
x1 0.5781818 7.720909 -0.17818182 -2.8727273 0.18909091
x2 7.7209091 158.391136 -2.50227273 -33.6113636 1.66659091
x3 -0.1781818 -2.502273 2.30333333 0.6530303 0.01712121
x4 -2.8727273 -33.611364 0.65303030 16.6287879 -1.26893939
x5 0.1890909 1.666591 0.01712121 -1.2689394 0.14083333
Melakukan standarisasi karena data yang digunakan memiliki perbedaan yang cukup jauh
data[]=lapply(data,function (x) if ([Link](x)){scale(x,center=TRUE,scale=TRUE)}else x)
data[]
x1 x2 x3 x4 x5
1 0.5260509 -0.5422970 0.07687204 -1.0830895 2.4204300
2 1.4466400 1.3646815 0.73577522 -1.8187729 1.3545526
3 1.1836145 0.6972390 0.60399458 -1.0830895 0.2886751
4 0.9205891 0.8720454 0.34043331 -0.5926339 0.2886751
5 0.5260509 0.6813475 -0.31846987 0.3882774 -0.5107329
6 -1.1836145 -1.7262129 1.06522681 1.1239608 -1.0436716
7 -1.3151273 -1.1938480 0.66988490 1.1239608 -1.0436716
8 -1.5781527 -1.0031502 1.06522681 1.3691886 -0.5107329
9 -0.6575636 0.4191380 -0.12079892 0.6335052 -0.5107329
10 0.1315127 0.5383241 -0.77970210 0.1430496 -0.2442636
11 0.1315127 0.7369677 -0.97737305 -0.1021783 -0.2442636
12 -0.1315127 -0.8442353 -2.36106973 -0.1021783 -0.2442636
Mencari nilai eigen dan vector eigen
eigen(cov(data))
eigen() decomposition
$values
[1] 3.16028772 1.02956734 0.64755359 0.13089261 0.03169874
$vectors
[,1] [,2] [,3] [,4] [,5]
[1,] -0.54393436 -0.04549465 -0.1567095 0.50675582 0.6486187844
[2,] -0.44665602 -0.15371194 -0.6890895 -0.53253295 -0.1357766936
[3,] 0.08634079 0.93885697 -0.3244419 0.07635606 0.0002153806
[4,] 0.54474435 -0.07823418 -0.1733473 -0.39261231 0.7161978059
[5,] -0.44769707 0.29449936 0.6043889 -0.54738699 0.2189041307
# Menggunakan Cara Lain Untuk Mendapatkan eigen vector
pca=prcomp(data,center=TRUE,scale.=TRUE)
pca
Standard deviations (1, .., p=5):
[1] 1.7777198 1.0146760 0.8047071 0.3617908 0.1780414
Rotation (n x k) = (5 x 5):
PC1 PC2 PC3 PC4 PC5
x1 -0.54393436 0.04549465 -0.1567095 0.50675582 0.6486187844
x2 -0.44665602 0.15371194 -0.6890895 -0.53253295 -0.1357766936
x3 0.08634079 -0.93885697 -0.3244419 0.07635606 0.0002153806
x4 0.54474435 0.07823418 -0.1733473 -0.39261231 0.7161978059
x5 -0.44769707 -0.29449936 0.6043889 -0.54738699 0.2189041307
summary(pca)
Importance of components:
PC1 PC2 PC3 PC4 PC5
Standard deviation 1.7777 1.0147 0.8047 0.36179 0.17804
Proportion of Variance 0.6321 0.2059 0.1295 0.02618 0.00634
Cumulative Proportion 0.6321 0.8380 0.9675 0.99366 1.00000
Plot Dari Komponen Utama
plot(pca,type="l")