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),
Income = c(0, 560, 824, 3, 0)
)
print(data)
## Age Debt YearsEmployed CreditScore Income
## 1 30.83 0.000 1.25 1 0
## 2 58.67 4.460 3.04 6 560
## 3 24.50 0.500 1.50 0 824
## 4 27.83 1.540 3.75 5 3
## 5 20.17 5.625 1.71 0 0
numeric_data <- as.matrix(data)
# Hapus kolom dengan varians nol
numeric_data <- numeric_data[, apply(numeric_data, 2, var) > 0]
cor_matrix <- cor(numeric_data, use = "complete.obs")
eigen_results <- eigen(cor_matrix)
cat("Eigenvalues:\n")
## Eigenvalues:
print(eigen_results$values)
## [1] 2.504890e+00 1.216205e+00 8.937056e-01 3.851986e-01 2.201328e-16
cat("\nEigenvectors:\n")
##
## Eigenvectors:
print(eigen_results$vectors)
## [,1] [,2] [,3] [,4] [,5]
## [1,] -0.5173164 0.3435734 -0.1580531 -0.65202271 -0.40524882
## [2,] -0.2366539 -0.3405399 -0.8896621 0.17132470 0.08471519
## [3,] -0.5423918 -0.2393841 0.2932737 0.55001181 -0.50988619
## [4,] -0.6144324 -0.0402371 0.2391578 -0.05696149 0.74860716
## [5,] -0.0682825 0.8408722 -0.2007850 0.48964950 0.09055450
cov_matrix <- cov(numeric_data, use = "complete.obs")
cat("\nVariance-Covariance Matrix:\n")
##
## Variance-Covariance Matrix:
print(cov_matrix)
## Age Debt YearsEmployed CreditScore Income
## Age 231.361400 9.345663 6.999375 33.30 2046.9725
## Debt 9.345663 6.187675 0.605225 1.34 -112.3137
## YearsEmployed 6.999375 0.605225 1.182050 2.81 -42.7750
## CreditScore 33.300000 1.340000 2.810000 8.30 11.5500
## Income 2046.972500 -112.313750 -42.775000 11.55 151957.8000
cat("\nCorrelation Matrix:\n")
##
## Correlation Matrix:
print(cor_matrix)
## Age Debt YearsEmployed CreditScore Income
## Age 1.0000000 0.2470022 0.4232489 0.75990576 0.34522724
## Debt 0.2470022 1.0000000 0.2237872 0.18698295 -0.11582643
## YearsEmployed 0.4232489 0.2237872 1.0000000 0.89711754 -0.10092775
## CreditScore 0.7599058 0.1869829 0.8971175 1.00000000 0.01028446
## Income 0.3452272 -0.1158264 -0.1009278 0.01028446 1.00000000
Setelah mendapatkan file HTML, lakukan langkah berikut: