Korelasi peringkat Spearman

Pengujian A/B di R

Lauryn Burleigh

Data Scientist

Asumsi korelasi Spearman

  • Berbasis peringkat — diurutkan menurut posisi
  • Korelasi Spearman tinggi — posisi serupa pada dua variabel
  • Data kontinu atau diskret
    • Ordinal, interval, atau rasio

Gambar empat batang berurutan dari tertinggi ke terendah; tertinggi bernilai 1 dan terendah bernilai 4.

Pengujian A/B di R

Hubungan monotonik

  • Korelasi Spearman (rho): hubungan monotonik

    • Tidak selalu naik atau turun konsisten
  • Monotonik lebih longgar daripada linear

ggplot(data, aes(x = drownings, 
                 y = icecream)) +
  geom_point()

Plot sebar dengan hubungan meningkat monotonik: ice cream stabil, lalu naik, lalu stabil pada sumbu y saat drownings naik pada sumbu x.

Plot sebar dengan hubungan menurun monotonik: ice cream stabil, lalu turun, lalu stabil, lalu turun pada sumbu y saat drownings naik pada sumbu x.

Pengujian A/B di R

Hipotesis dan ukuran sampel

  • Hipotesis nol: tidak ada asosiasi monotonik antara waktu dan kenikmatan pizza
library(pwr)
pwr.r.test(r = 0.3, power = 0.80, 
           sig.level = 0.05)
    approximate correlation power 
 calculation (arctangh transformation) 

              n = 84.07364
              r = 0.3
      sig.level = 0.05
          power = 0.8
    alternative = two.sided
Pengujian A/B di R

Spearman mengabaikan grup

cor.test(~ enjoyment + time, 
         data = pizza, 
         method = "spearman", 
        exact = FALSE)
    Spearman's rank correlation rho
data:  time and enjoyment
S = 2, p-value = .003245
alternative hypothesis: true rho is 
not equal to 0
sample estimates:
      rho 
0.9984962 
samp <- length(pizza$time)
[1]  90
Pengujian A/B di R

Spearman dalam tiap grup

cor.test(~ enjoyment + time, 
         data = pizza, 
         subset = 
             (Topping == "Cheese"),
         method = "spearman",
         exact = FALSE)
    Spearman's rank correlation rho
data:  time and enjoyment
S = 1.2434e-14, p-value = 0.0003968
alternative hypothesis: true rho is 
not equal to 0
sample estimates:
rho 
  1 
ggplot(pizza, aes(x = enjoyment, 
                  y = time, 
                  color = Topping)) + 
  geom_point()

Kemiringan positif curam untuk data Cheese berwarna biru di kiri sumbu x, dan kemiringan positif lebih landai untuk data Pepperoni berwarna merah muda di kanan sumbu x.

Pengujian A/B di R

Analisis daya untuk Spearman

library(pwr)
pwr.r.test(r = 0.998, n = 90, 
           sig.level = 0.003)
     approximate correlation power 
  calculation (arctangh transformation) 

              n = 90
              r = 0.998
      sig.level = 0.003
          power = 1
    alternative = two.sided
Pengujian A/B di R

Merujuk keluaran

rhotest <- cor.test(~ enjoyment + time, 
         data = pizza, 
         method = "spearman")
samp <- length(pizza$time)
library(pwr)
pwr.r.test(r = rhotest$estimate, 
           sig.level = rhotest$p.value,
           n = samp)
     approximate correlation power 
  calculation (arctangh transformation) 

              n = 90
              r = 0.998
      sig.level = 0.003
          power = 1
    alternative = two.sided
Pengujian A/B di R

Ayo berlatih!

Pengujian A/B di R

Preparing Video For Download...