Repository navigation
Keep adjust() values on their rows when the model drops rows - #744
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain, with the residual row-alignment fix covered by regression tests and corresponding documentation and release-note updates.
No open issues 🎉
1 file not reviewed
man/adjust.Rd: Generated file
What changed in this PR
This pull request fixes adjust() so model residuals remain aligned with their original data rows when fitting omits observations, including missing weights and na.exclude.
Changes:
- Maps named residuals back to their source rows and preserves
NAfor omitted rows. - Errors when unnamed residuals cannot be safely aligned.
- Adds regression tests and updates documentation and release notes.
- Documentation should clarify the behavior for unnamed residuals and cases where omitted rows arise from missing input data.
| File | Summary |
|---|---|
tests/testthat/test-adjust.R |
Adds regression coverage for omitted weighted observations and na.exclude. |
R/adjust.R |
Aligns residuals by row name and handles unalignable unnamed residuals; documentation should clarify the resulting error behavior and remediation. |
NEWS.md |
Records the corrected row-alignment behavior. |
man/adjust.Rd |
Updates generated documentation for adjust() row handling. |
Review effort: Lite
strengejacke
approved these changes
Nov 3, 2026
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.
adjust()now passes...to the function that fits the model (#696), so the model can use fewer rows than the complete rows in the data..model_adjust_for()still assumed one residual per complete row, so the values landed on the wrong rows, with only R's "number of items to replace" warning.Before this PR, every value moved up one row, and the last row was filled by recycling. Now row 1 is
NAand the others match the fit's residuals.na.action = na.excludewas misaligned too and is also fixed.The residuals now go on their rows by name.
stan_glmer()residuals have no names, so if their count doesn't match the complete rows, it stops with an error. I found no argument that reaches that error, so it has no test.1.4.1 has no
...inadjust(), so no release has this bug. That's why the existingNEWS.mdbullet changes and there's no new one.