relative_risk_from_table#

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

Compute the (log) relative risk directly from a ContingencyTable

Use this instead of relative_risk() 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 relative risk

Returns:

The relative risk (or log relative risk if use_log is True). Dimensions of the cell counts are preserved.

Return type:

DataArray

References

[Agresti2022]

Examples:

The relative risk of a heart attack when taking a placebo relative to taking aspirin, from [Agresti2022]. Those taking a placebo were 1.82 times as likely to suffer a heart attack as those taking aspirin.

>>> 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(relative_risk_from_table(table, False))
1.82