我正在尝试创建一个贝叶斯T检验计算器(使用“黑客的贝叶斯方法”寻求帮助),并希望确保我的解释正确。
例如,如果我有10,000个用于控制和测试的样本,而控制转换为500,控制转换为700,则输入增加50%和35%的概率,分别得到11.16%和73.86%。
如果然后我切换控件并进行测试,然后尝试找到-33%和-26%的概率,我将得到1减去第一个示例中的概率。这是由于分布的尾部吗?有人介意向我解释正确的解释方式吗?
from scipy.stats import beta
import numpy as np
from matplotlib import pyplot as plt
visitors_to_B = int(input('Enter number of visitors to the Control: '))
conversions_from_B = int(input('Enter number of conversions from the Control: '))
visitors_to_A = int(input('Enter number of visitors to test A: '))
conversions_from_A = int(input('Enter number of conversions from test A: '))
alpha_prior = 1
beta_prior =1
posterior_A = beta(alpha_prior + conversions_from_A,
beta_prior + visitors_to_A - conversions_from_A)
posterior_B = beta(alpha_prior + conversions_from_B,
beta_prior + visitors_to_B - conversions_from_B)
samples = 20000
samples_posterior_A = posterior_A.rvs(samples)
samples_posterior_B = posterior_B.rvs(samples)
print('There is a',round((samples_posterior_A > samples_posterior_B).mean()*100,2), '% chance that test A converts better than the control')
def relative_increase(a,b):
return (a-b)/b
posterior_rel_increase = relative_increase(samples_posterior_A,
samples_posterior_B)
inc1 = float(input('(1 of 2) What relative percent increase from test A to the control do you want to test? '))/100
inc2 = float(input('(2 of 2) What relative percent increase from test A to the control do you want to test? '))/100
print('There is a ',round((posterior_rel_increase > inc1).mean()*100,2), '% chance that test A has a ', round(inc1*100,2),'% relative increase than the control')
print('There is a ',round((posterior_rel_increase > inc2).mean()*100,2), '% chance that test A has a ', round(inc2*100,2),'% relative increase than the control')
input('Press Enter to close')