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:
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
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.
# Install dan panggil library yang dibutuhkan
if (!requireNamespace("readr", quietly = TRUE)) install.packages("readr")
if (!requireNamespace("dplyr", quietly = TRUE)) install.packages("dplyr")
if (!requireNamespace("knitr", quietly = TRUE)) install.packages("knitr")
library(readr)
library(dplyr)
library(knitr)
# Membaca file CSV dan memilih kolom numerik
data_numeric <- read_csv("data rumah.csv") |>
select(where(is.numeric))
# Menghitung eigen values dan eigen vectors dari matriks kovarians
cov_matrix <- cov(data_numeric)
eig <- eigen(cov_matrix)
# Menampilkan hasil dalam format tabel
cat("### Eigenvalues\n")
## ### Eigenvalues
kable(as.data.frame(eig$values), col.names = "Eigenvalues")
| Eigenvalues |
|---|
| 3.498546e+12 |
| 3.356500e+06 |
| 7.345801e-01 |
| 5.958731e-01 |
| 3.626262e-01 |
| 1.677009e-01 |
cat("### Eigenvectors\n")
## ### Eigenvectors
kable(as.data.frame(eig$vectors))
| V1 | V2 | V3 | V4 | V5 | V6 |
|---|---|---|---|---|---|
| 0.9999998 | 0.0006219 | 0.0000002 | 0.0000002 | 0.0000000 | 0.0000001 |
| 0.0006219 | -0.9999998 | -0.0001068 | 0.0000469 | 0.0000123 | -0.0000207 |
| 0.0000001 | 0.0000213 | -0.4831235 | -0.3524835 | -0.7742078 | 0.2072422 |
| 0.0000001 | 0.0000272 | -0.1156247 | -0.0741885 | -0.1559105 | -0.9781712 |
| 0.0000002 | 0.0000794 | -0.7760615 | -0.2230034 | 0.5897316 | 0.0146506 |
| 0.0000002 | -0.0000819 | 0.3885243 | -0.9058261 | 0.1688515 | -0.0041371 |
cat("### Variance-Covariance Matrix\n")
## ### Variance-Covariance Matrix
kable(as.data.frame(cov_matrix))
| price | area | bedrooms | bathrooms | stories | parking | |
|---|---|---|---|---|---|---|
| price | 3.498544e+12 | 2.175676e+09 | 5.059464e+05 | 4.864093e+05 | 6.826446e+05 | 6.194673e+05 |
| area | 2.175676e+09 | 4.709512e+06 | 2.432321e+02 | 2.113466e+02 | 1.581294e+02 | 6.599897e+02 |
| bedrooms | 5.059464e+05 | 2.432321e+02 | 5.447383e-01 | 1.386738e-01 | 2.615893e-01 | 8.856250e-02 |
| bathrooms | 4.864093e+05 | 2.113466e+02 | 1.386738e-01 | 2.524757e-01 | 1.421715e-01 | 7.684160e-02 |
| stories | 6.826446e+05 | 1.581294e+02 | 2.615893e-01 | 1.421715e-01 | 7.525432e-01 | 3.404280e-02 |
| parking | 6.194673e+05 | 6.599897e+02 | 8.856250e-02 | 7.684160e-02 | 3.404280e-02 | 7.423300e-01 |
cat("### Correlation Matrix\n")
## ### Correlation Matrix
kable(as.data.frame(cor(data_numeric)))
| price | area | bedrooms | bathrooms | stories | parking | |
|---|---|---|---|---|---|---|
| price | 1.0000000 | 0.5359973 | 0.3664940 | 0.5175453 | 0.4207124 | 0.3843936 |
| area | 0.5359973 | 1.0000000 | 0.1518585 | 0.1938195 | 0.0839961 | 0.3529805 |
| bedrooms | 0.3664940 | 0.1518585 | 1.0000000 | 0.3739302 | 0.4085642 | 0.1392699 |
| bathrooms | 0.5175453 | 0.1938195 | 0.3739302 | 1.0000000 | 0.3261647 | 0.1774958 |
| stories | 0.4207124 | 0.0839961 | 0.4085642 | 0.3261647 | 1.0000000 | 0.0455471 |
| parking | 0.3843936 | 0.3529805 | 0.1392699 | 0.1774958 | 0.0455471 | 1.0000000 |