R Markdown

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:

# Membuat Data Frame dari data numerik
data <- data.frame(
  Age = c(30.83, 58.67, 24.50, 27.83, 20.17),
  Debt = c(0.000, 4.460, 0.500, 1.540, 5.625),
  YearsEmployed = c(1.25, 3.04, 1.50, 3.75, 1.71),
  CreditScore = c(1, 6, 0, 5, 0),
  ZipCode = c(202, 43, 280, 100, 120),
  Income = c(0, 560, 824, 3, 0)
)

print(data)
##     Age  Debt YearsEmployed CreditScore ZipCode Income
## 1 30.83 0.000          1.25           1     202      0
## 2 58.67 4.460          3.04           6      43    560
## 3 24.50 0.500          1.50           0     280    824
## 4 27.83 1.540          3.75           5     100      3
## 5 20.17 5.625          1.71           0     120      0
# 1. Menghitung Eigenvalue dan Eigenvector
#Menggunakan eigen() untuk mendapatkan nilai eigen (eigenvalues) dan vektor eigen (eigenvectors) dari matriks kovarians.cov(data) menghitung matriks kovarians dari dataset. eigen() menghitung eigenvalues dan eigenvectors dari matriks kovarians.

eigen_result <- eigen(cov(data))

print("Eigenvalues:")
## [1] "Eigenvalues:"
print(eigen_result$values)
## [1] 1.529991e+05 7.738258e+03 7.494804e+01 4.551851e+00 4.419579e-12
## [6] 3.114202e-13
print("Eigenvectors:")
## [1] "Eigenvectors:"
print(eigen_result$vectors)
##               [,1]         [,2]        [,3]         [,4]         [,5]
## [1,] -1.289707e-02 -0.131560133  0.97942701  0.134315337 -0.072164510
## [2,]  8.188149e-04 -0.019605573 -0.12793653  0.643339225 -0.503369496
## [3,]  3.179438e-04 -0.009024801 -0.01847413 -0.334972014 -0.857800240
## [4,]  3.494977e-05 -0.027135529  0.08386896 -0.675118146 -0.068810738
## [5,] -8.349361e-02  0.987380472  0.12816503  0.008883966 -0.029121428
## [6,] -9.964245e-01 -0.081052896 -0.02352452 -0.002084805  0.002684459
##              [,6]
## [1,]  0.000000000
## [2,] -0.562121863
## [3,]  0.389293791
## [4,] -0.729184634
## [5,] -0.027483850
## [6,]  0.001939676
# 2. Menghitung Variance-Covariance Matrix
#Mengguunakan fungsi cov() untuk menghitung matriks varians-kovarians. Matriks kovarians menunjukkan seberapa besar variabel dalam dataset berkorelasi satu sama lain.

cov_matrix <- cov(data)

print("Variance-Covariance Matrix:")
## [1] "Variance-Covariance Matrix:"
print(cov_matrix)
##                       Age        Debt YearsEmployed CreditScore    ZipCode
## Age            231.361400    9.345663      6.999375       33.30  -831.0325
## Debt             9.345663    6.187675      0.605225        1.34  -161.4613
## YearsEmployed    6.999375    0.605225      1.182050        2.81   -73.2075
## CreditScore     33.300000    1.340000      2.810000        8.30  -207.0000
## ZipCode       -831.032500 -161.461250    -73.207500     -207.00  8612.0000
## Income        2046.972500 -112.313750    -42.775000       11.55 12109.2500
##                    Income
## Age             2046.9725
## Debt            -112.3137
## YearsEmployed    -42.7750
## CreditScore       11.5500
## ZipCode        12109.2500
## Income        151957.8000
# 3. Menghitung Correlation Matrix
#Mengguunakan fungsi cor() untuk menghitung matriks korelasi. Korelasi menunjukkan hubungan antara variabel dalam skala -1 hingga 1.

cor_matrix <- cor(data)

print("Correlation Matrix:")
## [1] "Correlation Matrix:"
print(cor_matrix)
##                      Age       Debt YearsEmployed CreditScore    ZipCode
## Age            1.0000000  0.2470022     0.4232489  0.75990576 -0.5887359
## Debt           0.2470022  1.0000000     0.2237872  0.18698295 -0.6994434
## YearsEmployed  0.4232489  0.2237872     1.0000000  0.89711754 -0.7255806
## CreditScore    0.7599058  0.1869829     0.8971175  1.00000000 -0.7742466
## ZipCode       -0.5887359 -0.6994434    -0.7255806 -0.77424657  1.0000000
## Income         0.3452272 -0.1158264    -0.1009278  0.01028446  0.3347370
##                    Income
## Age            0.34522724
## Debt          -0.11582643
## YearsEmployed -0.10092775
## CreditScore    0.01028446
## ZipCode        0.33473701
## Income         1.00000000
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

Including Plots

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.