Oleh: Andi Syaiful Rahmat
ANALISIS KOMPONEN UTAMA (PCA)
A. Load Dataset
x1 <- c(78, 103, 103, 105, 109, 123, 123, 133, 133, 133, 134, 136, 138, 138, 141, 147, 149, 153, 155, 155, 158, 159, 162, 177, 93, 94, 96, 101, 102, 103, 104, 106, 107, 112, 113, 114, 116, 117, 117, 119, 120, 120, 121, 125, 127, 128, 131, 135)
x2 <- c(71, 84, 86, 86, 88, 92, 95, 99, 102, 102, 100, 102, 98, 99, 105, 108, 107, 107, 115, 117, 115, 118, 124, 132, 74, 78, 80, 84, 85, 81, 83, 83, 82, 89, 88, 86, 90, 90, 91, 93, 89, 93, 95, 93, 96, 95, 95, 106)
x3 <- c(48, 38, 42, 42, 44, 50, 46, 51, 51, 51, 48, 49, 51, 51, 53, 57, 55, 56, 63, 60, 62, 63, 61, 67, 37, 35, 35, 39, 38, 37, 39, 39, 38, 40, 40, 40, 43, 41, 41, 41, 40, 44, 42, 45, 45, 45, 46, 47)
Y <- c(31, 34, 20, 44, 12, 52, 25, 49, 62, 52, 22, 42, 77, 32, 32, 10, 61, 65, 15, 47, 55, 28, 24, 32, 74, 78, 20, 44, 25, 61, 13, 53, 52, 39, 18, 66, 50, 40, 51, 23, 59, 33, 55, 43, 26, 55, 25, 56)
n <- length(x1)
data<- data.frame(log(x1), log(x2), log(x3))
B. Membuat Matriks Korelasi serta Menampilkan Nilai Eigen dan Vektor Eigen dari Matriks Korelasi
r <- cor(data, use = 'complete.obs')
mtx_cor <- matrix(r, 3, 3)
eigen(mtx_cor)$value
## [1] 2.82676958 0.15142358 0.02180684
eigen(mtx_cor)$vector
## [,1] [,2] [,3]
## [1,] -0.5812592 0.4851026 0.6533094
## [2,] -0.5868582 0.3062517 -0.7495381
## [3,] -0.5636800 -0.8190759 0.1066748
Interpretasi: Berdasarkan hasil analisis, diperoleh nilai eigen dari matriks korelasi adalah 2,82676958, 0,15142358, 0,02180684 dan dapat dilihat bahwa nilai eigen pada komponen utama pertama memiliki nilai yang lebih besar dari 1. Sehingga nilai eigen pada komponen utama pertama akan menjadi koefisien pada model komponen utama yang terbentuk nantinya. Selain itu, diperoleh juga vektor eigen dari matriks korelasi sebagai berikut:
v_1’=[-0,5812592 0,4851026 0,6533094]
v_2’=[-0,5868582 0,3062517 -0,7495381]
v_3’=[-0,5636800 0,8190759 0,1066748]
C. Melakukan Analisis Komponen Utama
fit_pca <- princomp(data, cor = FALSE)
summary(fit_pca)
## Importance of components:
## Comp.1 Comp.2 Comp.3
## Standard deviation 0.2648404 0.06450718 0.021374745
## Proportion of Variance 0.9382270 0.05566158 0.006111408
## Cumulative Proportion 0.9382270 0.99388859 1.000000000
Interpretasi: Berdasarkan hasil analisis, diperoleh nilai proporsi variansi pada komponen utama pertama adalah sebesar 93,82% . Apabila dijumlahkan dengan komponen utama kedua hasilnya sebesar 99,39%, dimana nilai proporsi variansi pada komponen utama kedua adalah sebesar 5,57%. Sehingga dapat disimpulkan bahwa satu komponen utama, dalam hal ini komponen utama pertama sudah dapat dikatakan mencukupi.
D. Menampilkan Hasil Visualisasi dari Analisis Komponen Utama
plot_pca <- loadings(fit_pca)
plot_pca
##
## Loadings:
## Comp.1 Comp.2 Comp.3
## log.x1. 0.626 0.556 0.548
## log.x2. 0.488 0.269 -0.830
## log.x3. 0.609 -0.787 0.103
##
## Comp.1 Comp.2 Comp.3
## SS loadings 1.000 1.000 1.000
## Proportion Var 0.333 0.333 0.333
## Cumulative Var 0.333 0.667 1.000
plot(fit_pca,type = "lines")
Interpretasi: Berdasarkan hasil analisis, diperoleh fungsi komponen utama adalah sebagai berikut:
y_i=log(x_i), i=1,2,3
dimana komponen utamanya
KU_1 = 0.626 log(x_1)+0.488 log(x_2)+0.609 log(x_3)
KU_2 = 0.488 log(x_1)+0.269 log(x_2)+0.333 log(x_3)
KU_3 = 0.609 log(x_1)-0.787 log(x_2)+0.103 log(x_3)
Selain itu, hasil visualisasi plot komponen utama terhadap variansinya menunjukkan bahwa garis pada komponen kedua melandai. Sehingga dapat disimpulkan bahwa satu komponen utama, dalam hal ini komponen utama pertama sudah cukup untuk mewakili ketiga variabel lainnya.
E. Menampilkan Skor Komponen Utama
fit_pca$scores
## Comp.1 Comp.2 Comp.3
## [1,] -0.394326019 -0.3626422889 -0.0061599220
## [2,] -0.280572283 0.0208540157 -0.0176405684
## [3,] -0.208164448 -0.0515511907 -0.0268587329
## [4,] -0.196135164 -0.0408621075 -0.0163285327
## [5,] -0.133210970 -0.0504966639 -0.0101496618
## [6,] 0.041883334 -0.0719447541 0.0322855528
## [7,] 0.006787227 0.0022726307 -0.0029592447
## [8,] 0.138619519 -0.0243654197 0.0162334889
## [9,] 0.153189290 -0.0163407834 -0.0085561543
## [10,] 0.153189290 -0.0163407834 -0.0085561543
## [11,] 0.111306044 0.0301897569 0.0057372542
## [12,] 0.142789193 0.0275271631 -0.0004682085
## [13,] 0.156748572 -0.0065823181 0.0448711513
## [14,] 0.161703448 -0.0038533063 0.0364407095
## [15,] 0.227288381 -0.0063425650 0.0033227959
## [16,] 0.311394387 -0.0328436761 0.0102514656
## [17,] 0.293564573 0.0002644359 0.0216920601
## [18,] 0.321103566 0.0008146790 0.0380558413
## [19,] 0.436115196 -0.0652387343 -0.0025602565
## [20,] 0.414830067 -0.0222234189 -0.0219093121
## [21,] 0.438366166 -0.0419971867 0.0062862235
## [22,] 0.464620985 -0.0441546627 -0.0099937441
## [23,] 0.480880681 0.0049445356 -0.0442706554
## [24,] 0.623894507 -0.0028325554 -0.0380240007
## [25,] -0.422549689 -0.0490041560 0.0289413595
## [26,] -0.423993924 0.0148052100 -0.0146480800
## [27,] -0.398468561 0.0333125770 -0.0241439009
## [28,] -0.277025406 -0.0104782033 -0.0256984690
## [29,] -0.280898984 0.0186125510 -0.0328098281
## [30,] -0.314555298 0.0320566888 0.0098085799
## [31,] -0.264561673 0.0025714556 0.0002735581
## [32,] -0.252646960 0.0131587318 0.0107034645
## [33,] -0.268501532 0.0355529382 0.0232315361
## [34,] -0.168731287 0.0426070950 -0.0144951965
## [35,] -0.168685979 0.0445103261 -0.0002449687
## [36,] -0.174394959 0.0432277023 0.0236696205
## [37,] -0.097304686 0.0082240115 0.0028992168
## [38,] -0.120928121 0.0504614378 0.0026875140
## [39,] -0.115535237 0.0534316930 -0.0064881748
## [40,] -0.094323006 0.0686963399 -0.0152600817
## [41,] -0.125576006 0.0809543812 0.0232820941
## [42,] -0.046101642 0.0177964585 -0.0033954032
## [43,] -0.058844360 0.0647233582 -0.0213174260
## [44,] -0.006887453 0.0228077437 0.0212743938
## [45,] 0.018536368 0.0401646124 0.0036020568
## [46,] 0.018331774 0.0417092281 0.0165918935
## [47,] 0.046202058 0.0372961955 0.0315437285
## [48,] 0.131579021 0.0665468219 -0.0407488818
ANALISIS FAKTOR
A. Load Dataset
x1 <- c(78, 103, 103, 105, 109, 123, 123, 133, 133, 133, 134, 136, 138, 138, 141, 147, 149, 153, 155, 155, 158, 159, 162, 177, 93, 94, 96, 101, 102, 103, 104, 106, 107, 112, 113, 114, 116, 117, 117, 119, 120, 120, 121, 125, 127, 128, 131, 135)
x2 <- c(71, 84, 86, 86, 88, 92, 95, 99, 102, 102, 100, 102, 98, 99, 105, 108, 107, 107, 115, 117, 115, 118, 124, 132, 74, 78, 80, 84, 85, 81, 83, 83, 82, 89, 88, 86, 90, 90, 91, 93, 89, 93, 95, 93, 96, 95, 95, 106)
x3 <- c(48, 38, 42, 42, 44, 50, 46, 51, 51, 51, 48, 49, 51, 51, 53, 57, 55, 56, 63, 60, 62, 63, 61, 67, 37, 35, 35, 39, 38, 37, 39, 39, 38, 40, 40, 40, 43, 41, 41, 41, 40, 44, 42, 45, 45, 45, 46, 47)
x4 <- c(12, 13, 20, 14, 14, 15, 9, 11, 11, 21, 8, 9, 11, 12, 13, 17, 15, 16, 13, 10, 12, 20, 9, 7, 37, 35, 35, 39, 38, 37, 39, 39, 38, 40, 40, 40, 43, 41, 41, 41, 40, 44, 42, 45, 45, 45, 46, 47)
x5 <- c(8, 10, 42, 42, 44, 50, 46, 51, 51, 51, 48, 49, 51, 51, 53, 57, 55, 56, 63, 60, 62, 63, 61, 67, 37, 35, 35, 39, 38, 37, 39, 39, 38, 40, 40, 40, 43, 41, 41, 41, 40, 44, 42, 45, 45, 45, 46, 47)
Y <- c(31, 34, 20, 44, 12, 52, 25, 29, 62, 52, 22, 42, 77, 32, 32, 10, 61, 65, 15, 47, 55, 28, 24, 32, 74, 78, 20, 44, 25, 61, 13, 53, 52, 39, 18, 66, 50, 40, 51, 23, 59, 33, 55, 43, 26, 55, 25, 56)
data <- data.frame(x1, x2, x3, x4, x5)
B. Menampilkan Analisis Faktor
r <- cor(data, use = 'complete.obs')
mtx_cov <- matrix(r, 5, 5)
fit <- factanal(factors = 2, covmat = mtx_cov)
fit
##
## Call:
## factanal(factors = 2, covmat = mtx_cov)
##
## Uniquenesses:
## [1] 0.005 0.034 0.012 0.441 0.204
##
## Loadings:
## Factor1 Factor2
## [1,] 0.930 0.361
## [2,] 0.891 0.416
## [3,] 0.696 0.709
## [4,] -0.226 -0.713
## [5,] 0.851 0.266
##
## Factor1 Factor2
## SS loadings 2.919 1.385
## Proportion Var 0.584 0.277
## Cumulative Var 0.584 0.861
##
## The degrees of freedom for the model is 1 and the fit was 0.0092
factor_analysis <- factanal(~x1 + x2 + x3 + x4 + x5, factors = 2, data = data, rotation = "varimax", scores = "regression")
factor_analysis
##
## Call:
## factanal(x = ~x1 + x2 + x3 + x4 + x5, factors = 2, data = data, scores = "regression", rotation = "varimax")
##
## Uniquenesses:
## x1 x2 x3 x4 x5
## 0.005 0.034 0.012 0.441 0.204
##
## Loadings:
## Factor1 Factor2
## x1 0.930 0.361
## x2 0.891 0.416
## x3 0.696 0.709
## x4 -0.226 -0.713
## x5 0.851 0.266
##
## Factor1 Factor2
## SS loadings 2.919 1.385
## Proportion Var 0.584 0.277
## Cumulative Var 0.584 0.861
##
## Test of the hypothesis that 2 factors are sufficient.
## The chi square statistic is 0.4 on 1 degree of freedom.
## The p-value is 0.528
Interpretasi: Berdasarkan hasil analisis, dapat dilihat nilai uniqueness dari masing-masing variabel kurang dari 0,5. Sehingga faktor-faktor yang terbentuk dapat menjelaskan variabilitasnya dengan baik. Apabila dilihat pada loadings factor terhadap masing-masing variabel, diperoleh variabel yang dapat direduksi adalah faktor 1 yang berisikan x_1, x_2, dan x_5. Adapun untuk faktor 2 berisikan x_3 dan x_4. Dari SS loadings dari masing-masing faktor diperoleh nilai lebih dari 1, yang berarti kedua faktor layak untuk dipertahankan. Selain itu, diperoleh juga nilai p-value sebesar 0,528 dimana nilai ini lebih besar dari nilai taraf signifikansi (0,05). Sehingga dapat disimpulkan bahwa faktor 1 dan faktor 2 cukup untuk menggambarkan data.