Skip to content

Instantly share code, notes, and snippets.

@okomestudio
Created May 12, 2014 19:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okomestudio/878b44714833d7a14768 to your computer and use it in GitHub Desktop.
Save okomestudio/878b44714833d7a14768 to your computer and use it in GitHub Desktop.
An example of A/B test using the chi-squared test for independence.
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
"""An example of A/B test using the chi-squared test for independence."""
import numpy as np
import pandas as pd
from scipy.stats import chi2_contingency
def main():
data = pd.io.parsers.read_csv('n10000.csv')
data = data.set_index('version')
observed = data.values
print observed
result = chi2_contingency(observed)
chisq, p = result[:2]
print 'chisq = {}, p = {}'.format(chisq, p)
print
data = pd.io.parsers.read_csv('n40000.csv')
data = data.set_index('version')
observed = data.values
print observed
result = chi2_contingency(observed)
chisq, p = result[:2]
print 'chisq = {}, p = {}'.format(chisq, p)
if __name__ == '__main__':
main()
version not converted converted
A 4514 486
B 4473 527
version not converted converted
A 17998 2002
B 17742 2258
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment