dfsampling <- read.csv('dataset_praktikum_sampling.csv')
head(dfsampling)
## student_id gender study_hours attendance family_income exam_score pass
## 1 1 L 4.2 70.0 50034 74.0 1
## 2 2 P 8.1 64.5 52111 76.1 1
## 3 3 P 0.1 64.3 91400 60.6 1
## 4 4 L 3.6 81.8 115892 63.5 1
## 5 5 L 3.6 77.5 81109 55.0 0
## 6 6 L 6.9 61.3 33905 78.4 1
summary(dfsampling)
## student_id gender study_hours attendance
## Min. : 1.0 Length:500 Min. : 0.000 Min. :60.10
## 1st Qu.:125.8 Class :character 1st Qu.: 4.500 1st Qu.:70.67
## Median :250.5 Mode :character Median : 6.100 Median :81.20
## Mean :250.5 Mean : 6.001 Mean :80.47
## 3rd Qu.:375.2 3rd Qu.: 7.500 3rd Qu.:90.10
## Max. :500.0 Max. :13.300 Max. :99.90
## family_income exam_score pass
## Min. : 3548 Min. : 41.50 Min. :0.000
## 1st Qu.: 22873 1st Qu.: 68.80 1st Qu.:1.000
## Median : 37014 Median : 76.10 Median :1.000
## Mean : 52631 Mean : 76.17 Mean :0.924
## 3rd Qu.: 62783 3rd Qu.: 84.15 3rd Qu.:1.000
## Max. :401401 Max. :100.00 Max. :1.000
#Histogram exam_Score
hist(dfsampling$exam_score)
#Histogram study_hours
hist(dfsampling$study_hours)
pop <- read.csv('dataset_praktikum_sampling.csv')
n <- 30
k <- 1000
mean_sample <- replicate(k, mean(sample(pop$exam_score, n, replace = TRUE)))
# Histogram distribusi sampling
hist(mean_sample)
# mean empiris distribusi sampling
mean(mean_sample)
## [1] 76.24631
# sd empiris distribusi sampling
sd(mean_sample)
## [1] 2.081489
# Perbandingan sd empiris dengan standard error teroritis
(sd(pop$exam_score) / sqrt(n))
## [1] 1.975043
n_values <- c(5, 30, 100)
par(mfrow=c(1,3))
for (n in n_values) {
means <- replicate(1000, mean(sample(dfsampling$exam_score, n, replace = TRUE)))
hist(means, main=paste('n =', n))
}
Pengaruh terhadap bentuk: Semakin besar ukuran sampel (n =5; n = 30; n=100), bentuk distribusi sampling menjadi semakin simetris dan mendekati bentuk lonceng sempurna. Hal ini sesuai dengan Teorema Limit Pusat.
Pengaruh terhadap sebaran: Semakin besar ukuran sampel (n =5; n = 30; n=100), sebarannya semakin sempit/rapat. Dibuktikan pada n=5, nilai rata-ratanya menyebar luas dari angka 60-90. Pada n=30, nilai menyempit di kisaran 70-82. Pada n=100, nilai semakin rapat dan terkonsentrasi di sekitar 73-79. Ini terjadi karena nilai standard error akan semakin kecil seiring bertambahnya ukuran sampel (n)
prop_sample <- replicate(1000, mean(rbinom(100, 1, mean(dfsampling$pass))))
hist(prop_sample)
mean(prop_sample)
## [1] 0.92495
sd(prop_sample)
## [1] 0.02634942
(p <- mean(dfsampling$pass))
## [1] 0.924
(sqrt(p*(1-p)/100))
## [1] 0.02649981
library(boot)
## Warning: package 'boot' was built under R version 4.5.3
median_fun <- function(data, indices) { median(data[indices]) }
boot_res <- boot(data=pop$exam_score, statistic=median_fun, R=2000)
boot.ci(boot_res, type='perc')
## BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
## Based on 2000 bootstrap replicates
##
## CALL :
## boot.ci(boot.out = boot_res, type = "perc")
##
## Intervals :
## Level Percentile
## 95% (75.15, 77.70 )
## Calculations and Intervals on Original Scale
# Asumsi varians berbeda (default):
t.test(exam_score ~ gender, data=dfsampling)
##
## Welch Two Sample t-test
##
## data: exam_score by gender
## t = -1.8865, df = 497.63, p-value = 0.05981
## alternative hypothesis: true difference in means between group L and group P is not equal to 0
## 95 percent confidence interval:
## -3.71700835 0.07553213
## sample estimates:
## mean in group L mean in group P
## 75.27520 77.09593
# Asumsi varians sama:
t.test(exam_score ~ gender, data=dfsampling, var.equal=TRUE)
##
## Two Sample t-test
##
## data: exam_score by gender
## t = -1.8863, df = 498, p-value = 0.05983
## alternative hypothesis: true difference in means between group L and group P is not equal to 0
## 95 percent confidence interval:
## -3.71714814 0.07567193
## sample estimates:
## mean in group L mean in group P
## 75.27520 77.09593
library(effsize)
## Warning: package 'effsize' was built under R version 4.5.3
cohen.d(dfsampling$exam_score ~ dfsampling$gender)
##
## Cohen's d
##
## d estimate: -0.168741 (negligible)
## 95 percent confidence interval:
## lower upper
## -0.344807536 0.007325481