Tugas 3 Metode Multivariat Neo Saffana Farhalik
##Langkah 1 : Install dan load packages yang dibutuhkan
install.packages(“HSAUR3”)
install.packages(“ggplot2”)
install.packages(“factoextra”)
library(HSAUR3)
library(ggplot2)
library(factoextra)
data(“heptathlon”, package = “HSAUR3”)
##Langkah 2 : Mengekplorasi data
str(heptathlon)
heptathlon_data <- heptathlon[, -8]
head(heptathlon_data)
##Langkah 3 : Standarisasikan Data
heptathlon_scaled <- scale(heptathlon_data)
##Langkah 4 : Mengerjakan PCA
pca_result <- prcomp(heptathlon_scaled, center = TRUE, scale. = TRUE)
summary(pca_result)
##Langkah 5 : Menginterpretasikan Varians
explained_variance <- pca_result\(sdev^2 / sum(pca_result\)sdev^2)
fviz_screeplot(pca_result, addlabels = TRUE, ylim = c(0, 50))
##Langkah 6: Visualisasi Komponen Utama dengan biplot
fviz_pca_biplot(pca_result, repel = TRUE, label = “var”)
##Langkah 7: Menyimpan dokumen
quarto render your_file.qmd