membuat dataframe dengan data numerik dari tabel

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),
  Income = c(0, 560, 824, 3, 0)
)
  1. Eigen value dan eigen vector dari covariance matrix
cov_matrix <- cov(data)  # Matriks kovarians
eigen_result <- eigen(cov_matrix)  # Eigen decomposition
cat("Eigenvalues:\n")
## Eigenvalues:
print(eigen_result$values)
## [1] 1.519855e+05 2.046288e+02 5.515401e+00 8.810774e-01
cat("Eigenvectors:\n")
## Eigenvectors:
print(eigen_result$vectors)
##               [,1]        [,2]         [,3]          [,4]
## [1,] -0.0134874524  0.99771613  0.055954477 -0.0353512228
## [2,]  0.0007381111  0.05468974 -0.997847290 -0.0361838792
## [3,]  0.0002807996  0.03730694 -0.034170588  0.9987194221
## [4,] -0.9999087283 -0.01340703 -0.001500938  0.0007305969
  1. Variance-Covariance Matrix
cat("Variance-Covariance Matrix:\n")
## Variance-Covariance Matrix:
print(cov_matrix)
##                       Age        Debt YearsEmployed      Income
## Age            231.361400    9.345663      6.999375   2046.9725
## Debt             9.345663    6.187675      0.605225   -112.3137
## YearsEmployed    6.999375    0.605225      1.182050    -42.7750
## Income        2046.972500 -112.313750    -42.775000 151957.8000
  1. Correlation Matrix
cor_matrix <- cor(data)  # Matriks korelasi
cat("Correlation Matrix:\n")
## Correlation Matrix:
print(cor_matrix)
##                     Age       Debt YearsEmployed     Income
## Age           1.0000000  0.2470022     0.4232489  0.3452272
## Debt          0.2470022  1.0000000     0.2237872 -0.1158264
## YearsEmployed 0.4232489  0.2237872     1.0000000 -0.1009278
## Income        0.3452272 -0.1158264    -0.1009278  1.0000000

visualisasi correlation matrix

# Install package jika belum ada
if (!require(corrplot)) install.packages("corrplot", dependencies=TRUE)
## Loading required package: corrplot
## corrplot 0.95 loaded
# Load library
library(corrplot)

# Plot correlation matrix
corrplot(cor_matrix, method="color", type="upper",
         col=colorRampPalette(c("blue", "white", "red"))(200),
         addCoef.col="black", tl.col="black", tl.srt=45)