Skip to content

ivsfm: refuse uhet for C2SLS instead of silently ignoring it - #46

Merged
davidhbernstein merged 1 commit into
mainfrom
fix/c2sls-uhet
Oct 1, 2026
Merged

davidhbernstein merged 1 commit into
mainfrom
fix/c2sls-uhet

Conversation

@davidhbernstein

Copy link
Copy Markdown
Owner

ivsfm(model_name = "C2SLS", uhet = ~q) returned the homoskedastic 2016 fit as if uhet had not been given. This PR makes it an error.

Mechanism

C2SLS (APS 2016, Section 4.1) does three things:

  1. It runs 2SLS.
  2. It recovers σ_u and σ_v from the residuals' second and third moments.
  3. It shifts the intercept by √(2/π)·σ̂_u.

None of these steps involves environmental variables. The C2SLS branch of ivsfm() never reads Q, the uhet design matrix. But uhet was accepted for every model_name. The only places that read Q are the IVLIML/IVCF likelihood and its JLMS. So a user who asked C2SLS for the APS (2017) model got the 2016 one, with no warning and no delta_ rows.

Measured

On main (1c7d78e) I ran a sample with n = 600 and σ_u,i = exp(0.5 q_i). The out matrices with and without uhet = ~q were identical, and identical(a$jlms, b$jlms) was TRUE.

Fix

Supplying uhet with "C2SLS" is now an error that points to "IVLIML" or "IVCF". Those two estimate δ, and an existing test checks that they recover it. man/ivsfm.Rd now says this in the uhet argument. \usage is unchanged, and tools::checkRd is clean.

Tests

test-ivsfm.R adds "C2SLS refuses uhet rather than ignoring it". It fails on main and passes here.

I ran test-ivsfm*.R and test-endogeneity-test.R with test_dir(load_package = "installed") on R 4.3.3, on main and on this branch. The results are the same apart from the new test.

One failure appears on both: "ivsfm rejects malformed calls" (line 189). With instruments = ~1, R 4.3's stats::reformulate(character(0)) errors before the "excluded instrument" message is reached. The package declares R (>= 4.0.0), so this is a real defect on older R, but it is not this PR's. I'll handle it separately.

NEWS entry under ## Bug fixes.

🤖 Generated with Claude Code

https://claude.ai/code/session_014oJL17ewiahA8pWbemnqNp


Generated by Claude Code

C2SLS is 2SLS with a homoskedastic moment correction and has no delta to
estimate. It accepted `uhet` and returned the homoskedastic fit unchanged --
same coefficients, same jlms, no delta_ rows -- so asking for the APS (2017)
model returned the 2016 one without a word. Now an error pointing to IVLIML
or IVCF.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014oJL17ewiahA8pWbemnqNp
@davidhbernstein
davidhbernstein merged commit 3e36e22 into main Oct 1, 2026
5 checks passed
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