Tables Contingency tables
07 May 2015
Contingency tables & analyses
2x2 tables are commonly used to assess risk in epidemiology. The rows represent a risk factor, like exposure to a disease, or sex. The columns represent an outcome, like infection status, or whether the disease was severe or mild.
Create a 2x2 table
Both rows and columns must be binary. Note that you must tell epipy how you wish the table to be organized by providing a list of values.
import epipy
import pandas as pd
mers_df = epipy.get_data('mers_line_list')
table = epipy.create_2x2(mers_df, row='Sex', 'Health status',
['M', 'F'], ['Dead', 'Alive'])
table returns:
Dead Alive All
M 46 54 101
F 16 44 60
All 70 114 185
Analyze a 2x2 table
2x2 tables are used to calculate odds ratios, relative risk, and chi square tests.
epipy.analyze_2x2(table)
returns:
Odds ratio: 0.57 (95% CI: (0.22, 1.46))
Relative risk: 0.69 (95% CI: (0.38, 1.26))
Attributable risk: -0.126 (95% CI: (-0.34, 0.08))
Attributable risk percent: -44.86% (95% CI: (-43.19, -46.517))
Population attributable risk: -0.089
Population attributable risk percent: -27.84%
Chi square: 2.91278015543
p value: 0.57252592908
Alternatively, you can call each function separately:
epipy.odds_ratio(table)
epipy.relative_risk(table)
epipy.chi2(table)