data <- read.csv("D:/Kuliah Semester 4/PSD/Expanded_data.csv")
head(data)
## X Gender EthnicGroup ParentEduc LunchType TestPrep
## 1 0 female bachelor's degree standard none
## 2 1 female group C some college standard
## 3 2 female group B master's degree standard none
## 4 3 male group A associate's degree free/reduced none
## 5 4 male group C some college standard none
## 6 5 female group B associate's degree standard none
## ParentMaritalStatus PracticeSport IsFirstChild NrSiblings TransportMeans
## 1 married regularly yes 3 school_bus
## 2 married sometimes yes 0
## 3 single sometimes yes 4 school_bus
## 4 married never no 1
## 5 married sometimes yes 0 school_bus
## 6 married regularly yes 1 school_bus
## WklyStudyHours MathScore ReadingScore WritingScore
## 1 < 5 71 71 74
## 2 5 - 10 69 90 88
## 3 < 5 87 93 91
## 4 5 - 10 45 56 42
## 5 5 - 10 76 78 75
## 6 5 - 10 73 84 79
str(data)
## 'data.frame': 30641 obs. of 15 variables:
## $ X : int 0 1 2 3 4 5 6 7 8 9 ...
## $ Gender : chr "female" "female" "female" "male" ...
## $ EthnicGroup : chr "" "group C" "group B" "group A" ...
## $ ParentEduc : chr "bachelor's degree" "some college" "master's degree" "associate's degree" ...
## $ LunchType : chr "standard" "standard" "standard" "free/reduced" ...
## $ TestPrep : chr "none" "" "none" "none" ...
## $ ParentMaritalStatus: chr "married" "married" "single" "married" ...
## $ PracticeSport : chr "regularly" "sometimes" "sometimes" "never" ...
## $ IsFirstChild : chr "yes" "yes" "yes" "no" ...
## $ NrSiblings : int 3 0 4 1 0 1 1 1 3 NA ...
## $ TransportMeans : chr "school_bus" "" "school_bus" "" ...
## $ WklyStudyHours : chr "< 5" "5 - 10" "< 5" "5 - 10" ...
## $ MathScore : int 71 69 87 45 76 73 85 41 65 37 ...
## $ ReadingScore : int 71 90 93 56 78 84 93 43 64 59 ...
## $ WritingScore : int 74 88 91 42 75 79 89 39 68 50 ...
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.3.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
data <- data %>%
pivot_longer(cols = c("MathScore", "ReadingScore", "WritingScore"),
names_to = "variable",
values_to = "value")
ggplot(data, aes(x = variable, y = value, fill = variable)) +
geom_boxplot() +
labs(title = "Boxplot untuk Mendeteksi Outliner ", x = "Variabel", y = "Nilai") +
theme_minimal()
Outliner adalah nilai yang jauh berbeda dari nilai lainnya dalam kumpulan data. Cara memeriksa outliner adalah bisa menggunakan boxplot, Z-score, ataupun quartile. Cara menanggulangi outliner adalah bisa dengan menghapus, mengganti atau melakukan transformasi data.
Memeriksa jam belajar manakah per minggu yang paling banyak dilakukan oleh student
library(ggplot2)
# Membaca file CSV
data <- read.csv("D:/Kuliah Semester 4/PSD/Expanded_Data.csv")
# Visualisasi bar chart
ggplot(data, aes(x = WklyStudyHours, fill = WklyStudyHours)) +
geom_bar() +
labs(title = "Distribusi Jam Belajar per Minggu",
x = "Jam Belajar per Minggu",
y = "Jumlah Siswa") +
theme_minimal()
data <- read.csv("D:/Kuliah Semester 4/PSD/Expanded_Data.csv")
data$EthnicGroup <- as.factor(data$EthnicGroup)
# Uji ANOVA untuk Math Score
anova_math <- aov(MathScore ~ EthnicGroup, data = data)
summary(anova_math)
## Df Sum Sq Mean Sq F value Pr(>F)
## EthnicGroup 5 433219 86644 390.5 <2e-16 ***
## Residuals 30635 6797185 222
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Uji ANOVA untuk Reading Score
anova_reading <- aov(ReadingScore ~ EthnicGroup, data = data)
summary(anova_reading)
## Df Sum Sq Mean Sq F value Pr(>F)
## EthnicGroup 5 151623 30325 142.4 <2e-16 ***
## Residuals 30635 6522586 213
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Uji ANOVA untuk Writing Score
anova_writing <- aov(WritingScore ~ EthnicGroup, data = data)
summary(anova_writing)
## Df Sum Sq Mean Sq F value Pr(>F)
## EthnicGroup 5 197543 39509 170.2 <2e-16 ***
## Residuals 30635 7110172 232
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Load library
library(ggplot2)
library(reshape2)
## Warning: package 'reshape2' was built under R version 4.3.3
##
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
##
## smiths
library(ggcorrplot)
## Warning: package 'ggcorrplot' was built under R version 4.3.3
# Import data
data <- read.csv("D:/Kuliah Semester 4/PSD/Expanded_Data.csv")
# Ambil hanya kolom skor
scores <- data[, c("MathScore", "ReadingScore", "WritingScore")]
corr_matrix <- cor(scores, use = "complete.obs")
print(corr_matrix)
## MathScore ReadingScore WritingScore
## MathScore 1.0000000 0.8178249 0.8071182
## ReadingScore 0.8178249 1.0000000 0.9525844
## WritingScore 0.8071182 0.9525844 1.0000000
# Visualisasi heatmap korelasi
ggcorrplot(corr_matrix,
method = "circle",
lab = TRUE, # tampilkan nilai korelasi
lab_size = 5,
title = "Correlation Heatmap of Scores",
colors = c("red", "white", "blue"),
type = "upper") # hanya tampilkan bagian atas
library(ggplot2)
data$PracticeSport <- as.factor(data$PracticeSport)
# Uji ANOVA untuk MathScore berdasarkan PracticeSport
anova_math <- aov(MathScore ~ PracticeSport, data = data)
summary(anova_math)
## Df Sum Sq Mean Sq F value Pr(>F)
## PracticeSport 3 41751 13917 59.31 <2e-16 ***
## Residuals 30637 7188652 235
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Visualisasi distribusi MathScore berdasarkan PracticeSport
ggplot(data, aes(x = PracticeSport, y = MathScore, fill = PracticeSport)) +
geom_boxplot() +
labs(title = "Perbandingan Nilai Math Berdasarkan Frekuensi Olahraga",
x = "Frekuensi Olahraga",
y = "Math Score") +
theme_minimal()