A/B test --计算实验所需样本量

如果懒得看下方内容,或者是看完了还有些许不懂,可以直接用这个好用又免费的计算器来计算
https://www.evanmiller.org/ab-testing/sample-size.html

新加一个
https://www.eyeofcloud.com/abtest-widget/124.html

……………………………………………………………………
A/B 测试一般是比较实验组和对照组在某些指标上是否存在差异,当然更多时候是看实验组相比对照组某个指标表现是否更好。

这样的对比在统计学上叫做两样本假设检验,即实验组和对照组为两样本;

  • 假设检验的原假设Ho:实验组和对照组无显著差异;
  • 备择假设H1:实验组和对照组存在显著差异。

显然,如果实验选取的样本很小,实验结果可信度就不高,因为很可能抽取的样本不能代表真实的水平。而在实际中,因为各种成本的考量,实验样本量也不可能无限大。那么,一般至少需要多少样本才能得到可信的结论呢?

实验所需样本量的一般公式

统计学里有最小样本量计算的公式,公式如下:
在这里插入图片描述
其中

  • n是每组所需样本量,因为A/B测试一般至少2组,所以实验所需样本量为2n;
  • α和β分别称为第一类错误概率和第二类错误概率,一般分别取0.05和0.2;
  • Z为正态分布的分位数函数;
  • Δ为两组数值的差异,如点击率1%到1.5%,那么Δ就是0.5%;
  • σ为标准差,是数值波动性的衡量,σ越大表示数值波动越厉害。

从这个公式可以知道,在其他条件不变的情况下,如果实验两组数值差异越大或者数值的波动性越小,所需要的样本量就越小。

比例类数值所需样本量的计算

实际A/B测试中,我们关注的较多的一类是比例类的数值,如点击率、转化率、留存率等。

这类比例类数值的特点是,对于某一个用户(样本中的每一个样本点)其结果只有两种,“成功”或“未成功”;对于整体来说,其数值为结果是“成功”的用户数所占比例。如转化率,对于某个用户只有成功转化或未成功转化。

比例类数值的假设检验在统计学中叫做两样本比例假设检验。其最小样本量计算的公式为:

在这里插入图片描述
上面式子中

  • p1我们称为基础值,是实验关注的关键指标现在的数值(对照组);
  • p2我们称为目标值,是希望通过实验将其改善至的水平;
  • α和β第一类错误和第二类错误上边已经提到,暂不多做说明,通常设定α为0.05,β为0.2 。

既然样本量计算的公式已经清楚,那么我们按照公式代入即可得到结果。这里介绍5种获得比例类数值实验所需样本量的方法,分别为:在线工具、Excel、R、Python、G*Power。

以下将以以p1=0.3,p2=0.305,α=0.05,β=0.2为例,演示在这几个工具里计算样本量的方法。

用在线工具计算所需样本量

文章开头提起的好用免费的计算器:
https://www.evanmiller.org/ab-testing/sample-size.html

计算方式如下:
在这里插入图片描述

在Excel中计算所需样本量

在Excel中用上NORM.S.INV等函数,即可实现样本量计算。如图:
在这里插入图片描述
C7-C11的公式分别为:

C7:=(NORM.S.INV(C4/2)+NORM.S.INV(C5))2*(C2*(1-C2)+C3*(1-C3))/(C3-C2)2

C8:=(NORM.S.INV(C4/2)SQRT(2(C2+C3)/2*(1-(C2+C3)/2))+NORM.S.INV(C5)SQRT(C2(1-C2)+C3*(1-C3)))2/(C3-C2)2

C9:=(NORM.S.INV(C4/2)SQRT(2C2*(1-C2))+NORM.S.INV(C5)SQRT(C2(1-C2)+C3*(1-C3)))2/(C3-C2)2

C10:=2*(NORM.S.INV(C4/2)+NORM.S.INV(C5))2/(2*ASIN(SQRT(C2))-2*ASIN(SQRT(C3)))2

