A/B 拆分测试的卡方独立性检验

机器算法验证 卡方检验 测试
2022-03-24 07:56:34

我有一个网页的 A/B 拆分测试的结果。

Page  Impressions   Clicks    CTR       
A     56,000        10        0.018%    
B     78,000        21        0.027%    

我想测试 ctr 的统计显着差异。零假设 - 页面 A 和 B 之间的点击率没有差异。

我将如何在更理论的层面上做到这一点?就像行、列、设置期望值一样?

2个回答

这是布置卡方检验的一种方法——您不一定需要所有这些细节。测试不关心你的行和列的方式,所以我会按照你的方式来做。

Comparing proportions via Pearson's Chi-squared test of independence
at the 5% level      #(for this example, at least - you choose your own level)

Null hypothesis - there is no difference in CTR between pages A & B.

Observed:
   Clicks   Nonclicks     Impressions 
A     10       55990           56000
B     21       77979           78000

Tot   31      133969          134000

Expected:
   Clicks   Nonclicks     Impressions 
A   12.96    55987.04          56000
B   18.04    77981.96          78000

Tot   31      133969          134000

(Expected 表的正文中的条目是 row.total*column.total/overall.total)

对卡方的贡献 =(观察到 - 预期)^2/预期

       Clicks   Nonclicks   
 A     0.6741   0.0001560
 B     0.4840   0.0001120

Chi-square = sum((Observed - Expected)^2/Expected)
           = 1.158368

 df = 1
 p-value = 0.2818  

 At the 5% level we do not reject H0 - there's no evidence of a difference in
 click through rate.

(您需要表格或程序来查找 p 值。)

独立性的卡方检验只检验变量之间是否存在关系,但并不是说 CTR 之间没有区别:

H0:点击和界面是独立的。哈:点击和界面不是独立的(也就是说,发生了一些有趣的事情;你的一个界面表现更好)

您将像这样准备测试:

success <- c(10,21)
failure <- c(55990,77979)
my.table <- rbind(success,failure)

然后运行测试:

> chisq.test(my.table)

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

data:  my.table
X-squared = 0.79955, df = 1, p-value = 0.3712

当您关闭连续性校正时,您会得到与前一个受访者相同的结果(许多人认为您根本不需要,除非您在 A 或 B 上的点击次数少于 5 次):

> chisq.test(my.table, correct=FALSE)

    Pearson's Chi-squared test

data:  my.table
X-squared = 1.1584, df = 1, p-value = 0.2818

如果需要,您可以轻松访问期望值表并手动计算卡方检验统计量:

> chisq.test(my.table, correct=FALSE)$expected
               [,1]        [,2]
success    12.95522    18.04478
failure 55987.04478 77981.95522

另一种选择是二比例 zitest,它说:

H0:B 的 CTR - A 的 CTR = 0 Ha:B 的 CTR - A 的 CTR > 0(B 的 CTR 更大)

> source("https://raw.githubusercontent.com/NicoleRadziwill/R-Functions/master/z2test.R")
> z2.test(10,55990,21,77979)
$estimate
[1] -9.069995e-05

$ts.z
[1] -1.076516

$p.val
[1] 0.1408483

$cint
[1] -2.504372e-04  6.903728e-05

请注意,p 值很大 (0.14),置信区间包括零值——A 和 B CTR 之间没有区别。

您还可以使用卡方检验统计量来运行测试并获得置信区间:

> prop.test(c(10,21),c(55990,77979))

    2-sample test for equality of proportions with continuity correction

data:  c(10, 21) out of c(55990, 77979)
X-squared = 0.79999, df = 1, p-value = 0.3711
alternative hypothesis: two.sided
95 percent confidence interval:
 -2.657756e-04  8.437566e-05
sample estimates:
      prop 1       prop 2 
0.0001786033 0.0002693033

请注意,p 值与您之前运行独立性卡方检验时的 p 值相同,并且置信区间中也包含零……表明您的 A 和 B 的 CTR 之间没有显着差异。