Skip to content

ENH: Add tF confidence intervals at multiple levels for IV2SLS - #860

Open
soodoku wants to merge 5 commits into
bashtage:mainfrom
finite-sample:feature/tf-confidence-intervals
Open

soodoku wants to merge 5 commits into
bashtage:mainfrom
finite-sample:feature/tf-confidence-intervals

Conversation

@soodoku

@soodoku soodoku commented Nov 2, 2026 •

Copy link
Copy Markdown

Adds IVResults.tf_conf_int(level=0.95, *, method="table") for IV2SLS with one endogenous regressor and one excluded instrument. It supports 18 bundled confidence levels from 75% to 99.99%, and explicit numerical calibration at other levels within that range through the optional tf-inference package.

At 95%, the unbounded-interval boundary is approximately F=3.84145882; F strictly above it gives finite bounds, including F between that boundary and 4. For an estimate of 1, SE of 0.4 and first-stage F=10, the interval is approximately [-0.37214, 2.37214]. Each level has its own calibrated plateau: the 99% plateau critical value is about 2.72549.

The method reuses the fitted coefficient, covariance convention and first-stage regression. Included controls, constant weights, unadjusted or robust covariance (including aliases), and debiased=False are supported. Unsupported configurations raise ValueError; conventional inference is unchanged.

The default uses generated NPZ tables from the Appendix B.3 numerical construction in Lee, McCrary, Moreira and Porter (2022). The roughly 3 MB of bundled data include source revision, MIT license, construction settings, numerical diagnostics and checksums. The reader interpolates the regularized squared critical value, preserving its finite boundary limit, and caches tables after their first load. There is no new mandatory dependency, interpolation across levels, or implicit slow computation. method="compute" explicitly uses tf-inference and caches the calibration by level; its installation and numerical settings are documented.

Calibration uses deterministic integration, a finite nuisance-parameter grid and local searches. The source package records 4,032 held-out checks and comparisons with refined curves. These are numerical validation, not a uniform size proof, a conservative rounding guarantee, or finite-sample coverage guarantees. The procedure remains asymptotic under the single-instrument IV assumptions; no p-value API is introduced.

Validation at 53cc6a0ca5d8653897f432ad9bd38a348e1aab4a:

  • All 106 feature tests pass locally and against the wheel installed outside the checkout. They cover all 18 levels, the exact boundary, finite intervals at F=3.9, hand-calculated 95% and 99% fits, estimator/covariance restrictions, labels and transformations, invalid inputs, checksums, cache behavior, missing optional dependencies, and real 96.3% numerical calibration. Bundled results also match tf-inference at independently sampled F values.
  • The decisive boundary and level tests fail against the prior production implementation and pass after restoration.
  • Full local suite: 23,384 passed, 2,473 skipped and 47 expected failures. The 13 remaining failures match the previous baseline: the existing RandomEffects constant-outcome case and 12 notebooks blocked by the local sandbox's socket policy.
  • Flake8, Black, isort, Ruff and changed API numpydoc checks pass. Mypy retains the same 17 existing errors in five files.
  • The updated guide's 15 executable examples and a warning-free HTML/API build pass. The complete site's theme is locally blocked by its multiprocessing socket requirement.
  • Source distribution and wheel builds pass. Local median critical-value lookup is 2.54 microseconds warm and 0.82 milliseconds with an empty table cache (Python 3.13, macOS ARM64; imports excluded).
  • Azure's Linux/Windows matrix is running for this commit; Codacy and Snyk have passed. GitHub's type-checking, CodeQL and wheel workflows await maintainer approval for the fork contribution.

References: Valid t-Ratio Inference for IV; author manuscript, Appendix B.3; pinned table source and validation.

AI assistance was used for implementation, testing and documentation.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-02T03:49:18.855472Z
We couldn’t complete this review. Comment @codex review to try again.
39ba585 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.47696% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.65%. Comparing base (7fa390b) to head (53cc6a0).

Files with missing lines Patch % Lines
linearmodels/tests/iv/test_tf.py 95.65% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #860      +/-   ##
==========================================
- Coverage   99.68%   99.65%   -0.04%     
==========================================
  Files         199      201       +2     
  Lines       37875    38242     +367     
  Branches     2436     2456      +20     
==========================================
+ Hits        37756    38110     +354     
- Misses         51       64      +13     
  Partials       68       68              
Flag Coverage Δ
adder 99.64% <96.47%> (-0.04%) ⬇️
subtractor 99.64% <96.47%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread linearmodels/iv/results.py Resolved
@soodoku soodoku changed the title ENH: Add conservative 95% tF confidence intervals for IV2SLS ENH: Add tF confidence intervals at multiple levels for IV2SLS Nov 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants