if (!require(“corrplot”)) install.packages(“corrplot”, dependencies = TRUE)
if (!require(“ggplot2”)) install.packages(“ggplot2”, dependencies = TRUE)
library(corrplot) library(ggplot2)
mydata <- data.frame( Gender = c(1, 0, 0, 1, 1), Age = c(30.83, 58.67, 24.50, 27.83, 20.17), Debt = c(0.000, 4.460, 0.500, 1.540, 5.625), Married = c(1, 1, 1, 1, 1), BankCustomer = c(1, 1, 1, 1, 1), Industry = c(“Industrials”, “Materials”, “Materials”, “Industrials”, “Industrials”), YearsEmployed = c(1.25, 3.04, 1.50, 3.75, 1.71), PriorDefault = c(1, 1, 1, 1, 1), Employed = c(1, 1, 0, 1, 0), CreditScore = c(1, 6, 0, 5, 0), DriversLicense = c(0, 0, 0, 1, 0), Citizen = c(“ByBirth”, “ByBirth”, “ByBirth”, “ByBirth”, “ByOtherMeans”), ZipCode = c(202, 43, 280, 100, 120), Income = c(0, 560, 824, 3, 0), Approved = c(1, 1, 1, 1, 1) )
numeric_data <- mydata[sapply(mydata, is.numeric)]
var_cov_matrix <- cov(numeric_data) print(“Variance-Covariance Matrix:”) ## [1] “Variance-Covariance Matrix:” print(var_cov_matrix)
corr_matrix <- cor(numeric_data)
print(“Correlation Matrix:”)
print(corr_matrix)
corrplot(corr_matrix, method = “circle”, type = “lower”, tl.col = “black”, tl.srt = 45)
eigen_decomp <- eigen(var_cov_matrix) print(“Eigen Values:”)
print(eigen_decomp$values)
print(“Eigen Vectors:”)
print(eigen_decomp$vectors)
eigen_df <- data.frame(Index = 1:length(eigen_decomp\(values), EigenValue = eigen_decomp\)values)
ggplot(eigen_df, aes(x = Index, y = EigenValue)) + geom_bar(stat = “identity”, fill = “steelblue”) + geom_text(aes(label = round(EigenValue, 2)), vjust = -0.5) + labs(title = “Eigenvalues dari Variance-Covariance Matrix”, x = “Index”, y = “Eigenvalue”) + theme_minimal()