ivsfm: reach the order-condition message for instruments = ~1 on R < 4.4 - #47
Merged
Merged
Conversation
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
# Conflicts: # NEWS.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 asmodel.matrix(reformulate(inst_v), dsub)[, -1].instruments = ~1,inst_vis empty.stats::reformulate(character(0))throws its own error: "'termlabels' must be a character vector of length at least one".DESCRIPTIONdeclaresR (>= 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 attest-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.Randtest-endogeneity-test.R, run withtest_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