odds_ratio_from_table#

rojak.turbulence.metrics.odds_ratio_from_table(table, use_log)[source]#

Compute the (log) sample odds ratio directly from a ContingencyTable

Use this instead of sample_odds_ratio() when the cell counts have already been tabulated, e.g. from counts accumulated per chunk rather than from binary arrays. Infinite values, which arise when one of the cell counts is zero, are masked out with NaN.

Parameters:
  • table (ContingencyTable) – Contingency table of cell counts, where n_11 is the count of cases with both the exposure and the outcome present (see contingency_table())

  • use_log (bool) – If True, returns the natural logarithm of the odds ratio

Returns:

The sample odds ratio (or log odds ratio if use_log is True). Dimensions of the cell counts are preserved.

Return type:

DataArray

References

[Agresti2022]

Examples:

The odds of a heart attack when taking a placebo relative to taking aspirin, from [Agresti2022]

>>> table = ContingencyTable(
...     n_00=xr.DataArray(10933), n_01=xr.DataArray(5 + 99), n_10=xr.DataArray(10845), n_11=xr.DataArray(18 + 171)
... )
>>> float(odds_ratio_from_table(table, False))
1.83
>>> float(odds_ratio_from_table(table, True))
0.605