我有一个测试,我想检查测试组的安装率是否至少是对照组的 70%。为此,我从 Python 库中获取了以下函数
alpha = 0.1
power = 0.80
p_A = 0.0056 # control group install rate
effect_size = sms.proportion_effectsize(p_A, p_A * 0.7) # 70% of control
# Step 2: Calculate sample size per group with a one-sided (non-inferiority) test
sample_size = sms.NormalIndPower().solve_power(
effect_size,
power=power,
alpha=alpha,
ratio=1,
alternative='larger' # one-tailed test for detecting p_B >= 70% * p_A
)
我得到了大约 15000 个样本量。但是当我收集结果后运行测试时。当测试 IR 是对照的 85% 时,它无法检测测试 IR 和对照 IR 之间的差异。我不明白为什么如果它足够大,它看不到差异。
import numpy as np
import statsmodels.stats.api as sms
# Example: Assume these are your data
x_test = 80 # Number of installs in test group
n_test = 15015 # Sample size in test group
x_control = 101 # Number of installs in control group
n_control = 15015 # Sample size in control group
# Step 1: Observed proportions
p_test = x_test / n_test
p_control = x_control / n_control
x_control = p_control * n_control * 0.7
# Step 2: Conduct the z-test for proportions
stat, p_value = sms.proportions_ztest([x_test, x_control], [n_test, n_control], alternative='larger')
# Step 3: Output the result
print(f"Z-statistic: {stat:.4f}, p-value: {p_value:.4f}")
# Decision based on p-value
alpha = 0.05
if p_value < alpha:
print("Reject the null hypothesis: Test group's rate is significantly greater than 70% of control group's rate.")
else:
print("Fail to reject the null hypothesis: No significant difference found.")
我尝试用 z 检验计算样本大小以及结果
我认为您遇到的问题与效果大小和比较有关。
effect_size = sms.proportion_effectsize(p_A, p_A * 0.7) # 70% of control
正在获得介于 control 和 70% 的控件之间的效果大小。
在测试中,您将对 x_test 和 70% 的对照 进行显着性测试。不是原始控制和 x_test,这是您在效果大小部分所做的事情。因此,如果您在代码中省略
x_control = p_control * n_control * 0.7
行,您会发现非常接近 95% 的显着性。
我认为您想要做的是将 x_test 与 70% 的对照进行比较,因此您的效果大小需要是对 70% 的对照的预测。在这种情况下:
effect_size = sms.proportion_effectsize(p_A * 0.7 , x_test)
这有道理吗?我最近也在为非劣效性测试而苦苦挣扎