Skip to content

Commit d0aefae

Browse files
igerberclaude
andcommitted
Reorder solve_logit effective-sample checks: rank reduction before size gate
Move the n_pos <= k identification check AFTER rank-deficient column dropping so that warn/silent modes can drop redundant columns on the positive-weight subset before rejecting. Previously a valid design with one redundant covariate on the effective sample was rejected instead of proceeding with column dropping. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d682bf4 commit d0aefae

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

diff_diff/linalg.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,15 +1217,10 @@ def solve_logit(
12171217
f"outcome class(es). Logistic regression requires both 0 and 1 "
12181218
f"in the effective (positive-weight) sample."
12191219
)
1220-
# Check rank on the effective sample, not the full padded design
1220+
# Check rank deficiency on positive-weight rows FIRST — full design
1221+
# may be full rank due to zero-weight padding. Drop columns before
1222+
# checking sample-size identification.
12211223
X_eff = X_with_intercept[pos_mask]
1222-
if n_pos <= X_eff.shape[1]:
1223-
raise ValueError(
1224-
f"Only {n_pos} positive-weight observation(s) for "
1225-
f"{X_eff.shape[1]} parameters. Cannot identify logistic model."
1226-
)
1227-
# Check rank deficiency on positive-weight rows — full design may
1228-
# be full rank due to zero-weight padding.
12291224
eff_rank_info = _detect_rank_deficiency(X_eff)
12301225
if len(eff_rank_info[1]) > 0:
12311226
n_dropped_eff = len(eff_rank_info[1])
@@ -1247,6 +1242,13 @@ def solve_logit(
12471242
eff_dropped_original = list(eff_rank_info[1])
12481243
X_with_intercept = np.delete(X_with_intercept, eff_rank_info[1], axis=1)
12491244
k = X_with_intercept.shape[1]
1245+
# Check sample-size identification AFTER column dropping
1246+
if n_pos <= k:
1247+
raise ValueError(
1248+
f"Only {n_pos} positive-weight observation(s) for "
1249+
f"{k} parameters (after rank reduction). "
1250+
f"Cannot identify logistic model."
1251+
)
12501252

12511253
# Check rank deficiency once before iterating (on possibly-shrunk matrix)
12521254
rank_info = _detect_rank_deficiency(X_with_intercept)

0 commit comments

Comments
 (0)