Drug-Safety Agent on Databricks · Purpose · The 2x2 table
One real example: the 2x2 table
Every signal check starts with four numbers arranged in a two-by-two box. The question is simple: among reports that mention this drug, is the side effect more common than among reports that mention other drugs?
The ratio. Among lisinopril reports, 7,015 out of 316,833 mention angioedema. Among all other reports, 37,265 out of 20,737,326 do. Dividing the first share by the second gives the proportional reporting ratio (PRR): 12.3. Angioedema is reported about 12 times as often with lisinopril as with other drugs.
The screen. A common rule of thumb flags a pair when it has at least 3 reports and a PRR of at least 2. This pair screens as a signal: True. The odds-ratio version (ROR) says 12.6, with a 95% interval of 12.3 to 12.9.
What it does not say. Reports are voluntary and incomplete, and a drug that is used by many people collects many reports. So a high ratio is a reason to look, not proof. Here the label already warns about angioedema (yes, label version 20261001), so this is a known effect and not a new finding. Telling those two apart is exactly what the label check is for.
The real code
Cut from the repository each time this site is built, so it always matches what runs. Each header names the file and the line it was cut from.
src/drugsafety/stats.py:13The four counts@dataclass(frozen=True)
class Table:
a: int
b: int
c: int
d: int
def __post_init__(self) -> None:
if min(self.a, self.b, self.c, self.d) < 0:
raise ValueError("counts cannot be negative")src/drugsafety/stats.py:25The proportional reporting ratiodef prr(t: Table) -> float | None:
"""Proportional reporting ratio: (a/(a+b)) / (c/(c+d)). None when undefined."""
if t.a + t.b == 0 or t.c + t.d == 0 or t.c == 0:
return None
return (t.a / (t.a + t.b)) / (t.c / (t.c + t.d))src/drugsafety/stats.py:48The screen: at least 3 reports and a PRR of at least 2def is_signal(t: Table, min_cases: int = 3, min_prr: float = 2.0) -> bool:
"""Evans-style screen: at least `min_cases` reports and PRR >= `min_prr`. A reason to look, not proof."""
p = prr(t)
return t.a >= min_cases and p is not None and p >= min_prr