C11:=16*(C2*(1-C2))/(C3-C2)^2

在R中计算所需样本量

R中可以直接使用power.prop.test函数实现。一行代码就可搞定:

power.prop.test(p1 = 0.30, p2 = 0.305, sig.level = 0.05, power = 0.80, alternative = 'two')

在这里插入图片描述

在Python中计算所需样本量

Python中科学计算库里statsmodel也可直接支持计算。具体代码为:

from statsmodels.stats.power import zt_ind_solve_power
from statsmodels.stats.proportion import proportion_effectsize as es
 
zt_ind_solve_power(effect_size=es(prop1=0.30, prop2=0.305), alpha=0.05, power=0.8, alternative="two-sided")

执行后得到结果:
在这里插入图片描述

在G*Power中计算所需样本量

打开G*Power,选取Test family、Statistical test和Type of power analyisis为如下截图所示且输入对应数值。A/B 测试一般是实验组和对照组样本一样多,故N2/N1设为1。

点击Calculate,得到Sample size group1和Sample size group2即为对照组和实验组所需的样本量。

在这里插入图片描述

  • 12
    点赞
  • 74
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
make for plat=atlas310 cross=aarch64-ascend310-linux-gnu- LDFLAGS=-Wl,--gc-sections -static -L/home/257916/server/test/v1.1/Trunk/build/../src/thirdpart/libs/atlas310 -L/home/257916/server/test/v1.1/Trunk/build/../lib/atlas310 -ldw -lbs -lpthread -lm EXTRA_CFLAGS=-DSVN_VERSION="\"64670"\" -I /net -DOSA_MODULE_NAME=Spectrum-Convert@64670 -DBUILD_DATE="\"Mon, 24 Jul 2023 19:48:54 +0800"\" CFLAGS=-D_GNU_SOURCE -I/home/257916/server/test/v1.1/Trunk/build/../include -I/home/257916/server/test/v1.1/Trunk/build/../src/base/include -I/home/257916/server/test/v1.1/Trunk/build/../src/base/test/include -I/home/257916/server/test/v1.1/Trunk/build/../src/decode/include -I/home/257916/server/test/v1.1/Trunk/build/../src/decode/test/include -I/home/257916/server/test/v1.1/Trunk/build/../src/fourier/include -I/home/257916/server/test/v1.1/Trunk/build/../src/fourier/test/include -I/home/257916/server/test/v1.1/Trunk/build/../src/include -I/home/257916/server/test/v1.1/Trunk/build/../src/service/include -I/home/257916/server/test/v1.1/Trunk/build/../src/service/test/include -I/home/257916/server/test/v1.1/Trunk/build/../src/draw/include -I/home/257916/server/test/v1.1/Trunk/build/../src/draw/test/include -I/home/257916/server/test/v1.1/Trunk/build/../tools/include -fPIC -ffunction-sections -fdata-sections -g -Wall -O1 -c -o ############################################################ mkdir -p /home/257916/server/test/v1.1/Trunk/build/../bin/atlas310 aarch64-ascend310-linux-gnu-g++ -o draw test/src/draw_pic_test.o -Wl,--gc-sections -static -L/home/257916/server/test/v1.1/Trunk/build/../src/thirdpart/libs/atlas310 -L/home/257916/server/test/v1.1/Trunk/build/../lib/atlas310 -ldw -lbs -lpthread -lm /opt/Atlas310-ascend/toolkit/toolchain/hcc/bin/../lib64/gcc/aarch64-target-linux-gnu/7.3.0/../../../../aarch64-target-linux-gnu/bin/ld: test/src/draw_pic_test.o: Relocations in generic ELF (EM: 62) /opt/Atlas310-ascend/toolkit/toolchain/hcc/bin/../lib64/gcc/aarch64-target-linux-gnu/7.3.0/../../../../aarch64-target-linux-gnu/bin/ld: test/src/draw_pic_test.o: Relocations in generic ELF (EM: 62) /opt/Atlas310-ascend/toolkit/toolchain/hcc/bin/../lib64/gcc/aarch64-target-linux-gnu/7.3.0/../../../../aarch64-target-linux-gnu/bin/ld: test/src/draw_pic_test.o: Relocations in generic ELF (EM: 62) /opt/Atlas310-ascend/toolkit/toolchain/hcc/bin/../lib64/gcc/aarch64-target-linux-gnu/7.3.0/../../../../aarch64-target-linux-gnu/bin/ld: test/src/draw_pic_test.o: Relocations in generic ELF (EM: 62) /opt/Atlas310-ascend/toolkit/toolchain/hcc/bin/../lib64/gcc/aarch64-target-linux-gnu/7.3.0/../../../../aarch64-target-linux-gnu/bin/ld: test/src/draw_pic_test.o: Relocations in generic ELF (EM: 62) /opt/Atlas310-ascend/toolkit/toolchain/hcc/bin/../lib64/gcc/aarch64-target-linux-gnu/7.3.0/../../../../aarch64-target-linux-gnu/bin/ld: test/src/draw_pic_test.o: Relocations in generic ELF (EM: 62) /opt/Atlas310-ascend/toolkit/toolchain/hcc/bin/../lib64/gcc/aarch64-target-linux-gnu/7.3.0/../../../../aarch64-target-linux-gnu/bin/ld: test/src/draw_pic_test.o: Relocations in generic ELF (EM: 62) /opt/Atlas310-ascend/toolkit/toolchain/hcc/bin/../lib64/gcc/aarch64-target-linux-gnu/7.3.0/../../../../aarch64-target-linux-gnu/bin/ld: test/src/draw_pic_test.o: Relocations in generic ELF (EM: 62) /opt/Atlas310-ascend/toolkit/toolchain/hcc/bin/../lib64/gcc/aarch64-target-linux-gnu/7.3.0/../../../../aarch64-target-linux-gnu/bin/ld: test/src/draw_pic_test.o: error adding symbols: file in wrong format collect2: error: ld returned 1 exit status make[1]: *** [draw] Error 1 make[1]: Leaving directory `/home/257916/server/test/v1.1/Trunk/src/draw' make: *** [draw] Error 2
07-25
根你提供的信息,编译过程中出现了一个错误。错误信息显示 ld (链接器) 试图处理一个格式错误的文件。 具体来说,ld 报告了以下错误: ``` /opt/Atlas310-ascend/toolkit/toolchain/hcc/bin/../lib64/gcc/aarch64-target-linux-gnu/7.3.0/../../../../aarch64-target-linux-gnu/bin/ld: test/src/draw_pic_test.o: error adding symbols: file in wrong format collect2: error: ld returned 1 exit status ``` 这个错误通常发生在尝试链接不兼容的目标文件时。可能有以下几个原因导致这个错误: 1. 目标文件 `test/src/draw_pic_test.o` 的格式不正确,不符合链接器的预期。你可能要检查这个目标文件是否由正确的编译器生成,并且是否与你的交叉编译目标匹配。 2. 链接器正在尝试将不同架构的目标文件链接在一起。请确保你的交叉编译环境配置正确,并且编译器和链接器的目标架构与你的目标平台一致。 3. 缺少必要的库文件。请确保你的链接命令中指定的库文件存在,并且位于正确的位置。 针对这个错误,你可以尝试以下几个步骤来解决问题: 1. 检查目标文件的生成方式和来源。确保使用正确的编译器和编译选项生成目标文件,并确认目标文件的格式正确。 2. 检查你的交叉编译环境配置,确保交叉编译器和链接器的目标架构与你的目标平台一致。 3. 检查链接命令中指定的库文件路径是否正确,并确保库文件存在。 如果问题仍然存在,可能要更多的上下文信息来进行进一步的诊断和解决。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值