# Load data (pastikan file hcvdat0.csv sudah di-upload ke tab Files)
data <- read.csv("hcvdat0.csv")
# Mengambil kolom numerik saja dan menghapus NA agar perhitungan bisa jalan
data_numeric <- na.omit(data[, 5:14])
# a) Correlation Matrix
print("Matriks Korelasi:")
## [1] "Matriks Korelasi:"
cor(data_numeric)
## ALB ALP ALT AST BIL CHE
## ALB 1.000000000 -0.14611991 0.03949714 -0.17760895 -0.16959750 0.36091940
## ALP -0.146119911 1.00000000 0.22160301 0.06702428 0.05837241 0.02948169
## ALT 0.039497139 0.22160301 1.00000000 0.19865775 -0.10679662 0.22434447
## AST -0.177608947 0.06702428 0.19865775 1.00000000 0.30957974 -0.19727042
## BIL -0.169597498 0.05837241 -0.10679662 0.30957974 1.00000000 -0.32071323
## CHE 0.360919403 0.02948169 0.22434447 -0.19727042 -0.32071323 1.00000000
## CHOL 0.210419878 0.12590008 0.14999727 -0.20121300 -0.18156956 0.42801828
## CREA 0.001433247 0.15390895 -0.03610554 -0.01794810 0.01990962 -0.01212000
## GGT -0.147598318 0.46130000 0.21970686 0.47777362 0.21056656 -0.09571613
## PROT 0.570725680 -0.06308514 0.01678633 0.01740394 -0.05257491 0.30628754
## CHOL CREA GGT PROT
## ALB 0.210419878 0.001433247 -0.147598318 0.57072568
## ALP 0.125900079 0.153908950 0.461299996 -0.06308514
## ALT 0.149997271 -0.036105541 0.219706857 0.01678633
## AST -0.201213004 -0.017948098 0.477773617 0.01740394
## BIL -0.181569556 0.019909617 0.210566559 -0.05257491
## CHE 0.428018276 -0.012119999 -0.095716131 0.30628754
## CHOL 1.000000000 -0.051464078 0.008822692 0.24504950
## CREA -0.051464078 1.000000000 0.125353469 -0.03011070
## GGT 0.008822692 0.125353469 1.000000000 -0.03712701
## PROT 0.245049503 -0.030110695 -0.037127008 1.00000000
# b) Variance-Covariance Matrix
print("Matriks Kovarian:")
## [1] "Matriks Kovarian:"
cov(data_numeric)
## ALB ALP ALT AST BIL CHE
## ALB 33.1982701 -21.823283 4.747912 -33.634186 -17.009455 4.556430
## ALP -21.8232826 671.901949 119.841675 57.100968 26.337454 1.674411
## ALT 4.7479116 119.841675 435.269784 136.220708 -38.783770 10.255372
## AST -33.6341863 57.100968 136.220708 1080.231200 177.110426 -14.206173
## BIL -17.0094554 26.337454 -38.783770 177.110426 302.988734 -12.231702
## CHE 4.5564303 1.674411 10.255372 -14.206173 -12.231702 4.800799
## CHOL 1.3687395 3.684302 3.532962 -7.466047 -3.568064 1.058755
## CREA 0.4186596 202.254881 -38.188738 -29.906045 17.569457 -1.346299
## GGT -46.1804560 649.315069 248.909775 852.706557 199.031456 -11.388355
## PROT 17.5892871 -8.746677 1.873261 3.059630 -4.895025 3.589626
## CHOL CREA GGT PROT
## ALB 1.3687395 0.4186596 -46.1804560 17.589287
## ALP 3.6843023 202.2548814 649.3150694 -8.746677
## ALT 3.5329616 -38.1887382 248.9097752 1.873261
## AST -7.4660468 -29.9060449 852.7065571 3.059630
## BIL -3.5680635 17.5694569 199.0314564 -4.895025
## CHE 1.0587548 -1.3462991 -11.3883550 3.589626
## CHOL 1.2745375 -2.9455248 0.5408745 1.479767
## CREA -2.9455248 2570.1849279 345.0941704 -8.165186
## GGT 0.5408745 345.0941704 2948.7514092 -10.783808
## PROT 1.4797666 -8.1651857 -10.7838076 28.610549
# c) Eigen value dan eigen vector (dari matriks kovarian)
ev <- eigen(cov(data_numeric))
print("Eigen Value:")
## [1] "Eigen Value:"
ev$values
## [1] 3590.5373071 2476.8097617 843.4296979 489.7187901 380.2428453
## [6] 232.3374883 47.2653540 12.3734800 3.5747390 0.9226964
print("Eigen Vector:")
## [1] "Eigen Vector:"
ev$vectors
## [,1] [,2] [,3] [,4] [,5]
## [1,] 0.0156218028 0.0081947233 -0.01293557 0.005719585 -0.062047828
## [2,] -0.2240444617 -0.0044550145 -0.45302019 -0.600736009 0.598336308
## [3,] -0.0846236613 -0.0637826732 -0.02241537 -0.667268736 -0.610707415
## [4,] -0.3032719000 -0.1980907922 0.83553615 -0.280769844 0.169557280
## [5,] -0.0710508473 -0.0326184499 0.17265724 0.123240052 0.448773979
## [6,] 0.0039750179 0.0017948186 -0.01494087 -0.018409759 -0.030439045
## [7,] 0.0005335915 -0.0006255074 -0.01077785 -0.005578380 -0.007781516
## [8,] -0.3245507772 0.9383531779 0.11145005 -0.011225544 -0.039043340
## [9,] -0.8602402464 -0.2739091658 -0.23095286 0.315146852 -0.179228468
## [10,] 0.0037725469 -0.0020771672 0.00848671 -0.001601357 -0.019952778
## [,6] [,7] [,8] [,9] [,10]
## [1,] -0.009602406 0.723108927 0.683402230 -0.0745185033 -8.275758e-03
## [2,] -0.155311540 0.035391284 0.015744551 -0.0056893951 3.516929e-03
## [3,] 0.410506669 -0.028165930 -0.014504902 -0.0230684653 2.335389e-03
## [4,] -0.249244174 0.016034548 0.023483799 0.0106465034 -6.289793e-03
## [5,] 0.862800270 0.047104851 0.010249748 0.0272555209 -7.144701e-05
## [6,] -0.014625740 0.111230857 -0.012696297 0.9677036977 2.220235e-01
## [7,] -0.001774051 0.040386338 -0.031658544 0.2179789842 -9.744948e-01
## [8,] 0.008460369 -0.001383688 -0.003559904 0.0004543819 -1.492079e-03
## [9,] 0.013168734 0.001172207 -0.001318765 0.0004112480 2.045699e-03
## [10,] -0.016167195 0.677189039 -0.728470103 -0.0951871749 3.054650e-02
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.