Vous êtes sur la page 1sur 11

data=read.

delim("clipboard")

> data
Makanan Sandang Perumahan Kesehatan Transportasi Informasi Rekreasi Pendidikan PenyediaanMakanan Perawatan

1 108.18 110.16 103.95 109.52 102.99 99.35 106.10 110.69 107.58 116.13

2 108.85 110.21 104.11 109.99 102.77 99.44 106.26 110.75 107.59 115.75

3 109.26 110.16 104.15 110.41 102.57 99.42 106.38 110.75 107.66 115.38

4 109.02 110.28 104.26 110.44 102.27 99.55 107.13 110.75 107.85 115.87

5 108.83 110.25 104.28 110.42 102.55 99.52 107.41 110.75 107.96 116.87

6 108.48 110.09 104.42 110.77 102.92 99.63 107.34 110.75 107.99 117.59

7 108.87 110.01 104.43 110.98 103.09 99.75 107.23 110.75 108.11 117.33

8 108.89 109.80 104.43 110.73 103.01 99.76 107.41 111.23 108.20 117.74

9 107.79 109.78 104.55 110.87 102.84 99.78 107.84 111.23 108.20 118.50

10 108.04 109.89 104.62 110.91 103.41 99.84 107.76 112.06 108.20 118.95

11 109.21 109.91 104.70 111.38 103.95 99.91 109.16 112.07 108.29 119.77

12 111.81 109.89 104.92 111.40 104.70 99.96 109.12 112.07 108.42 120.00

> #normalisasi data

> data.normal=data

> data.normal
Makanan Sandang Perumahan Kesehatan Transportasi Informasi Rekreasi Pendidikan PenyediaanMakanan Perawatan

1 108.18 110.16 103.95 109.52 102.99 99.35 106.10 110.69 107.58 116.13

2 108.85 110.21 104.11 109.99 102.77 99.44 106.26 110.75 107.59 115.75

3 109.26 110.16 104.15 110.41 102.57 99.42 106.38 110.75 107.66 115.38

4 109.02 110.28 104.26 110.44 102.27 99.55 107.13 110.75 107.85 115.87

5 108.83 110.25 104.28 110.42 102.55 99.52 107.41 110.75 107.96 116.87

6 108.48 110.09 104.42 110.77 102.92 99.63 107.34 110.75 107.99 117.59

7 108.87 110.01 104.43 110.98 103.09 99.75 107.23 110.75 108.11 117.33

8 108.89 109.80 104.43 110.73 103.01 99.76 107.41 111.23 108.20 117.74

9 107.79 109.78 104.55 110.87 102.84 99.78 107.84 111.23 108.20 118.50
10 108.04 109.89 104.62 110.91 103.41 99.84 107.76 112.06 108.20 118.95

11 109.21 109.91 104.70 111.38 103.95 99.91 109.16 112.07 108.29 119.77

12 111.81 109.89 104.92 111.40 104.70 99.96 109.12 112.07 108.42 120.00

> data.pca=prcomp(data.normal,center=F)

> data.pca

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

[1] 357.33132946 1.37075922 0.87287064 0.41371416 0.23617128 0.20022169 0.12913314


0.06653425 0.03141814 0.01245978

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

PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9

Makanan -0.3184199 -0.18231010 0.88382776 -0.070363489 0.03421476 0.06575842


0.22848797 0.11277588 0.03604590

Sandang -0.3216255 -0.46236492 -0.21795750 0.063618458 -0.10063686 -0.53887020 -


0.12031181 0.47742506 0.25035715

Perumahan -0.3051622 -0.15787216 -0.15413336 -0.038130190 0.12167438 0.04849088


0.19090793 0.24007732 -0.68381853

Kesehatan -0.3234334 -0.03756943 -0.11843478 -0.436677379 0.30284413 0.53476157 -


0.49271777 0.18023813 0.18437756

Transportasi -0.3013303 0.04803722 0.15849979 0.599244143 0.20820109 -0.14100774 -


0.55634434 -0.33271252 -0.04155101

Informasi -0.2912992 -0.18651808 -0.19451048 0.007739662 0.14040260 0.03749954


0.15330013 -0.38686318 -0.39131775

Rekreasi -0.3140178 0.30205785 0.06197136 -0.532617843 -0.47026103 -0.37376228 -


0.21806803 -0.30218769 -0.11652854

Pendidikan -0.3249026 0.01133905 -0.13249316 0.357381186 -0.69644261 0.49125642


0.09321558 0.05828347 0.10243863

PenyediaanMakanan -0.3156920 -0.16245358 -0.20561907 -0.084806381 0.21993408 -0.01525850


0.44862057 -0.45610721 0.49804011

Perawatan -0.3434345 0.75616888 -0.08323779 0.145299624 0.25411222 -0.12008374


0.25214778 0.32575315 0.08629331

PC10
Makanan 0.086890646

Sandang 0.160080529

Perumahan -0.527157136

Kesehatan 0.048262927

Transportasi -0.193656301

Informasi 0.703597050

Rekreasi -0.096633264

Pendidikan 0.009434408

PenyediaanMakanan -0.344287849

Perawatan 0.161516545

> #komponen data

> summary(data.pca)

Importance of components:

PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 PC10

Standard deviation 357.3 1.37076 0.87287 0.4137 0.2362 0.2002 0.1291 0.06653 0.03142 0.01246

Proportion of Variance 1.0 0.00001 0.00001 0.0000 0.0000 0.0000 0.0000 0.00000 0.00000 0.00000

Cumulative Proportion 1.0 0.99999 1.00000 1.0000 1.0000 1.0000 1.0000 1.00000 1.00000 1.00000

> #standarisasi

> data[]=lapply(data.normal, function(x) if(is.numeric(x)){scale(x,center=TRUE,scale=TRUE)}else x)

> #analisis biplot

> matriks<-as.matrix.data.frame(data)

> matriks

Makanan Sandang Perumahan Kesehatan Transportasi Informasi Rekreasi Pendidikan


PenyediaanMakanan

[1,] -0.74350902 0.6963999 -1.65774818 -2.0954939 -0.148905374 -1.5250208 -1.35925813 -


0.7997805 -1.50248256

[2,] -0.08443377 0.9768294 -1.07050159 -1.2252004 -0.479250070 -1.0810794 -1.19553319 -


0.6963977 -1.46706057
[3,] 0.31888094 0.6963999 -0.92368994 -0.4474913 -0.779563429 -1.1797330 -1.07273948 -
0.6963977 -1.21910667

[4,] 0.08279428 1.3694307 -0.51995792 -0.3919407 -1.230033469 -0.5384844 -0.30527880 -


0.6963977 -0.54608895

[5,] -0.10410766 1.2011730 -0.44655209 -0.4289745 -0.809594765 -0.6864649 -0.01876015 -


0.6963977 -0.15644710

[6,] -0.44840070 0.3037986 0.06728867 0.2191164 -0.254015050 -0.1438699 -0.09038981 -


0.6963977 -0.05018115

[7,] -0.06475988 -0.1448886 0.10399158 0.6079710 0.001251306 0.4480519 -0.20295071 -0.6963977


0.37488268

[8,] -0.04508599 -1.3226925 0.10399158 0.1450489 -0.118874038 0.4973787 -0.01876015 0.1306643


0.69368055

[9,] -1.12714984 -1.4348643 0.54442652 0.4042853 -0.374140394 0.5960324 0.42125064 0.1306643


0.69368055

[10,] -0.88122624 -0.8179194 0.80134691 0.4783528 0.481752681 0.8919933 0.33938817


1.5607925 0.69368055

[11,] 0.26969622 -0.7057476 1.09497020 1.3486463 1.292598752 1.2372810 1.77198143


1.5780229 1.01247842

[12,] 2.82730166 -0.8179194 1.90243426 1.3856801 2.418773850 1.4839151 1.73105019


1.5780229 1.47296424

Perawatan

[1,] -0.86668166

[2,] -1.10884271

[3,] -1.34463111

[4,] -1.03237080

[5,] -0.39510487

[6,] 0.06372659

[7,] -0.10196255

[8,] 0.15931648

[9,] 0.64363859

[10,] 0.93040825

[11,] 1.45296631
[12,] 1.59953748

> ##Biplot dengan Manual

> #Singular Value Decomposition

> y<-svd(matriks)

> #Matriks L, A, dan U

> L<-diag(y$d)

> A<-y$v

> U<-y$u

>L

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]

[1,] 9.306944 0.000000 0.000000 0.000000 0.000000 0.0000000 0.0000000 0.0000000 0.0000000
0.00000000

[2,] 0.000000 3.477013 0.000000 0.000000 0.000000 0.0000000 0.0000000 0.0000000 0.0000000
0.00000000

[3,] 0.000000 0.000000 2.317693 0.000000 0.000000 0.0000000 0.0000000 0.0000000 0.0000000
0.00000000

[4,] 0.000000 0.000000 0.000000 1.738195 0.000000 0.0000000 0.0000000 0.0000000 0.0000000
0.00000000

[5,] 0.000000 0.000000 0.000000 0.000000 1.134115 0.0000000 0.0000000 0.0000000 0.0000000
0.00000000

[6,] 0.000000 0.000000 0.000000 0.000000 0.000000 0.8980631 0.0000000 0.0000000 0.0000000
0.00000000

[7,] 0.000000 0.000000 0.000000 0.000000 0.000000 0.0000000 0.6738211 0.0000000 0.0000000
0.00000000

[8,] 0.000000 0.000000 0.000000 0.000000 0.000000 0.0000000 0.0000000 0.4790547 0.0000000
0.00000000

[9,] 0.000000 0.000000 0.000000 0.000000 0.000000 0.0000000 0.0000000 0.0000000 0.3429302
0.00000000

[10,] 0.000000 0.000000 0.000000 0.000000 0.000000 0.0000000 0.0000000 0.0000000 0.0000000
0.06537941

>A

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]


[1,] 0.1701498 -0.8084700135 -0.08452634 0.38975762 0.16374342 -0.26768866 0.008931057 -
0.03677054 0.003089263

[2,] -0.2787199 -0.4311847623 -0.30830063 -0.68449360 -0.12351774 0.15897494 -0.349514292


0.07402379 -0.058736998

[3,] 0.3503620 -0.0137686726 -0.18278065 -0.03338708 0.07565267 0.08546609 -0.259822979 -


0.75548066 0.236870507

[4,] 0.3271753 0.0223371953 -0.49098989 0.03666553 0.23295428 0.59515353 0.344187982


0.08276418 -0.319587327

[5,] 0.3017669 -0.3194742996 0.52769402 0.03556402 -0.39781382 0.45371969 -0.018926797


0.18435494 -0.068597181

[6,] 0.3480424 0.1319164275 -0.13115972 0.06875118 0.06734101 0.13763000 -0.411360117


0.44287911 0.634023938

[7,] 0.3390994 -0.0724121839 -0.19642352 -0.37138019 -0.21283038 -0.39635860 0.577818240


0.16537955 0.281947400

[8,] 0.3187636 0.0008908542 0.43917455 -0.42334855 0.68346459 -0.12829576 -0.066085800


0.06778761 -0.182014822

[9,] 0.3400998 0.1502114529 -0.26427759 0.11381822 -0.19204767 -0.37531000 -0.428913385


0.24374301 -0.548622120

[10,] 0.3451142 0.1117758510 0.16236751 -0.20249717 -0.43109959 -0.04833697 -0.001826591 -


0.30672889 -0.134144830

[,10]

[1,] 0.24178311

[2,] 0.03456460

[3,] -0.36761257

[4,] 0.11880740

[5,] -0.35210681

[6,] 0.22070953

[7,] -0.24524895

[8,] 0.02480215

[9,] -0.23847003

[10,] 0.70765102

>U
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]

[1,] -0.39633668 -0.02922290 0.63578707 -0.028891540 -0.40555441 -0.1217967 0.00453260


0.15783363 -0.0582515727

[2,] -0.33227285 -0.17642279 0.22814333 -0.003289532 0.13686252 0.1763691 -0.06746038 -


0.09765336 0.4988800318

[3,] -0.29227006 -0.20658483 -0.04358481 0.218585917 0.51925391 0.2239062 0.44075727 -


0.15635988 -0.3986292608

[4,] -0.22608090 -0.14754571 -0.42686921 -0.246107799 0.26961008 -0.2774466 -0.18873247


0.16557170 0.4188804358

[5,] -0.16659054 -0.09664323 -0.31558233 -0.331143544 -0.26001084 -0.4029318 -0.07667762 -


0.05411699 -0.4635270562

[6,] -0.04729182 0.08719434 -0.23958800 -0.049523446 -0.38621379 0.3455874 0.03997731 -


0.41373933 -0.0783202726

[7,] 0.02391042 0.07036925 -0.30508026 0.320510261 -0.24190219 0.5136346 -0.27290300


0.42574054 0.0005099721

[8,] 0.09759481 0.24033693 0.04186079 0.528110475 0.14974697 -0.4073735 -0.05171226


0.33716330 -0.1506991804

[9,] 0.13626889 0.53937169 -0.06047029 0.174903578 -0.08291202 -0.2250957 0.27766807 -


0.41213455 0.3271623759

[10,] 0.23001673 0.34901865 0.28868337 -0.351291897 0.40331585 0.1785084 -0.51627832 -


0.13457404 -0.2304193490

[11,] 0.41236318 0.01126419 0.07144947 -0.444710893 -0.01937739 0.1264824 0.56099897


0.43759584 0.0829489120

[12,] 0.56068881 -0.64113559 0.12525088 0.212848420 -0.08281869 -0.1298439 -0.15017018 -


0.25532686 0.0514649643

[,10]

[1,] -0.31959623

[2,] 0.49810962

[3,] -0.20367666

[4,] -0.25315372

[5,] 0.12441578

[6,] 0.35220818

[7,] -0.26407674
[8,] 0.44628122

[9,] -0.32060381

[10,] -0.05182464

[11,] 0.11891268

[12,] -0.12699567

> #jika alfa=1

> G=U

> H=A%*%L

>H

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]

[1,] 1.583575 -2.811060908 -0.1959061 0.67747471 0.18570393 -0.24040131 0.006017934 -


0.01761510 0.001059402 0.015807638

[2,] -2.594030 -1.499235110 -0.7145464 -1.18978330 -0.14008337 0.14276952 -0.235510092


0.03546145 -0.020142690 0.002259813

[3,] 3.260800 -0.047873856 -0.4236295 -0.05803326 0.08579885 0.07675394 -0.175074196 -


0.36191658 0.081230049 -0.024034294

[4,] 3.045002 0.077666723 -1.1379641 0.06373184 0.26419703 0.53448542 0.231921112


0.03964857 -0.109596144 0.007767558

[5,] 2.808528 -1.110816356 1.2230330 0.06181721 -0.45116676 0.40746891 -0.012753275


0.08831611 -0.023524044 -0.023020537

[6,] 3.239212 0.458675159 -0.3039880 0.11950296 0.07637247 0.12360043 -0.277183112


0.21216333 0.217425952 0.014429860

[7,] 3.155980 -0.251778119 -0.4552495 -0.64553116 -0.24137420 -0.35595503 0.389346100


0.07922586 0.096688276 -0.016034233

[8,] 2.966715 0.003097512 1.0178720 -0.73586230 0.77512769 -0.11521769 -0.044530004


0.03247397 -0.062418378 0.001621550

[9,] 3.165290 0.522287204 -0.6125144 0.19783826 -0.21780422 -0.33705206 -0.289010873


0.11676624 -0.188139090 -0.015591031

[10,] 3.211958 0.388646109 0.3763181 -0.35197956 -0.48891667 -0.04340965 -0.001230796 -


