Skip to content

Instantly share code, notes, and snippets.

@dinob0t
Last active January 22, 2016 21:42
Show Gist options
  • Save dinob0t/e296f05b30779c9e1f2c to your computer and use it in GitHub Desktop.
Save dinob0t/e296f05b30779c9e1f2c to your computer and use it in GitHub Desktop.
create function
zconf_interval_two_samples
(total_a float, conv_a float, total_b float, conv_b float, alpha float)
--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
-- alpha = alpha value (0.05?)
RETURNS float
--OUTPUT:
--Returns confidence interval
STABLE
AS $$
from scipy.stats import norm
import numpy as np
p1 = conv_a/total_a
p2 = conv_a/total_b
se = np.sqrt(p1*(1-p1)/total_a + p2*(1-p2)/total_b)
z_critical = norm.ppf(1-0.5*alpha)
return p2-p1+z_critical*se
$$LANGUAGE plpythonu;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment