Skip to content

Instantly share code, notes, and snippets.

@mgk
Created November 13, 2015 17:42
Show Gist options
  • Save mgk/f0b2a4efe4378c70377b to your computer and use it in GitHub Desktop.
Save mgk/f0b2a4efe4378c70377b to your computer and use it in GitHub Desktop.
chi squared test generated uncounted data for smoking example
#!/usr/bin/env/python
# Generate uncounted data for this example:
#http://www.r-tutor.com/elementary-statistics/goodness-fit/chi-squared-test-independence
# python make-smoking-uncounted-data.py < uncounted-data.csv
#
# R:
# chisq.test(table(read.csv("uncounted-data.csv")))
data = {
'Heavy': { 'Frequent': 7, 'None': 1, 'Some': 3},
'Never': { 'Frequent': 87, 'None': 18, 'Some': 84},
'Occas': { 'Frequent': 12, 'None': 3, 'Some': 4},
'Regul': { 'Frequent': 9, 'None': 1, 'Some': 7},
}
print("Smoke,Exercise")
for smoking, exercise in data.items():
for e, count in exercise.items():
for i in range(count):
print('{},{}'.format(smoking, e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment