Anova dan Uji Tukey
Package yang digunakan
Instalasi package di R dilakukan menggunakan syntax install.packages(‘nama package’). Selanjutnya, jika sudah ter-install, kita panggil package tersebut agar dapat kita gunakan dengan menggunakan syntax: library(NamaPackage).
library(agricolae)#biasa digunakan untuk perancangan percobaan, termasuk uji Tukey, Jika belum install jangan lupa: install.packages("agricolae") Bisa juga uji Tukey dengan install.packages('multicompView')
library(car) #untuk ANOVA, Jika belum install jangan lupa: install.packages("car")
library(dplyr) #working with data frames,Jika belum install: install.packages("dplyr") atau install.packages("tidyverse")Case 1 Soal 1
1a. Uji Hipotesis There are difference in the mean GRE scores for applicants admitted to the three programs
Di sini kita menggunakan ANOVA.
#Input Data
y_c1 <- c(630,640,470,600,580,660,660,480,650,710,
660,640,720,690,530,760,670,700,710,450,
440,330,670,570,590,540,450,570,530,630)
ulangan_c1<- c(rep(c(1,2,3,4,5,6,7,8,9,10),3))
perlakuan_c1<- c(rep("Life Sciences",10),
rep("Physical Sciences",10),
rep("Social Sciences",10))
full_data_c1<- data.frame("Perlakuan_c1"= as.factor(perlakuan_c1),"Respon_c1"= y_c1,
"Ulangan_c1"=ulangan_c1)
full_data_c1## Perlakuan_c1 Respon_c1 Ulangan_c1
## 1 Life Sciences 630 1
## 2 Life Sciences 640 2
## 3 Life Sciences 470 3
## 4 Life Sciences 600 4
## 5 Life Sciences 580 5
## 6 Life Sciences 660 6
## 7 Life Sciences 660 7
## 8 Life Sciences 480 8
## 9 Life Sciences 650 9
## 10 Life Sciences 710 10
## 11 Physical Sciences 660 1
## 12 Physical Sciences 640 2
## 13 Physical Sciences 720 3
## 14 Physical Sciences 690 4
## 15 Physical Sciences 530 5
## 16 Physical Sciences 760 6
## 17 Physical Sciences 670 7
## 18 Physical Sciences 700 8
## 19 Physical Sciences 710 9
## 20 Physical Sciences 450 10
## 21 Social Sciences 440 1
## 22 Social Sciences 330 2
## 23 Social Sciences 670 3
## 24 Social Sciences 570 4
## 25 Social Sciences 590 5
## 26 Social Sciences 540 6
## 27 Social Sciences 450 7
## 28 Social Sciences 570 8
## 29 Social Sciences 530 9
## 30 Social Sciences 630 10
# Membuat Model
model_c1<- aov(Respon_c1~Perlakuan_c1, data = full_data_c1)
# ANOVA
summary(model_c1)## Df Sum Sq Mean Sq F value Pr(>F)
## Perlakuan_c1 2 74807 37403 4.47 0.021 *
## Residuals 27 225930 8368
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Karena nilai-p <0.05 maka 𝐻0 ditolak. Cukup bukti untuk menyatakan bahwa there are difference in the mean GRE scores for applicants admitted to the three programs. Artinya ada perbedaan dari nilai rata-rata GRE SCORE Ketiga graduate program tersebut.
1b. CI for the difference in the Average in mean GRE scores for Life Sciences and Physical Sciences
##Filter data untuk Life Sciences
data.LifeSciences <- full_data_c1 %>%
filter(Perlakuan_c1=="Life Sciences")
##Filter data untuk Physical Sciences
data.PhysicalSciences <- full_data_c1 %>%
filter(Perlakuan_c1=="Physical Sciences")
#CI 95% for the difference in the Average in mean GRE scores
# for Life Sciences and Physical Sciences
t.test(data.LifeSciences$Respon_c1,data.PhysicalSciences$Respon_c1,
alternative = "two.sided", conf.level = 0.95, var.equal = T)$conf.int## [1] -126.35932 36.35932
## attr(,"conf.level")
## [1] 0.95
Confidence Interval 95% for the difference in the Average in mean of normal baku data of GRE scores for Life Sciences and Physical Sciences is between -126.35932 and 36.35932. CI ini memuat nilai 0 berarti Tak Tolak Ho, kurang cukup bukti untuk menyatakan bahwa Mean of GRE scores for applicants admitted to the Physical Sciences graduate program berbeda dengan Mean of GRE scores for applicants admitted to the Life Sciences graduate program. Namun, perlu dilakukan uji lanjutan seperti Uji Tukey untuk membuktikannya.
1c. Uji Tukey
Uji Perbandingan Berganda BNJ (Beda Nyata Jujur) atau Tukey.
HSD.test(model_c1, "Perlakuan_c1",console=T) ##
## Study: model_c1 ~ "Perlakuan_c1"
##
## HSD Test for Respon_c1
##
## Mean Square Error: 8367.778
##
## Perlakuan_c1, means
##
## Respon_c1 std r Min Max
## Life Sciences 608 78.42902 10 470 710
## Physical Sciences 653 94.05081 10 450 760
## Social Sciences 532 100.53192 10 330 670
##
## Alpha: 0.05 ; DF Error: 27
## Critical Value of Studentized Range: 3.506426
##
## Minimun Significant Difference: 101.4308
##
## Treatments with the same letter are not significantly different.
##
## Respon_c1 groups
## Physical Sciences 653 a
## Life Sciences 608 ab
## Social Sciences 532 b
Dari output Tukey/BNJ di atas dapat disimpulkan bahwa pada taraf nyata 5%, kita memiliki cukup bukti untuk mengatakan bahwa antara nilai Mean GRE scores for applicants admitted to the Physical Sciences graduate program berbeda dengan Mean GRE scores for applicants admitted to the Social Sciences graduate program.
Sedangkan untuk kombinasi lainnya, uji Perbandingan Berganda BNJ (Beda Nyata Jujur) atau Tukey disimpulkan bahwa kita kurang cukup bukti untuk menyatakan bahwa:
Mean GRE scores for applicants admitted to the Physical Sciences graduate program berbeda dengan Mean GRE scores for applicants admitted to the Life Sciences graduate program.
Mean GRE scores for applicants admitted to the Life Sciences graduate program berbeda dengan Mean GRE scores for applicants admitted to the Social Sciences graduate program.
Case 1 Soal 2
Pada case 1 soal kedua ini digunakan alpha = 2.06% agar bisa dibandingkan dengan output MINITAB yang menggunakan (1-alpha) 97.94% CI.
#Input Data
y_c1.2 <- c(0.0279, 0.0276, 0.0270, 0.0275, 0.0281,
0.0268, 0.0274, 0.0267, 0.0263, 0.0267,
0.0280, 0.0279, 0.0282, 0.0278, 0.0283)
ulangan_c1.2<- c(rep(c(1,2,3,4,5),3))
perlakuan_c1.2<- c(rep(1,5),
rep(2,5),
rep(3,5))
full_data_c1.2<- data.frame("Perlakuan_c1.2"= as.factor(perlakuan_c1.2),
"Respon_c1.2"= y_c1.2,"Ulangan_c1.2"=ulangan_c1.2)
full_data_c1.2## Perlakuan_c1.2 Respon_c1.2 Ulangan_c1.2
## 1 1 0.0279 1
## 2 1 0.0276 2
## 3 1 0.0270 3
## 4 1 0.0275 4
## 5 1 0.0281 5
## 6 2 0.0268 1
## 7 2 0.0274 2
## 8 2 0.0267 3
## 9 2 0.0263 4
## 10 2 0.0267 5
## 11 3 0.0280 1
## 12 3 0.0279 2
## 13 3 0.0282 3
## 14 3 0.0278 4
## 15 3 0.0283 5
# Membuat Model
model_c1.2<- aov(Respon_c1.2~Perlakuan_c1.2, data = full_data_c1.2)
# Anova
summary(model_c1.2,alpha = 0.0206)## Df Sum Sq Mean Sq F value Pr(>F)
## Perlakuan_c1.2 2 4.116e-06 2.058e-06 16.38 0.000372 ***
## Residuals 12 1.508e-06 1.257e-07
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Berdasarkan hasil di atas didapatkan nilai p_value = 0.000372 < alpha = 0.0206 yang berarti Tolak Ho. Cukup bukti untuk menyatakan bahwa three methods of measurement berpengaruh terhadap the calcium content of a powdered mineral substance.
Uji Perbandingan Berganda BNJ (Beda Nyata Jujur) atau Tukey.
Digunakan alpha = 2.06% agar bisa dibandingkan dengan output MINITAB yang menggunakan (1-alpha)97.94% CI.
HSD.test(model_c1.2, "Perlakuan_c1.2",alpha = 0.0206, console=T) ##
## Study: model_c1.2 ~ "Perlakuan_c1.2"
##
## HSD Test for Respon_c1.2
##
## Mean Square Error: 1.256667e-07
##
## Perlakuan_c1.2, means
##
## Respon_c1.2 std r Min Max
## 1 0.02762 0.0004207137 5 0.0270 0.0281
## 2 0.02678 0.0003962323 5 0.0263 0.0274
## 3 0.02804 0.0002073644 5 0.0278 0.0283
##
## Alpha: 0.0206 ; DF Error: 12
## Critical Value of Studentized Range: 4.476856
##
## Minimun Significant Difference: 0.0007097381
##
## Treatments with the same letter are not significantly different.
##
## Respon_c1.2 groups
## 3 0.02804 a
## 1 0.02762 a
## 2 0.02678 b
Dari output BNJ di atas dapat disimpulkan bahwa pada taraf nyata 2.06%, cukup bukti untuk menyatakan bahwa:
nilai tengah the calcium content of a powdered mineral substance untuk metode 3 berbeda dengan nilai tengah the calcium content of a powdered mineral substance untuk metode 2.
nilai tengah the calcium content of a powdered mineral substance untuk metode 1 berbeda dengan nilai tengah the calcium content of a powdered mineral substance untuk metode 2.
Sedangkan kita tidak cukup bukti untuk menyatakan nilai tengah the calcium content of a powdered mineral substance untuk metode 3 berbeda dengan nilai tengah the calcium content of a powdered mineral substance untuk metode 1.
Jika dibandingkan dengan output minitab di bawah ini, hasilnya sama. Dimana selang kepercayaan selisih nilai tengah the calcium content of a powdered mineral substance untuk metode 3 dan metode 1 melewati nilai 0 yang berarti tidak tolak Ho, kita tidak cukup bukti untuk menyatakan nilai tengah the calcium content of a powdered mineral substance untuk metode 3 berbeda dengan nilai tengah the calcium content of a powdered mineral substance untuk metode 1.
Sedangkan selang kepercayaan selisih nilai tengah the calcium content of a powdered mineral substance untuk metode 3 dan metode 2 tidak melewati nilai 0 serta metode 1 dan 2 juga tidak melewati nilai 0 yang berarti tolak Ho, kita cukup bukti untuk menyatakan nilai tengah the calcium content of a powdered mineral substance untuk metode 3 berbeda dengan nilai tengah the calcium content of a powdered mineral substance untuk metode 1 serta nilai tengah the calcium content of a powdered mineral substance untuk metode 1 berbeda dengan nilai tengah the calcium content of a powdered mineral substance untuk metode 2.
Case 2
2a. Pengujian Hipotesis Persentase Berat Katun Berpengaruh terhadap Kekuatan Bahan
#Input Data
y <- c(7,7,15,11,9,
12,17,12,18,
14, 18, 18, 19, 19,
19, 25, 22, 19, 23,
7, 10, 11,15)
ulangan<- c(c(1,2,3,4,5),
c(1,2,3,4),
rep(c(1,2,3,4,5),2),
c(1,2,3,4))
perlakuan<- c(rep(15,5),
rep(20,4),
rep(25,5),
rep(30,5),
rep(35,4))
full_data<- data.frame("Perlakuan"= as.factor(perlakuan),"Respon"= y,
"Ulangan"=ulangan)
full_data## Perlakuan Respon Ulangan
## 1 15 7 1
## 2 15 7 2
## 3 15 15 3
## 4 15 11 4
## 5 15 9 5
## 6 20 12 1
## 7 20 17 2
## 8 20 12 3
## 9 20 18 4
## 10 25 14 1
## 11 25 18 2
## 12 25 18 3
## 13 25 19 4
## 14 25 19 5
## 15 30 19 1
## 16 30 25 2
## 17 30 22 3
## 18 30 19 4
## 19 30 23 5
## 20 35 7 1
## 21 35 10 2
## 22 35 11 3
## 23 35 15 4
Pengujian Hipotesis Persentase Berat Katun Berpengaruh terhadap Kekuatan Bahan
# Membuat Model
model<- aov(Respon~Perlakuan, data = full_data)
# Anova
summary(model)## Df Sum Sq Mean Sq F value Pr(>F)
## Perlakuan 4 459.1 114.78 13.53 2.91e-05 ***
## Residuals 18 152.7 8.48
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Berdasarkan hasil di atas didapatkan nilai p_value = 2.91e-05 < alpha = 0.05 yang berarti Tolak Ho. Cukup bukti untuk menyatakan bahwa persentase berat katun berpengaruh terhadap kekuatan bahan.
2b. Uji Perbandingan Berganda BNJ
Uji Perbandingan Berganda BNJ (Beda Nyata Jujur) atau Tukey.
HSD.test(model, "Perlakuan",console=T) ##
## Study: model ~ "Perlakuan"
##
## HSD Test for Respon
##
## Mean Square Error: 8.483333
##
## Perlakuan, means
##
## Respon std r Min Max
## 15 9.80 3.346640 5 7 15
## 20 14.75 3.201562 4 12 18
## 25 17.60 2.073644 5 14 19
## 30 21.60 2.607681 5 19 25
## 35 10.75 3.304038 4 7 15
##
## Alpha: 0.05 ; DF Error: 18
## Critical Value of Studentized Range: 4.276293
##
## Groups according to probability of means differences and alpha level( 0.05 )
##
## Treatments with the same letter are not significantly different.
##
## Respon groups
## 30 21.60 a
## 25 17.60 ab
## 20 14.75 bc
## 35 10.75 c
## 15 9.80 c
Dari output BNJ di atas dapat disimpulkan bahwa pada taraf nyata 5%, kurang cukup bukti untuk menyatakan bahwa:
nilai tengah kekuatan bahan untuk tingkat persentase berat katun 30 berbeda dengan nilai tengah kekuatan bahan untuk tingkat persentase berat katun 25.
nilai tengah kekuatan bahan untuk tingkat persentase berat katun 25 berbeda dengan nilai tengah kekuatan bahan persentase berat katun 20.
nilai tengah kekuatan bahan untuk tingkat persentase berat katun 20 berbeda dengan nilai tengah kekuatan bahan untuk tingkat persentase berat katun 35 dan 15. Nilai tengah kekuatan bahan untuk tingkat persentase berat katun 35 juga berbeda dengan nilai tengah kekuatan bahan 15.
Sedangkan untuk kombinasi lainnya dapat dikatakan bahwa cukup bukti untuk mengatakan bahwa nilai tengah kekuatan bahan kombinasi tingkat persentase berat katun lainnya selain yang disebutkan di atas adalah berbeda.
Mahasiswa Pascasarjana Statistika dan Sains Data, IPB University, reniamelia@apps.ipb.ac.id↩︎