Ordinal association: an unbounded profile interval counts as separation

This commit is contained in:
2026-12-03 23:27:28 -06:00
parent aab20683aa
commit d337542ede
2 changed files with 8 additions and 0 deletions
+2
View File
@@ -447,6 +447,8 @@ def ordinal(t: pd.DataFrame, outcome: str, predictor: str, adjust, high: float)
return {**out, "reason": "does not converge (separation)"} return {**out, "reason": "does not converge (separation)"}
profile = lambda v: -_fit_ordinal(X, yk, K, fixed=(0, v))[1] # noqa: E731 profile = lambda v: -_fit_ordinal(X, yk, K, fixed=(0, v))[1] # noqa: E731
lo, hi = _interval(profile, beta[0], -nll, 0.1) lo, hi = _interval(profile, beta[0], -nll, 0.1)
if not (np.isfinite(lo) and np.isfinite(hi)):
return {**out, "reason": "does not converge (separation)"}
p = float(stats.chi2.sf(max(2 * (-nll - profile(0.0)), 0.0), 1)) p = float(stats.chi2.sf(max(2 * (-nll - profile(0.0)), 0.0), 1))
state = _ordinal_scoring(par, levels, high) state = _ordinal_scoring(par, levels, high)
return _summary("ordinal", len(d), beta[0], lo, hi, p, design, state, levels=K) return _summary("ordinal", len(d), beta[0], lo, hi, p, design, state, levels=K)
+6
View File
@@ -26,6 +26,12 @@ def test_ordinal_on_monotone_trend():
assert a.ordinal(frame, "level", "z", (), high=2)["odds_ratio"] > 1 assert a.ordinal(frame, "level", "z", (), high=2)["odds_ratio"] > 1
def test_ordinal_separated_binary_predictor():
frame = pd.DataFrame({"z": [0] * 8 + [1] * 8, "level": [0, 1] * 4 + [3, 4] * 4})
fit = a.ordinal(frame, "level", "z", (), high=3)
assert fit["reason"] == "does not converge (separation)"
def test_pairs_by_level(): def test_pairs_by_level():
item = a.pairs("item") item = a.pairs("item")
spikes = [p for p in item if p["biomarker"] == "spikes"] spikes = [p for p in item if p["biomarker"] == "spikes"]