Latihan Statistik Chi-Square dan Non Parametrik
Latihan Statistika Uji Chi-Square dan Non Parametrik
Soal dan Jawaban
Gunakan data berikut: Jumlah kelahiran per hari selama satu minggu (345, 370, 360, 342, 356, 330, 310). Uji apakah distribusinya seragam.
{# Frekuensi observasi observed <- c(345, 370, 360, 342, 356, 330, 310)# Uji chi-square dengan asumsi distribusi seragam chisq.test(x = observed, p = rep(1/length(observed), length(observed)))}Chi-squared test for given probabilities data: observed X-squared = 7.0477, df = 6, p-value = 0.3165 Nilai P-Value, >0.05, Gagal menolak Ho, Tidak ada bukti yang menyatakan bahwa distribusi jumlah kelahiran merata.Jumlah pemilih yang memilih 4 kandidat: A (260), B (240), C (300), D (200). Apakah pilihan pemilih merata?
{# Frekuensi observasi observed <- c(260, 240,300,200)# Uji chi-square dengan asumsi distribusi merata chisq.test(x = observed, p = rep(1/length(observed), length(observed))}Chi-squared test for given probabilities data: observed X-squared = 20.8, df = 3, p-value = 0.0001158 P-Value <0.05, Ho Ditolak, ada bukti yang cukup kuat bahwa distribusi jumlah pilihan tidak rata.Distribusi warna mobil di kampus: Hitam (90), Putih (60), Abu-abu (50), Merah (40). Apakah ada preferensi warna yang signifikan?
{# Frekuensi observasi observed <- c(90, 60, 50, 40)# Uji chi-square dengan asumsi distribusi signifikanchisq.test(x = observed, p = rep(1/length(observed), length(observed)))}Chi-squared test for given probabilities data: observed X-squared = 23.333, df = 3, p-value = 3.441e-05 P-Value <0.05, menolak Ho, terdapat preferensi warna yang signifikanApakah jenis kelamin berpengaruh terhadap preferensi film?
{# Membuat matriks kontingensi tabel <- matrix(c(60, 40, 50, 70), nrow = 2, byrow = TRUE) colnames(tabel) <- c("Film A", "Film B") rownames(tabel) <- c("Laki-laki", "Perempuan") tabel}Film A Film B Laki-laki 60 40 Perempuan 50 70{Uji Chi-square untuk independensi > chisq.test(tabel)}data: tabel X-squared = 6.6183, df = 1, p-value = 0.01009 P-Value <0.05, Ho ditolak,terdapat pengaruh antara jenis kelamin dan preferensi film.Hubungan antara program studi (Statistik, Komputer, Ekonomi) dan tempat tinggal (Kost, Rumah Orang Tua, Asrama).
{# Membuat matriks kontingensi tabel <- matrix(c(20, 10, 5, 15, 20, 10, 10, 25,10), nrow = 3, byrow = TRUE) colnames(tabel) <- c("Kost", "Rumah Orang Tua", "Asrama") rownames(tabel) <- c("Statistik", "Komputer", "Ekonomi") tabel}Kost Rumah Orang Tua Asrama Statistik 20 10 5 Komputer 15 20 10 Ekonomi 10 25 10{Uji Chi-square untuk independensi > chisq.test(tabel)}data: tabel X-squared = 10.863, df = 4, p-value = 0.02815 Nilai P-Value <0.05, Ho ditolak, terdapat hubungan signifikan antara program studi dan tempat tinggal.24 siswa menunjukkan peningkatan nilai setelah kursus, 8 penurunan, 3 sama. Apakah ada perbedaan signifikan?
# total perubahan (tidak termasuk yang nilainya tetap) # Sign test: uji binomial (dua arah) binom.test(successes, n, p = 0.5, alternative = "two.sided")}Exact binomial test data: successes and n number of successes = 24, number of trials = 32, p-value = 0.007 alternative hypothesis: true probability of success is not equal to 0.5 95 percent confidence interval: 0.5659506 0.8853840 sample estimates: probability of success 0.75 P-Value <0.05, menolak Ho, terdapat bukti bahwa kursus memiliki dampak peningkatan nilai.Gunakan Wilcoxon:
Skor sebelum pelatihan: 75, 70, 68, 72, 69
Skor sesudah: 78, 74, 70, 75, 72
{# Data Skor Pelatihan Sebelum <- c(75, 70, 68, 72, 69) Sesudah <- c(78, 74, 70, 75, 72) wilcox.test(Sebelum, Sesudah, paired = TRUE)}Wilcoxon signed rank test with continuity correction data: Sebelum and Sesudah V = 0, p-value = 0.05447 alternative hypothesis: true location shift is not equal to 0 P Value >0.05, gagal menolak Ho, tidak terdapat perbedaan signifikan antara skor sebelum dan sesudah.- Gunakan Mann-Whitney:
Kelompok A: 62, 65, 66, 70, 68
Kelompok B: 58, 60, 59, 63, 61
{#Data a <- c(62,65 , 66, 70, 68) b <- c(58, 60, 59, 63, 61) wilcox.test(a, b)}
Wilcoxon rank sum exact test
data: a and b W = 24, p-value = 0.01587
alternative hypothesis: true location shift is not equal to 0
P-Value <0.05, Gagal Menolak Ho, terdapat perbedaan signifikan antara kelompok A dan Kelompok B
Gunakanlah dataset pada link berikut untuk menjawab pertanyaan di bawah ini.
a. Are European Union membership variable and development variable independent from each other?
b. Do the Women Entrepreneurship Index and Global Entrepreneurship Index values show a statistically significant difference between the countries that are members of the European Union and not? (Method Mann-Whitney U)
c. us there a statistically significant relationship between Women’s Entrepreneurship Index and Global Entrepreneurship Index values?
{data <- read.csv("C:/Users/LOQ/Downloads/Dataset3.csv", sep =";")}
{# Membuat tabel kontingensi tabel_idn <- table (data$European.Union.Membership, data$Level.of.development) # Uji Chi-square untuk independensi chisq.test(tabel_idn)}
Pearson's Chi-squared test with Yates' continuity correction
data: tabel_idn X-squared = 26.222, df = 1, p-value = 3.043e-07
P-Value <0.05, Menolak Ho, terdapat hubungan antara keanggotaan uni eropa dengan tingkat pembangunan suatu negara.
{# Uji Mann-Whitney untuk Women Entrepreneurship Index wilcox.test(data$Women.Entrepreneurship.Index ~ data$European.Union.Membership)}
Wilcoxon rank sum test with continuity correction
data: data$Women.Entrepreneurship.Index by data$European.Union.Membership W = 536, p-value = 1.358e-05
alternative hypothesis: true location shift is not equal to 0
Warning message: In wilcox.test.default(x = DATA[[1L]], y = DATA[[2L]], ...) : cannot compute exact p-value with ties
P-Value <0.05, Menolak Ho, terdapat perbedaan antara yang menjadi anggota UE dan yang bukan UE.
{# Uji Mann-Whitney untuk Global Entrepreneurship Index wilcox.test(data$Entrepreneurship.Index ~ data$European.Union.Membership)}
Wilcoxon rank sum test with continuity correction
data: data$Entrepreneurship.Index by data$European.Union.Membership W = 490, p-value = 0.0005338
alternative hypothesis: true location shift is not equal to 0
Warning message: In wilcox.test.default(x = DATA[[1L]], y = DATA[[2L]], ...) : cannot compute exact p-value with ties
P-Value <0.05, Menolak Ho, terdapat perbedaan antar negara anggota UE dan NON UE.
{# Menghitung korelasi antara Women Entrepreneurship Index dan Entrepreneurship Index Korelasi <- cor(data$Women.Entrepreneurship.Index, data$Entrepreneurship.Index) print(Korelasi)}
[1] 0.9145797
Nilai korelasi 0.9145797, menunjukan terdapat hubungan yang kuat antara women enterpreneurship index dan entrepeneurship index.