Commit 1a8d89d
feat(smart): compare_estimators method_hints + sensitivity Sprint-B dims + g_computation error compaction
Three smart-layer enhancements closing the remaining Sprint-B
ergonomic gaps, plus five fixes from a fresh-eyes code review.
1. sp.compare_estimators(method_hints={...})
New kwarg forwards per-method kwargs to each estimator when the
shared (data, y, treatment, covariates, id, time, instrument)
signature is too narrow. Enables six Sprint-B methods in batch
comparison:
- proximal — needs {proxy_z, proxy_w}
- msm — needs {time_varying} + id + time
- principal_strat — needs {strata}
- front_door — needs {mediator}
- mediate — needs {mediator}
- mediate_interventional — needs {mediator, tv_confounders?}
_resolve_hints() merges shared + hint per ROADMAP §6:
per-method hints take precedence, UserWarning fires on conflict.
List comparison is set-based (order-insensitive) so a
reordered-but-set-equal list doesn't trigger spurious warnings.
2. sp.sensitivity_dashboard — Sprint-B-aware dimensions
- 'first_stage_f' (proximal): surfaces the IV-weakness check from
model_info as its own dashboard row with F ≥ 10 Stock-Yogo pass
logic.
- 'trim_sweep' (msm): max-stabilized-weight positivity watchdog
against the same 50 threshold as the diagnostic battery.
- 'monotonicity' (principal_strat): monotonicity-violation
fraction, 5% tolerance.
When dimensions= is left at default None, the list now
auto-expands with the matching Sprint-B token so callers don't
need to know the token. Baseline extraction handles
PrincipalStratResult (no .estimate / .params) by pulling the
complier row from .effects by label, not by .iloc[0] — so an
upstream reorder of the effects DataFrame can't silently make
the dashboard report an always-taker effect. Method label
prefers model_info['estimator'] for PSR.
3. sp.g_computation error message compaction
Non-binary D previously dumped the full sorted list of unique
values (~20 KB for n=400 continuous D) which exploded to a
multi-KB UserWarning when compare_estimators wrapped it. The
message now truncates to 5 values + "(N more)" count, filters
NaNs out of the sort (NaN sort order is undefined), and notes
NaN presence separately.
Five code-review findings applied:
- BLOCKER: hint-wins test now verifies the hint VALUE (via a second
run with a different hint set that produces a different estimate),
not just that a warning fired.
- MAJOR: list equality in _resolve_hints is set-based
(reorder-tolerant).
- MAJOR: complier row extraction uses stratum name filter, not
.iloc[0] positional indexing, in both sensitivity.py and
compare.py.
- MINOR: sorted(uniq) in g_computation filters NaN pre-sort and
annotates separately.
- MINOR: sensitivity_dashboard default dimensions auto-expand with
Sprint-B tokens so callers without the explicit token still see
the method-specific rows.
Regression: 200/200 Sprint-B tests pass (12 new this round).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 577f66d commit 1a8d89d
4 files changed
Lines changed: 732 additions & 21 deletions
File tree
- src/statspai
- inference
- smart
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
132 | 147 | | |
133 | 148 | | |
134 | | - | |
| 149 | + | |
| 150 | + | |
135 | 151 | | |
136 | 152 | | |
137 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| 118 | + | |
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
| |||
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
144 | 160 | | |
145 | 161 | | |
146 | 162 | | |
| |||
181 | 197 | | |
182 | 198 | | |
183 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
184 | 238 | | |
185 | 239 | | |
186 | 240 | | |
| |||
279 | 333 | | |
280 | 334 | | |
281 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
282 | 467 | | |
283 | 468 | | |
284 | 469 | | |
| |||
0 commit comments