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 dataframe dari data yang tersedia
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)
)
print(data)
## Age Debt YearsEmployed Income
## 1 30.83 0.000 1.25 0
## 2 58.67 4.460 3.04 560
## 3 24.50 0.500 1.50 824
## 4 27.83 1.540 3.75 3
## 5 20.17 5.625 1.71 0
eig_result <- eigen(cov(data))
eig_result$values # Eigenvalues
## [1] 1.519855e+05 2.046288e+02 5.515401e+00 8.810774e-01
eig_result$vectors # Eigenvectors
## [,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
cor_matrix <- cor(data)
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