def stat_power(control, trial, ci=0.975):
'''
Calculates statistical power.
Parameters
----------
control : array-type
Control population sample.
trial: array-type
Trial population sample.
Returns
-------
Float
'''
# Calculate the mean, se and me-(4 std)
control = np.log(control)
trial = np.log(trial)
control_mean = np.mean(control)
trial_mean = np.mean(trial)
control_se = np.std(control, ddof=1) / np.sqrt(control.shape[0])
trial_se = np.std(trial, ddof=1) / np.sqrt(trial.shape[0])
# Create a normal distribution based on mean and se
null_norm = sc.norm(control_mean, control_se)
alt_norm = sc.norm(trial_mean, trial_se)
# Calculate the rejection values (X*)
reject_low = null_norm.ppf((1 - ci) / 2)
reject_high = null_norm.ppf(ci + (1 - ci) / 2)
# Calculate power
power_lower = alt_norm.cdf(reject_low)
power_higher = 1 - alt_norm.cdf(reject_high)
power = (power_lower + power_higher) * 100
return power
metrics.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录