augment() can recompute rank() terms after omitting rows, producing values inconsistent with fitted()

Open
#587 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
r
Domain
backend

Research direction

Start by reading the augment() implementation and its tests for newdata = NULL, then trace how missing outcomes are omitted before predictions are computed. Add a reproducible case using a formula with rank() and missing outcomes; done means .fitted matches fitted(fit) for the observations used in the model, with residuals aligned to those observations.

Written by the indexing model from the issue text.

Description

Hi @danielinteractive, opening this separately as you suggested in #585.

While checking that fix, we noticed that augment(fit) can return .fitted values that differ from fitted(fit) when the formula includes rank(). Removing rows with missing outcomes before prediction changes the ranks of the remaining observations, so the predictions use different predictor values from those used to fit the model.

We saw this on the unmodified base too. With newdata = NULL, we would expect augment() to return the fitted values for the observations used in the model, alongside their matching residuals.

We’d be happy to look into this and put together a small reproducible example and a regression test. We’ll make sure the changes and tests are reviewed by a human before opening any PR.

Algoria

Dominant language
R
Stars
162
Forks
29
Avg merge
1d 9h
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openpharma/mmrm

All issues in openpharma/mmrm

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.