relativeRisk
Computes the relative risk with a log-based confidence interval for a 2×2 contingency table.
The relative risk (also called the risk ratio) compares the probability of the outcome in the exposed group to the probability in the unexposed group. A value of 1.0 means equal risk, values above 1.0 indicate higher risk in the first (exposed) group, and values below 1.0 indicate lower risk. Unlike the odds ratio, the relative risk has a direct probabilistic interpretation and is preferred when the outcome is common.
For a table [[a, b], [c, d]], the relative risk is (a / (a + b)) / (c / (c + d)). The confidence interval is constructed on the log scale using the standard error of log(RR) and exponentiated back. When the first cell in either row is zero, the confidence interval is (NaN, NaN) because the log transform is undefined.
Example:
val table = arrayOf(intArrayOf(10, 20), intArrayOf(30, 40))
val result = relativeRisk(table, confidenceLevel = 0.95)
result.estimate // 0.7778 (exposed group has lower risk)
result.ci // (0.438, 1.381) log-based 95% CIReturn
a RiskEstimate containing the relative risk and its log-based confidence interval.
Parameters
a 2×2 contingency table with non-negative integer counts.
the confidence level for the log-based interval. Must be in (0, 1). Defaults to 0.95 (95%).
See also
for the ratio of odds rather than probabilities.