Independent-sample t-test

A/B Testing ใน R

Lauryn Burleigh

Data Scientist

Independent t-test ในการออกแบบ A/B

  • นัยสำคัญของความแตกต่างระหว่างค่าเฉลี่ย
  • สมมติฐานหลัก:
    • พิซซ่าชีสและเปปเปอโรนีใช้เวลารับประทานเท่ากัน (ไม่มีความแตกต่าง)
A/B Testing ใน R

ข้อสมมติ

  • ตัวแปรตาม:
    • สเกลอินเทอร์วัลหรืออัตราส่วน
    • ช่วงห่างเท่ากัน
  • ตัวอย่างสุ่ม
  • การแจกแจงแบบปกติ
  • ความแปรปรวนของกลุ่มใกล้เคียงกัน
library(ggplot2)
ggplot(pizza, aes(x = Time, 
                  fill = Topping)) +
       geom_histogram() + 
       facet_grid(Topping~.)

ฮิสโตแกรมการแจกแจงแบบปกติ 2 กลุ่ม ได้แก่ เปปเปอโรนีสีชมพูมีค่าเฉลี่ย 8 และชีสสีฟ้ามีค่าเฉลี่ย 6.2

A/B Testing ใน R

ขนาดตัวอย่าง

library(pwr)
pwr.t.test(d = 0.73, power = 0.80, 
           sig.level = 0.05, 
           type = "two.sample", 
           alternative = "two.sided")
  Two-sample t test power calculation 

              n = 30.44799
              d = 0.73
      sig.level = 0.05
          power = 0.8
    alternative = two.sided

NOTE: n is number in *each* group
A/B Testing ใน R

การประเมินความแปรปรวน

  • ความแปรปรวนของกลุ่มเท่ากัน
  • Levene's test

ไม่มีนัยสำคัญ (p > 0.05) = ความแปรปรวนเท่ากัน

มีนัยสำคัญ (p < 0.05) = ความแปรปรวนไม่เท่ากัน

library(car)
leveneTest(Time ~ Topping, 
           data = Pizza)
Levene's Test for Homogeneity of Variance
         Df F value Pr(>F)
group   1  0.1457 0.7031
A/B Testing ใน R

การทดสอบ

t.test(Time ~ Topping, data = Pizza, 
       paired = FALSE, 
       alternative = "two.sided", 
       var.equal = TRUE)
    Two Sample t-test
data:  Time by Topping
t = 2.3811, df = 198, p-value = 0.01821
alternative hypothesis: true difference 
in means between group Pepperoni and 
group Cheese is not equal to 0
95 percent confidence interval:
 0.0599370 0.6377601
A/B Testing ใน R

Cohen's d

  • Cohen's d: ขนาดผลของ t-test
    • การวัดมาตรฐานของความแตกต่างระหว่างค่าเฉลี่ย
  • เล็ก: 0.2
  • กลาง: 0.5
  • ใหญ่: 0.8
library(effectsize)
cohens_d(Time ~ Topping, data = Pizza)
Cohen's d |       95% CI
<----------------------
0.34      | [0.06, 0.62]
A/B Testing ใน R

กำลังทดสอบ

library(pwr)

pwr.t.test(n = 1000, 
           sig.level = 0.0182, 
           d = 0.34, 
           type = "two.sample")
  Two-sample t test power calculation 
              n = 100
              d = 0.34
      sig.level = 0.0182
          power = 0.510256
    alternative = two.sided
NOTE: n is number in *each* group
  • กำลังทดสอบที่เหมาะสมสำหรับการยอมรับผล: 0.8
    • ความน่าจะเป็นของการเกิดข้อผิดพลาด: 20%
    • 100 - 80 = 20
A/B Testing ใน R

มาฝึกกันเถอะ!

A/B Testing ใน R

Preparing Video For Download...