# Menggunakan fungsi cor.test untuk menghitung Tau-Kendallcor.test(dataku$X, dataku$Y, method ="kendall")
Kendall's rank correlation tau
data: dataku$X and dataku$Y
z = 1.7529, p-value = 0.07962
alternative hypothesis: true tau is not equal to 0
sample estimates:
tau
0.4273658
# Menggunakan fungsi cor.test untuk menghitung korelasi Spearmancor.test(dataku$X, dataku$Y, method ="spearman")
Spearman's rank correlation rho
data: dataku$X and dataku$Y
S = 108.98, p-value = 0.1134
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
0.5046513
2.1.1 Chi-Square Test
# Membuat data contoh# Data asli dalam bentuk tabel silangfrekuensi <-matrix(c(30, 21, 30, 19, 15, 35), nrow =2)rownames(frekuensi) <-c("Kontrak", "Tetap")colnames(frekuensi) <-c("Rendah", "Sedang", "Tinggi")# Inisiasi vektor kosong untuk menyimpan dataStatus_Pegawai <-c()Tingkat_Produktivitas <-c()# Mengulang setiap kombinasi sesuai dengan frekuensinyafor (i in1:nrow(frekuensi)) {for (j in1:ncol(frekuensi)) { Status_Pegawai <-c(Status_Pegawai, rep(rownames(frekuensi)[i], frekuensi[i, j])) Tingkat_Produktivitas <-c(Tingkat_Produktivitas, rep(colnames(frekuensi)[j], frekuensi[i, j])) }}# Membuat dataframedataku2 <-data.frame(Status_Pegawai, Tingkat_Produktivitas)# Menampilkan datahead(dataku2)
Status_Pegawai Tingkat_Produktivitas
1 Kontrak Rendah
2 Kontrak Rendah
3 Kontrak Rendah
4 Kontrak Rendah
5 Kontrak Rendah
6 Kontrak Rendah
# Membuat data contoh# Vektor data untuk efisiensi pada skala besar dan kecilefisiensi_besar <-c(1.31, 1.25, 1.32, 1.3, 1.33, 1.31, 1.35, 1.34, 0.28, 1.34, 1.28)efisiensi_kecil <-c(1.21, 1.28, 1.32, 1.25, 1.27, 1.31, 1.26, 1.31, 1.24, 1.22)
wilcox.test(efisiensi_besar, efisiensi_kecil)
Wilcoxon rank sum test with continuity correction
data: efisiensi_besar and efisiensi_kecil
W = 82.5, p-value = 0.05614
alternative hypothesis: true location shift is not equal to 0
2.2.1.2 Chi-Square Test
2.2.2 More than two sample test (Independent)
2.2.2.1 Kruskal-Wallis Test
# Membuat data contoh# Membuat vektor untuk Industri A, B, dan Cindustri_A <-c(2.33, 2.79, 3.01, 2.33, 1.22, 2.79, 1.9, 1.65)industri_B <-c(2.33, 2.33, 2.79, 3.01, 1.99, 2.45)industri_C <-c(1.06, 1.37, 1.09, 1.65, 1.44, 1.11) # Membuat vektor industriindustri <-c(rep("Industri A", length(industri_A)), rep("Industri B", length(industri_B)), rep("Industri C", length(industri_C)))# Menggabungkan semua vektor valuenilai <-c(industri_A, industri_B, industri_C)# Membuat data framedataku4 <-data.frame(industri, nilai)# Menampilkan data framedataku4$industri <-as.factor(dataku4$industri)dataku4
industri nilai
1 Industri A 2.33
2 Industri A 2.79
3 Industri A 3.01
4 Industri A 2.33
5 Industri A 1.22
6 Industri A 2.79
7 Industri A 1.90
8 Industri A 1.65
9 Industri B 2.33
10 Industri B 2.33
11 Industri B 2.79
12 Industri B 3.01
13 Industri B 1.99
14 Industri B 2.45
15 Industri C 1.06
16 Industri C 1.37
17 Industri C 1.09
18 Industri C 1.65
19 Industri C 1.44
20 Industri C 1.11
# Uji kruskal walliskruskal.test(nilai ~ industri, data = dataku4)
Kruskal-Wallis rank sum test
data: nilai by industri
Kruskal-Wallis chi-squared = 10.619, df = 2, p-value = 0.004943
# Post hoc kruskal-wallis - Uji Dun#installed.packages("FSA")library(FSA)dunnTest(nilai ~ industri, data = dataku4)
Comparison Z P.unadj P.adj
1 Industri A - Industri B -0.6428883 0.520296550 0.52029655
2 Industri A - Industri C 2.6109139 0.009030062 0.01806012
3 Industri B - Industri C 3.0436533 0.002337243 0.00701173
2.2.2.2 Chi-Square Test
2.2.3 Two sample test (Dependent)
2.2.3.1 Sign Test
# Membuat data contoh# Data Skor Kepuasanproduk_lama <-c(16, 15, 18, 16, 17, 18, 20, 15, 14, 16, 19, 17)produk_baru <-c(18, 17, 16, 19, 17, 20, 18, 16, 15, 18, 20, 18)# Data Respondenresponden <-c(1:12)# Membuat data framedataku5 <-data.frame(Responden =c(rep(responden, 2)),Produk =factor(c(rep("Produk Lama", length(produk_lama)), rep("Produk Baru", length(produk_baru)))),Skor_Kepuasan =c(produk_lama, produk_baru))# Menampilkan data framedataku5
Responden Produk Skor_Kepuasan
1 1 Produk Lama 16
2 2 Produk Lama 15
3 3 Produk Lama 18
4 4 Produk Lama 16
5 5 Produk Lama 17
6 6 Produk Lama 18
7 7 Produk Lama 20
8 8 Produk Lama 15
9 9 Produk Lama 14
10 10 Produk Lama 16
11 11 Produk Lama 19
12 12 Produk Lama 17
13 1 Produk Baru 18
14 2 Produk Baru 17
15 3 Produk Baru 16
16 4 Produk Baru 19
17 5 Produk Baru 17
18 6 Produk Baru 20
19 7 Produk Baru 18
20 8 Produk Baru 16
21 9 Produk Baru 15
22 10 Produk Baru 18
23 11 Produk Baru 20
24 12 Produk Baru 18
# Menghitung perbedaandiff <- dataku5[dataku5$Produk =='Produk Baru', ]$Skor_Kepuasan - dataku5[dataku5$Produk =='Produk Lama', ]$Skor_Kepuasan# Menghitung jumlah perbedaan yang positifjumlah_positif <-sum(diff >0)
# Melakukan uji tandabinom.test(jumlah_positif, length(diff), p =0.5, alternative ="two.sided")
Exact binomial test
data: jumlah_positif and length(diff)
number of successes = 9, number of trials = 12, p-value = 0.146
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
0.4281415 0.9451394
sample estimates:
probability of success
0.75
# Membuat data contohdataku6 <-matrix(c(1.24,1.50,1.62,1.71,1.85,2.05,1.37,2.12,1.68,2.53,1.87,2.62,1.23,1.34,1.51,1.94,2.33,2.86,1.72,1.43,2.86), nrow =7, byrow =TRUE,dimnames =list(Person=as.character(1:7),Obat =c("Obat A","Obat B","Obat C")))dataku6
Obat
Person Obat A Obat B Obat C
1 1.24 1.50 1.62
2 1.71 1.85 2.05
3 1.37 2.12 1.68
4 2.53 1.87 2.62
5 1.23 1.34 1.51
6 1.94 2.33 2.86
7 1.72 1.43 2.86
friedman.test(dataku6)
Friedman rank sum test
data: dataku6
Friedman chi-squared = 8.8571, df = 2, p-value = 0.01193
2.2.4.2 Cochran Test
# Membuat data contoh## Input dataresponden <-c(1:8)produk_A <-c("Tidak","Tidak","Ya","Ya","Ya","Tidak","Tidak","Tidak")produk_B <-c("Tidak","Ya","Ya","Ya","Tidak","Tidak","Ya","Tidak")produk_C <-c("Ya","Tidak","Tidak","Ya","Tidak","Ya","Ya","Tidak")dataku7 <-data.frame(responden, produk_A, produk_B, produk_C)dataku7$produk_A <-as.factor(dataku7$produk_A)dataku7$produk_B <-as.factor(dataku7$produk_B)dataku7$produk_C <-as.factor(dataku7$produk_C)dataku7
responden produk_A produk_B produk_C
1 1 Tidak Tidak Ya
2 2 Tidak Ya Tidak
3 3 Ya Ya Tidak
4 4 Ya Ya Ya
5 5 Ya Tidak Tidak
6 6 Tidak Tidak Ya
7 7 Tidak Ya Ya
8 8 Tidak Tidak Tidak
Cochran's Q Test
H0: There is no difference in the effectiveness of treatments.
HA: There is a difference in the effectiveness of treatments.
Q = 0.333333333333333
Degrees of Freedom = 2
Significance Level = 0.05
The p-value is 0.846481724890614