皮爾森相關

R 中的 A/B 測試

Lauryn Burleigh

Data Scientist

皮爾森相關的假設

  • 選擇相關檢定:資料特性
  • 皮爾森相關
    • 線性
    • 常態分配

圖中直線自左下向右上遞增。

標準常態分配圖。

R 中的 A/B 測試

皮爾森相關與 A/B 測試

  • A 組:起司披薩
  • B 組:臘腸披薩

 

  • 吃披薩時間與享受度的關係

忽略分組

  • 虛無假設-吃飯時間與披薩享受度無關

各組別

  • 虛無假設-吃飯時間與起司披薩享受度無關
  • 虛無假設-吃飯時間與臘腸披薩享受度無關
R 中的 A/B 測試

決定樣本數

  • r 預期效果(用 cor() 求得)
  • 拒絕虛無的 sig.level
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
R 中的 A/B 測試

檢視線性關係

ggplot(pizza, aes(x = enjoyment, 
                  y = time)) + 
    geom_point()

散點圖:x 軸為 enjoyment、y 軸為 time,呈正線性關係。

ggplot(pizza, aes(x = enjoyment, 
                  y = time)) + 
    geom_point()

散點圖:x 軸 enjoyment、y 軸 time 呈正線性,但左下與右上各有一群聚點。

R 中的 A/B 測試

檢視常態性

shapiro.test(pizza$time)
    Shapiro-Wilk normality test
data:  pizza$time
W = 0.98686, p-value = 0.4282
  • 資料呈常態
shapiro.test(pizza$enjoyment)
    Shapiro-Wilk normality test
data:  pizza$enjoyment
W = 0.98916, p-value = 0.5971
  • 資料呈常態
R 中的 A/B 測試

皮爾森(忽略分組)

cor.test(~ time + enjoyment, 
         data = pizza, 
         method = "pearson")

 

變異比例:cor^2

0.30^2
[1] 0.09
Pearson's product-moment correlation

data:  time and enjoyment
t = 22.304, df = 88, p-value = 0.0218
alternative hypothesis: true correlation
is not equal to 0
95 percent confidence interval:
 0.8833166 0.9479256
sample estimates:
      cor 
0.3021878
R 中的 A/B 測試

皮爾森(組內)

cor.test(~ time + enjoyment, 
         data = pizza, 
         subset = 
             (Topping == "Cheese"),
         method = "pearson")
Pearson's product-moment correlation

data:  Time and Enjoy
t = 11.121, df = 98, p-value < 2.2e-16
alternative hypothesis: true correlation 
is not equal to 0
95 percent confidence interval:
 0.6451710 0.8226595
sample estimates:
     cor 
0.746935 
R 中的 A/B 測試

檢定力分析

皮爾森(忽略分組):

Pearson's product-moment correlation

data:  time and enjoyment
t = 22.304, df = 88, p-value = 0.0218
alternative hypothesis: true 
correlation is not equal to 0
95 percent confidence interval:
 0.8833166 0.9479256
sample estimates:
      cor 
0.3021878
library(pwr)
pwr.r.test(r = 0.302, n = 100, 
           sig.level = 0.022)
     approximate correlation power 
  calculation (arctangh transformation) 

              n = 100
              r = 0.302
      sig.level = 0.022
          power = 0.7853514
    alternative = two.sided
R 中的 A/B 測試

一起來練習吧!

R 中的 A/B 測試

Preparing Video For Download...