dataku = read.csv("C:/Users/HP/OneDrive/Documents/StudentsPerformance.csv")
head(dataku)
## gender race.ethnicity parental.level.of.education lunch
## 1 female group B bachelor's degree standard
## 2 female group C some college standard
## 3 female group B master's degree standard
## 4 male group A associate's degree free/reduced
## 5 male group C some college standard
## 6 female group B associate's degree standard
## test.preparation.course math.score reading.score writing.score
## 1 none 72 72 74
## 2 completed 69 90 88
## 3 none 90 95 93
## 4 none 47 57 44
## 5 none 76 78 75
## 6 none 71 83 78
# banyak amatan
n <- 10000
# membangkitan U(0,1)
u <- runif(n)
# fungsi inverse CDF
set.seed(10) # membuat seed
x <- -(log(1-u))
head(x)
## [1] 0.22837169 0.31346193 0.08636905 1.19647548 0.06758973 0.80173953
length(x)
## [1] 10000
set.seed(10) # membuat seed
y <- rexp(n,rate = 3)
head(y)
## [1] 0.004985469 0.306740402 0.250719646 0.525013950 0.077219539 0.362224334
length(y)
## [1] 10000
par(mfrow=c(1,2))
hist(x,main="Exp dari Inverse Transform",col="lightsalmon3")
hist(y,main="Exp dari fungsi rexp",col = "lightpink2" )
2A
#menambahkan kolom total skor
dataku$nilai.total.skor <- rowSums(dataku[6:8])
head(dataku)
## gender race.ethnicity parental.level.of.education lunch
## 1 female group B bachelor's degree standard
## 2 female group C some college standard
## 3 female group B master's degree standard
## 4 male group A associate's degree free/reduced
## 5 male group C some college standard
## 6 female group B associate's degree standard
## test.preparation.course math.score reading.score writing.score
## 1 none 72 72 74
## 2 completed 69 90 88
## 3 none 90 95 93
## 4 none 47 57 44
## 5 none 76 78 75
## 6 none 71 83 78
## nilai.total.skor
## 1 218
## 2 247
## 3 278
## 4 148
## 5 229
## 6 232
#menambahkan kolom rata rata skor
dataku$rata.rata.skor <- rowMeans(dataku[6:8])
head(dataku)
## gender race.ethnicity parental.level.of.education lunch
## 1 female group B bachelor's degree standard
## 2 female group C some college standard
## 3 female group B master's degree standard
## 4 male group A associate's degree free/reduced
## 5 male group C some college standard
## 6 female group B associate's degree standard
## test.preparation.course math.score reading.score writing.score
## 1 none 72 72 74
## 2 completed 69 90 88
## 3 none 90 95 93
## 4 none 47 57 44
## 5 none 76 78 75
## 6 none 71 83 78
## nilai.total.skor rata.rata.skor
## 1 218 72.66667
## 2 247 82.33333
## 3 278 92.66667
## 4 148 49.33333
## 5 229 76.33333
## 6 232 77.33333
2B
# Nilai Summary
summary(dataku)
## gender race.ethnicity parental.level.of.education
## Length:1000 Length:1000 Length:1000
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
## lunch test.preparation.course math.score reading.score
## Length:1000 Length:1000 Min. : 0.00 Min. : 17.00
## Class :character Class :character 1st Qu.: 57.00 1st Qu.: 59.00
## Mode :character Mode :character Median : 66.00 Median : 70.00
## Mean : 66.09 Mean : 69.17
## 3rd Qu.: 77.00 3rd Qu.: 79.00
## Max. :100.00 Max. :100.00
## writing.score nilai.total.skor rata.rata.skor
## Min. : 10.00 Min. : 27.0 Min. : 9.00
## 1st Qu.: 57.75 1st Qu.:175.0 1st Qu.: 58.33
## Median : 69.00 Median :205.0 Median : 68.33
## Mean : 68.05 Mean :203.3 Mean : 67.77
## 3rd Qu.: 79.00 3rd Qu.:233.0 3rd Qu.: 77.67
## Max. :100.00 Max. :300.0 Max. :100.00
library(e1071)
# Nilai Skewness math.score
skewness(dataku$math.score)
## [1] -0.2780989
# Nilai Skewness reading.score
skewness(dataku$reading.score)
## [1] -0.2583277
# Nilai Skewness writing.score
skewness(dataku$writing.score)
## [1] -0.2885762
# Nilai Kurtosis math.score
kurtosis(dataku$math.score)
## [1] 0.2610652
# Nilai Kurtosis reading.score
kurtosis(dataku$reading.score)
## [1] -0.07976785
# Nilai Kurtosis writing.score
kurtosis(dataku$writing.score)
## [1] -0.04511069
2C
# (i) Persentase Pie Chart Gender
gender <- table(dataku$gender)
gender
##
## female male
## 518 482
x <- c("female", "male")
percent <- round(gender/1000*100)
pie(gender, labels = paste(percent,"%"), main ="Persentase Pie Chart Gender", col = c("coral", "coral4"))
legend ("topright", c("female", "male"), cex = 0.8,
fill = c("coral", "coral4"))
# (ii) Persentase Pie Chart Race.Ethnicity
race.ethnicity <- table(dataku$race.ethnicity)
race.ethnicity
##
## group A group B group C group D group E
## 89 190 319 262 140
x <- c("Grup A", "Grup B", "Grup C", "Grup D", "Grup E")
percent <- round(race.ethnicity/1000*100)
pie(race.ethnicity, labels = paste(percent,"%"), main ="Persentase Pie Chart Race.Ethnicity", col = c("firebrick", "hotpink4","indianred3", "mediumorchid3", "skyblue4"))
legend ("topright", c("Grup A", "Grup B", "Grup C", "Grup D", "Grup E"), cex = 0.8,
fill = c("firebrick", "hotpink4","indianred3", "mediumorchid3", "skyblue4"))
# (iii) Persentase Pie Chart Parental.Level.Of.Education
parental.level.of.education <- table(dataku$parental.level.of.education)
parental.level.of.education
##
## associate's degree bachelor's degree high school master's degree
## 222 118 196 59
## some college some high school
## 226 179
x <- c("associate's degree", "bachelor's degree", "high school", "master's degree", "some college", "some high school")
percent <- round(parental.level.of.education/1000*100)
pie(parental.level.of.education, labels = paste(percent,"%"), main ="Persentase Pie Chart Parental.Level.Of.Education", col = c("lightcyan4","plum4","deepskyblue4", "orchid", "indianred4", "magenta4"))
legend ("topright", c("associate's degree", "bachelor's degree", "high school", "master's degree", "some college", "some high school"), cex = 0.8,
fill = c("lightcyan4","plum4","deepskyblue4", "orchid", "indianred4", "magenta4"))
# (iv) Persentase Pie Chart Lunch
lunch <- table(dataku$lunch)
lunch
##
## free/reduced standard
## 355 645
x <- c("free/reduced", "standard")
percent <- round(lunch/1000*100)
pie(lunch, labels = paste(percent,"%"), main ="Persentase Pie Chart Lunch", col = c("mediumvioletred","midnightblue"))
legend ("topright", c("free/reduced", "standard"), cex = 0.8,
fill = c("mediumvioletred","midnightblue"))
# (v) Persentase Pie Chart test.preparation.course
test.preparation.course <- table(dataku$test.preparation.course)
test.preparation.course
##
## completed none
## 358 642
x <- c("completed", "none")
percent <- round(test.preparation.course/1000*100)
pie(test.preparation.course, labels = paste(percent,"%"), main ="Persentase Pie Chart test.preparation.course", col = c("olivedrab","olivedrab3"))
legend ("topright", c("completed", "none"), cex = 0.8,
fill = c("olivedrab","olivedrab3"))
2D
#(i) parental.level.of.education
library(ggplot2)
rataan = aggregate(rata.rata.skor~parental.level.of.education, data=dataku, FUN = mean)
rata = rataan[ , -1]
ratarata.parental = rataan[ , -2]
ggplot(rataan, aes(x = ratarata.parental, y = rata , fill = parental.level.of.education ))+
geom_bar(stat = "identity")+
labs(title="Diagram Rata-Rata Skor Terhadap Parental Education")
#(ii) race.ethnicity
library(ggplot2)
rataan = aggregate(rata.rata.skor~race.ethnicity, data=dataku, FUN = mean)
rata = rataan[ , -1]
ratarata.raceethnicity = rataan[ , -2]
ggplot(rataan, aes(x = ratarata.raceethnicity, y = rata , fill = race.ethnicity ))+
geom_bar(stat = "identity")+
labs(title="Diagram Rata-Rata Skor Terhadap Parental Education")
2E
# (i) Parental Level dan Gender Terhadap Total Skor
library(ggplot2)
ggplot(dataku, aes(x=parental.level.of.education, y=nilai.total.skor, fill=gender))+
geom_bar(stat = "identity")+ scale_fill_manual(values=c("mistyrose3","navajowhite4"))+
labs(y="nilai total skor",
fill = "gender",
x = "parental level of education",
title = "Diagram Batang / Cluster Parental Level dan Gender Terhadap Total Skor")
# (ii) Race.Ethnicity dan Gender Terhadap Total Skor
library(ggplot2)
ggplot(dataku, aes(x=race.ethnicity, y=nilai.total.skor, fill=gender))+
geom_bar(stat = "identity")+ scale_fill_manual(values=c("darkseagreen","darkolivegreen4"))+
labs(y="nilai total skor",
fill = "gender",
x = "race.ethnicity",
title = "Diagram Batang / Cluster Race.Ethnicity dan Gender Terhadap Total Skor")
2F
library(ggplot2)
ggplot(dataku, mapping=aes(x=math.score,fill=gender))+
geom_histogram(color="black",binwidth=5)+
xlab("Mathematic Score")+
ggtitle(label="Histogram Sebaran Data Skor Matematika pada masing-masing jenis kelamin")+
scale_fill_manual(values=c("darkolivegreen3","darkseagreen3"))+
theme_dark()
2G
ggplot(dataku, mapping=aes(x=parental.level.of.education, y= math.score, fill=gender))+
geom_violin(fill="#2D2D2D", alpha=0.3, trim=F,width=1.02)+
geom_boxplot()+ labs(title="Boxplot Pada Skor Mat Terhadap Parental Education di Setiap Gender")+
coord_flip()+scale_fill_brewer(palette="RdPu")
## Warning: position_dodge requires non-overlapping x intervals
2H
pairs(~math.score + writing.score + reading.score, data = dataku, main = "Scatterplot Matrix", col = "mediumpurple3")