Praktek Chi Square dan Non Parametrik

Author

Siti Amania Raydesyana

Latihan

  1. 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, maka hipotesis nol gagal ditolak, sehingga dapat disimpulkan bahwa distribusi jumlah kelahiran selama satu minggu merata.

  2. 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

Nilai P-Value <0.05, maka hipotesis nol ditolak. Sehingga dapat disimpulkan bahwa distribusi jumlah pilihan pemilih tidak merata.

  1. 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 signifikan 
    chisq.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

Nilai P-Value <0.05, maka hipotesis nol ditolak. Sehingga dapat disimpulkan bahwa ada preferensi wana yang signifikan.

  1. Apakah 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)
    
        Pearson's Chi-squared test with Yates' continuity correction
    
    data:  tabel
    X-squared = 6.6183, df = 1, p-value = 0.01009

    nilai p-value <0.05, maka hipotesis nol ditolak, maka dapat disimpulkan bahwa terdapat pengaruh yang signifikan antara jenis kelamin dan preferensi film.

  2. 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)
    
        Pearson's Chi-squared test
    
    data:  tabel
    X-squared = 10.863, df = 4, p-value = 0.02815

    nilai p-value <0.05, maka hipotesis nol ditolak, maka dapat disimpulkan bahwa terdapat hubungan yang signifikan antara program studi dan tempat tinggal.

  3. 24 siswa menunjukkan peningkatan nilai setelah kursus, 8 penurunan, 3 sama. Apakah ada perbedaan signifikan? Sign Test

    # Jumlah siswa dengan nilai naik dan turun
    successes <- 24  # nilai meningkat
    n <- 32          # 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 

Karena p value <0.05, maka terdapat bukti statistik secara signifikan bahwa kursus berdampak pada peningkatan nilai.

  1. 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)
    Warning in wilcox.test.default(Sebelum, Sesudah, paired = TRUE): cannot compute
    exact p-value with ties
    
        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, maka gagal menolak H nol. maka dapat disimpulkan bahwa terdapat perbedaan signifikan antara skor sebelum dan sesudah pelatihan.

  1. 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, maka menolak H nol. dapat diinterpretasikan bahwa terdapat perbedaan yang signifikan secara statistik antara kelompok a dan kelompok b.

  1. Gunakanlah dataset pada link berikut untuk menjawab pertanyaan di bawah ini.
  • Are European Union membership variable and development variable independent from each other?

  • 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)

  • Is there a statistically significant relationship between Women’s Entrepreneurship Index and Global Entrepreneurship Index values?

    data <- read.csv("C:\\Users\\Lenovo\\Downloads\\Dataset3.csv")
    str(data)
    'data.frame':   51 obs. of  1 variable:
     $ No.Country.Level.of.development.European.Union.Membership.Currency.Women.Entrepreneurship.Index.Entrepreneurship.Index.Inflation.rate.Female.Labor.Force.Participation.Rate: chr  "4;Austria;Developed;Member;Euro;54.9;64.9;0.9;67.1" "6;Belgium;Developed;Member;Euro;63.6;65.5;0.6;58" "17;Estonia;Developed;Member;Euro;55.4;60.2;-0.88;68.5" "18;Finland;Developed;Member;Euro;66.4;65.7;-0.2;67.7" ...
data <- read.csv("D:\\KMP 61\\Semester 2 2025\\3. Statistika\\Praktikum\\Dataset3.csv", sep = ";")