0.14693993 -0.046002312 0.046265809

> #Cek besar keragaman yang mampu dijelaskan biplot (baiknya > 70%)

> cek<-eigen(t(matriks)%*%matriks)$values
> dim1<-sum(cek[1])/sum(cek)*100

> dim2<-sum(cek[2])/sum(cek)*100

> dim1+dim2

[1] 89.73531

> #matriks var covar (analisa keragaman/panjang panah di biplot)

> var<-H%*%t(H)

> sqrt(diag(var))

[1] 3.316625 3.316625 3.316625 3.316625 3.316625 3.316625 3.316625 3.316625 3.316625 3.316625

> cov2cor(var)

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]

[1,] 1.00000000 -0.05652977 0.4858619 0.4355499 0.6535096 0.3600187 0.4908084 0.3783759


0.3486051 0.3276903

[2,] -0.05652977 1.00000000 -0.7263130 -0.6626962 -0.5854147 -0.8127127 -0.6203427 -0.6967569 -


0.7939321 -0.7914822

[3,] 0.48586194 -0.72631302 1.0000000 0.9457682 0.7864548 0.9697638 0.9451601 0.8485287


0.9539312 0.9381109

[4,] 0.43554991 -0.66269616 0.9457682 1.0000000 0.6526731 0.9326567 0.8996383 0.7245194


0.9189921 0.8369867

[5,] 0.65350957 -0.58541471 0.7864548 0.6526731 1.0000000 0.7505676 0.7736937 0.8305701


0.6865867 0.8379637

[6,] 0.36001867 -0.81271274 0.9697638 0.9326567 0.7505676 1.0000000 0.9123544 0.8422293


0.9734454 0.9402856

[7,] 0.49080844 -0.62034267 0.9451601 0.8996383 0.7736937 0.9123544 1.0000000 0.8369854


0.9145961 0.9282791

[8,] 0.37837591 -0.69675688 0.8485287 0.7245194 0.8305701 0.8422293 0.8369854 1.0000000


0.7746796 0.8905891

[9,] 0.34860511 -0.79393212 0.9539312 0.9189921 0.6865867 0.9734454 0.9145961 0.7746796


1.0000000 0.9256253

[10,] 0.32769032 -0.79148223 0.9381109 0.8369867 0.8379637 0.9402856 0.9282791 0.8905891


0.9256253 1.0000000

> ##Biplot dengan menggunakan fungsi princomp atau prcomp

> #Mendefinisikan Model PCA


> ###Model 1

> model1<-princomp(matriks,cor=T)

Error in if (cor) { : argument is not interpretable as logical

> summary(model1)

Importance of components:

Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8


Comp.9

Standard deviation 2.8061493 1.0483589 0.69881087 0.52408549 0.34194865 0.270776212


0.203164695 0.144440436 0.103397344

Proportion of Variance 0.7874474 0.1099056 0.04883366 0.02746656 0.01169289 0.007331976


0.004127589 0.002086304 0.001069101

Cumulative Proportion 0.7874474 0.8973531 0.94618672 0.97365328 0.98534617 0.992678147


0.996805736 0.998892040 0.999961141

Comp.10

Standard deviation 0.0197126349

Proportion of Variance 0.0000388588

Cumulative Proportion 1.0000000000

> biplot(model1)

> ###Model 2

> model2<-prcomp(matriks,scale=T)

Error in scale.default(x, center = center, scale = scale.) :

length of 'scale' must equal the number of columns of 'x'

> summary(model2)

Importance of components:

PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 PC10

Standard deviation 2.8061 1.0484 0.69881 0.52409 0.34195 0.27078 0.20316 0.14444 0.10340
0.01971

Proportion of Variance 0.7874 0.1099 0.04883 0.02747 0.01169 0.00733 0.00413 0.00209 0.00107
0.00004

Cumulative Proportion 0.7874 0.8973 0.94619 0.97365 0.98535 0.99268 0.99681 0.99889 0.99996
1.00000
> biplot(model2)

>

Vous aimerez peut-être aussi