Tugas Rancob - Uji Dunnet

Unduh sebagai pdf atau txt
Unduh sebagai pdf atau txt
Anda di halaman 1dari 4

Ica Kartika Cahyani

1914191009
Proteksi Tanaman
Uji Dunnet

> # Selalu awali dengan membersihkan memori R Studio dan mengetahui


> # folder kerja yang ada :
> rm(list=ls()) # membersihkan memori R Studio
> getwd() # memeriksa folder kerja saat ini
[1] "C:/Users/Ica Kartika Cahyani/OneDrive/Dokumen"
> # Create data frame
> dataku <-
+ data.frame(Metode =
+ rep(c("Metode_Lama", "Metode_Baru_1", "Metode_Baru_2"), each = 10),
+ Nilai = c(76, 77, 77, 81, 82, 82, 83, 84, 85, 89,
+ 81, 82, 83, 83, 83, 84, 87, 90, 92, 93,
+ 77, 78, 79, 88, 89, 90, 91, 95, 95, 98))
> head(dataku)
Metode Nilai
1 Metode_Lama 76
2 Metode_Lama 77
3 Metode_Lama 77
4 Metode_Lama 81
5 Metode_Lama 82
6 Metode_Lama 82
> dataku
Metode Nilai
1 Metode_Lama 76
2 Metode_Lama 77
3 Metode_Lama 77
4 Metode_Lama 81
5 Metode_Lama 82
6 Metode_Lama 82
7 Metode_Lama 83
8 Metode_Lama 84
9 Metode_Lama 85
10 Metode_Lama 89
11 Metode_Baru_1 81
12 Metode_Baru_1 82
13 Metode_Baru_1 83
14 Metode_Baru_1 83
15 Metode_Baru_1 83
16 Metode_Baru_1 84
17 Metode_Baru_1 87
18 Metode_Baru_1 90
19 Metode_Baru_1 92
20 Metode_Baru_1 93
21 Metode_Baru_2 77
22 Metode_Baru_2 78
23 Metode_Baru_2 79
24 Metode_Baru_2 88
25 Metode_Baru_2 89
26 Metode_Baru_2 90
27 Metode_Baru_2 91
28 Metode_Baru_2 95
29 Metode_Baru_2 95
30 Metode_Baru_2 98
> str(dataku)
'data.frame': 30 obs. of 2 variables:
$ Metode: chr "Metode_Lama" "Metode_Lama" "Metode_Lama" "Metode_Lama" ...
$ Nilai : num 76 77 77 81 82 82 83 84 85 89 ...
> boxplot(Nilai ~ Metode,
+ main = "HASIL UJIAN BERDASARKAN METODE PENGAJARAN",
+ xlab = "METODE PENGAJARAN",
+ ylab = "NILAI HASIL UJIAN",
+ col = "steelblue",
+ border = "black",
+ data = dataku)
> #fit the one-way ANOVA model
> model <- aov(Nilai ~ Metode, data = dataku)
> #view model output
> summary(model)
Df Sum Sq Mean Sq F value Pr(>F)
Metode 2 211.5 105.73 3.415 0.0476 *
Residuals 27 836.0 30.96
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> #load DescTools library
> #if(!require(dplyr)){install.packages("DescTools")}
> library(DescTools)
> str(dataku) # Sekali lagi memeriksa struktur data
'data.frame': 30 obs. of 2 variables:
$ Metode: chr "Metode_Lama" "Metode_Lama" "Metode_Lama" "Metode_Lama" ...
$ Nilai : num 76 77 77 81 82 82 83 84 85 89 ...
> # Variabel Metode harus diubah menjadi faktor agar tidak error
> dataku$Metode = as.factor(dataku$Metode)
> str(dataku) # Perhatikan sekarang Metode telah menjadi faktor
'data.frame': 30 obs. of 2 variables:
$ Metode: Factor w/ 3 levels "Metode_Baru_1",..: 3 3 3 3 3 3 3 3 3 3 ...
$ Nilai : num 76 77 77 81 82 82 83 84 85 89 ...
> # Perform Dunnett's Test
> DunnettTest(x=dataku$Nilai, g=dataku$Metode)

Dunnett's test for comparing several treatments with a control :


95% family-wise confidence level

$Metode_Baru_1
diff lwr.ci upr.ci
Metode_Baru_2-Metode_Baru_1 2.2 -3.607188 8.007188
Metode_Lama-Metode_Baru_1 -4.2 -10.007188 1.607188
pval
Metode_Baru_2-Metode_Baru_1 0.5863
Metode_Lama-Metode_Baru_1 0.1787

---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

> ##############################################
> # Uji Dunnett bisa juga menggunakan script berikut ini:
> dunnet_HS <- DunnettTest(Nilai ~ Metode,
+ control = "Metode_Lama",
+ data = dataku)
> dunnet_HS

Dunnett's test for comparing several treatments with a control :


95% family-wise confidence level

$Metode_Lama
diff lwr.ci upr.ci pval
Metode_Baru_1-Metode_Lama 4.2 -1.6071876 10.00719 0.1787
Metode_Baru_2-Metode_Lama 6.4 0.5928124 12.20719 0.0296

Metode_Baru_1-Metode_Lama
Metode_Baru_2-Metode_Lama *
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

>
>
>
>
>
> # The mean difference in exam scores between the new studying technique 1
>
> # The mean difference in exam scores between the new studying technique 2
>
> # Based on the output, we can see that studying technique 2 is the only
> # Based on the output, we can see that studying technique 2 is the only
> # technique that produces significantly (p = .0296) different mean

Anda mungkin juga menyukai