Created
June 1, 2017 17:14
-
-
Save jdwyah/d080c0e706074582bcd553b9500ec309 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function | |
public.significance(control_size integer, | |
control_conversion integer, | |
experiment_size integer, | |
experiment_conversion integer) | |
returns float | |
stable as $$ | |
from scipy.stats import norm | |
def standard_error(sample_size, successes): | |
p = float(successes) / sample_size | |
return ((p * (1 - p)) / sample_size) ** 0.5 | |
def zscore(size_a, successes_a, size_b, successes_b): | |
p_a = float(successes_a) / size_a | |
p_b = float(successes_b) / size_b | |
se_a = standard_error(size_a, successes_a) | |
se_b = standard_error(size_b, successes_b) | |
numerator = (p_b - p_a) | |
denominator = (se_a ** 2 + se_b ** 2) ** 0.5 | |
return numerator / denominator | |
def percentage_from_zscore(zscore): | |
return norm.sf(zscore) | |
exp_zscore = zscore(control_size, control_conversion, | |
experiment_size, experiment_conversion) | |
return percentage_from_zscore(exp_zscore) | |
$$ language plpythonu; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment