比率检验原理及R语言实现

总体比率的假设检验实际上是业界最常用也是最需要的检验,例如在ABtest中,检验两个实验的转化率是否有显著差异,则需要用到比率检验。本文介绍比率检验的原理,以及R语言的实现代码。

单总体比率的假设检验

前提条件:

  • 样本取自两点分布 X ∼ B ( 1 , p ) X \sim B(1,p) XB(1,p)
  • 样本量 n n n很大,能够满足 n p > 5 np>5 np>5 n ( 1 − p ) > 5 n(1-p)>5 n(1p)>5

记要检验的原假设为为 H 0 : p = p 0 H_0: p=p_0 H0:p=p0,则样本比率 p ~ \widetilde{\mathrm{p}} p 服从方差为 p ( 1 − p ) / n p(1-p)/n p(1p)/n的正态分布,对应标准化的检验统计量近似服从 N ( 0 , 1 ) N(0,1) N(0,1)

u = n ( p ~ − p 0 ) p 0 ( 1 − p 0 ) \mathrm{u}=\frac{\sqrt{\mathrm{n}}\left(\widetilde{\mathrm{p}}-\mathrm{p}_{0}\right)}{\sqrt{\mathrm{p}_0\left(1-\mathrm{p}_0\right)}} u=p0(1p0) n (p p0)

实际上,当样本量很少时,需要采用精确的比率检验,即直接使用二项分布来检验,具体实现见下文的R代码。

两个总体比率的假设检验

检验前提条件:

  • 两总体互相独立
  • 变量都取自两点分布,即两总体服从二项分布
  • 两总体且每类的样本量满足大于5的要求,从而能用正态分布来近似

那么可知:

( p ~ 1 − p ~ 2 ) − ( p 1 − p 2 ) p 1 ( 1 − p 1 ) n 1 + p 2 ( 1 − p 2 ) n 2 ≈ ( p ~ 1 − p ~ 2 ) − ( p 1 − p 2 ) p 1 ( 1 − p ~ 1 ) n 1 + p ~ 2 ( 1 − p ~ 2 ) n 2 ∼ N ( 0 , 1 ) \frac{\left(\widetilde{\mathrm{p}}_1-\widetilde{\mathrm{p}}_2\right)-\left(\mathrm{p}_1-\mathrm{p}_2\right)}{\frac{\mathrm{p}_1\left(1-\mathrm{p}_1\right)}{\mathrm{n}_1}+\frac{\mathrm{p}_2\left(1-\mathrm{p}_2\right)}{\mathrm{n}_2}} \approx \frac{\left(\widetilde{\mathrm{p}}_1-\widetilde{\mathrm{p}}_2\right)-\left(\mathrm{p}_1-\mathrm{p}_2\right)}{\frac{\mathbb{p}_1\left(1-\widetilde{\mathrm{p}}_1\right)}{\mathrm{n}_1}+\frac{\widetilde{\mathrm{p}}_2\left(1-\widetilde{\mathrm{p}}_2\right)}{\mathrm{n}_2}} \sim \mathrm{N}(0,1) n1p1(1p1)

  • 3
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值