%matplotlib inline
import sympy
sympy.init_printing(use_latex=True)
from sympy.abc import x, y, alpha, beta
from sympy import latex
from IPython.display import HTML
def association_table(assocs):
latexed = {}
for key, value in assocs.items():
latexed[key] = latex(value)
latexed['s_total'] = latex(assocs['t_s'] + assocs['f_s'])
latexed['ns_total'] = latex(assocs['t_ns'] + assocs['f_ns'])
return """
<TABLE>
<TR><TH><TH>Significant<TH>Not significant
<TR><TH>True association<TD>${t_s}$<TD>${t_ns}$
<TR><TH>No association<TD>${f_s}$<TD>${f_ns}$
<TR><TH>Total<TD>${s_total}$<TD>${ns_total}$
</TABLE>
""".format(**latexed)
assocs = dict(t_s = x,
t_ns = alpha,
f_s = beta,
f_ns = y)
HTML(association_table(assocs))
Significant | Not significant | |
---|---|---|
True association | $x$ | $\alpha$ |
No association | $\beta$ | $y$ |
Total | $\beta + x$ | $\alpha + y$ |