Last active
January 22, 2016 21:34
-
-
Save dinob0t/2613676dce3c7f2f9cf7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 function | |
ztest_proportion_two_samples | |
(total_a float, conv_a float, total_b float, conv_b float, one_sided boolean) | |
--INPUTS: | |
-- total_a = total number that saw A | |
-- conv_a = converters for version A | |
-- total_b = total number that saw B | |
-- conv_b = converters for version B | |
-- one_sided = one or two sided test | |
RETURNS float | |
--OUTPUT: | |
--Returns p value | |
STABLE | |
AS $$ | |
import numpy as np | |
from scipy.stats import norm | |
p1 = conv_a/total_a | |
p2 = conv_b/total_b | |
p = (conv_a+conv_b)/(total_a+total_b) | |
se = p*(1-p)*(1/total_a+1/total_b) | |
se = np.sqrt(se) | |
z = (p1-p2)/se | |
p = 1-norm.cdf(abs(z)) | |
p *= 2-one_sided # if not one_sided: p *= 2 | |
return p | |
$$LANGUAGE plpythonu; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment