Skip to content

Keep adjust() values on their rows when the model drops rows - #744

Merged
jmgirard merged 1 commit into
mainfrom
hotfix-adjust-dropped-rows
Nov 3, 2026
Merged

jmgirard merged 1 commit into
mainfrom
hotfix-adjust-dropped-rows

Conversation

@jmgirard

@jmgirard jmgirard commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

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.

d <- mtcars[c("mpg", "wt")]
adjust(d, effect = "wt", select = "mpg", weights = c(NA, rep(1, 31)))

Before this PR, every value moved up one row, and the last row was filled by recycling. Now row 1 is NA and the others match the fit's residuals. na.action = na.exclude was 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 ... in adjust(), so no release has this bug. That's why the existing NEWS.md bullet changes and there's no new one.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 NA for 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

@jmgirard
jmgirard merged commit cd45bc4 into main Nov 3, 2026
28 checks passed
@jmgirard
jmgirard deleted the hotfix-adjust-dropped-rows branch November 3, 2026 19:14
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.

3 participants