names(data)  # Lihat semua nama kolom
[1] "No"                                   
[2] "Country"                              
[3] "Level.of.development"                 
[4] "European.Union.Membership"            
[5] "Currency"                             
[6] "Women.Entrepreneurship.Index"         
[7] "Entrepreneurship.Index"               
[8] "Inflation.rate"                       
[9] "Female.Labor.Force.Participation.Rate"
unique(data$EU_Member)
NULL
unique(data$Development_Status)
NULL
str(data)
'data.frame':   51 obs. of  9 variables:
 $ No                                   : int  4 6 17 18 19 20 22 28 30 34 ...
 $ Country                              : chr  "Austria" "Belgium" "Estonia" "Finland" ...
 $ Level.of.development                 : chr  "Developed" "Developed" "Developed" "Developed" ...
 $ European.Union.Membership            : chr  "Member" "Member" "Member" "Member" ...
 $ Currency                             : chr  "Euro" "Euro" "Euro" "Euro" ...
 $ Women.Entrepreneurship.Index         : num  54.9 63.6 55.4 66.4 68.8 63.6 43 64.3 51.4 56.6 ...
 $ Entrepreneurship.Index               : num  64.9 65.5 60.2 65.7 67.3 67.4 42 65.3 41.3 54.5 ...
 $ Inflation.rate                       : num  0.9 0.6 -0.88 -0.2 0 0.5 -1.7 -0.3 0 0.2 ...
 $ Female.Labor.Force.Participation.Rate: num  67.1 58 68.5 67.7 60.6 69.9 42.5 59.4 47.2 66.4 ...
#tabel kontingensi antara keanggotaan EU dan status pengembangan
table_eu_dev <- table(data$European.Union.Membership, data$Level.of.development)

#Uji Chi Square
chisq.test(table_eu_dev)

    Pearson's Chi-squared test with Yates' continuity correction

data:  table_eu_dev
X-squared = 26.222, df = 1, p-value = 3.043e-07

p value <0.05, maka menolak Hipotesis nol yang berarti terdapat hubungan yang signifikan secara statistik antara variabel status keanggotaan negara anggota EU dan status perkembangan negara. keduanya tidak independen

#Mann- Whitney U Test
# Uji Mann-Whitney untuk Women Entrepreneurship Index
wilcox.test(data$Women.Entrepreneurship.Index ~ data$European.Union.Membership)
Warning in wilcox.test.default(x = DATA[[1L]], y = DATA[[2L]], ...): cannot
compute exact p-value with ties

    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
# Uji Mann-Whitney untuk Global Entrepreneurship Index
wilcox.test(data$Entrepreneurship.Index ~ data$European.Union.Membership)
Warning in wilcox.test.default(x = DATA[[1L]], y = DATA[[2L]], ...): cannot
compute exact p-value with ties

    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

Women Entrepreneurship Index:

P-value <0.05, terdapat perbedaan signifikan antara kelompok negara yang menjadi anggota UE dan yang bukan anggota UE dalam hal Woman Entrepreneurship Index. perbedaan lokasi (perbedaan indeks kewirausahaan wanita) antara kedua kelompok tersebut tidak sama dengan nol, yang terbukti benar dengan p values yang sangat kecil.

Global Entrepreneurhip Index:

W= 490, nilai statistik uji wilcoxon untuk indeks kewirausahaan global

P Value <0.05, yang menunjukkan bahwa terdapat perbedaan signifikan antara negara anggota UE dan non UE dalam hal Global Entrepreneurship Index.

Kedua Uji menunjukkan bahwa ada perbedaan dalam posisi atau lokasi indeks kewirausahaan antara kedua kelompok tersebut.

# Menghitung korelasi antara Women Entrepreneurship Index dan Entrepreneurship Index
correlation <- cor(data$Women.Entrepreneurship.Index, data$Entrepreneurship.Index)

# Menampilkan hasil korelasi
correlation
[1] 0.9145797

Nilai korelasi 0.9145797 menunjukkan adanya hubungan yang sangat kuat dan positif antara Women Entrepreneurship Index dan Entrepreneurship Index.

Dengan kata lain, semakin tinggi nilai pada Women Entrepreneurship Index suatu negara, semakin tinggi pula nilai pada Entrepreneurship Index negara tersebut. Hubungan ini sangat kuat karena nilai korelasinya mendekati 1, yang menunjukkan hubungan linier yang sangat positif antara kedua variabel tersebut.

Secara umum, korelasi ini mengindikasikan bahwa negara-negara dengan tingkat kewirausahaan perempuan yang lebih tinggi cenderung juga memiliki tingkat kewirausahaan yang lebih tinggi secara keseluruhan, sebagaimana tercermin dalam Global Entrepreneurship Index.