Skip to content

ivsfm: reach the order-condition message for instruments = ~1 on R < 4.4 - #47

Merged
davidhbernstein merged 2 commits into
mainfrom
fix/ivsfm-no-instruments
Oct 1, 2026
Merged

davidhbernstein merged 2 commits into
mainfrom
fix/ivsfm-no-instruments

Conversation

@davidhbernstein

Copy link
Copy Markdown
Owner

On R before 4.4, ivsfm(..., instruments = ~1) stopped with an unrelated internal error instead of the order-condition message.

Mechanism

ivsfm() builds the excluded-instrument matrix as model.matrix(reformulate(inst_v), dsub)[, -1].

  • With instruments = ~1, inst_v is empty.
  • On R 4.3 and earlier, stats::reformulate(character(0)) throws its own error: "'termlabels' must be a character vector of length at least one".
  • That error fires before the check that should run, which stops with "0 excluded instrument(s) for 1 endogenous variable(s). The order condition needs…".
  • Only R 4.4 and later reach that message.

DESCRIPTION declares R (>= 4.0.0), so R 4.0–4.3 are supported, and on them this is a defect.

CI's oldest R is oldrel-1, which is 4.4 or later, so CI never saw this. In this sandbox (R 4.3.3), the existing test "ivsfm rejects malformed calls" fails on main at test-ivsfm.R:189.

Fix

When there are no excluded instruments, ivsfm() now builds a zero-column instrument matrix directly, so the order-condition check runs and gives its own message.

Tests

On R 4.3.3, the existing assertion at test-ivsfm.R:189 (expect_error(ivsfm(y ~ x1 + x2, ~x2, ~1, d), "excluded instrument")) fails on main and passes here. That test is the failing-then-passing evidence, so no new test was needed.

test-ivsfm.R, test-ivsfm-tails.R and test-endogeneity-test.R, run with test_dir(load_package = "installed"), all pass here with 0 failures.

NEWS entry under ## Bug fixes.

🤖 Generated with Claude Code

https://claude.ai/code/session_014oJL17ewiahA8pWbemnqNp


Generated by Claude Code

claude added 2 commits October 1, 2026 04:02
reformulate(character(0)) is an error before R 4.4, so with no excluded
instruments ivsfm() failed inside model.matrix() instead of reporting the
order condition. Build a zero-column instrument matrix directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014oJL17ewiahA8pWbemnqNp
@davidhbernstein
davidhbernstein merged commit c2bf00b 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