get_df() gains df_per_obs support for mmrm - #1214
Merged
vincentarelbundock merged 2 commits intoAug 20, 2026
Merged
Conversation
Member
|
Looks good to me, let copilot double check |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes get_df.mmrm() so it can return per-observation degrees of freedom (df_per_obs = TRUE), enabling correct DF vectors for downstream consumers such as prediction confidence intervals.
Changes:
- Add
.mmrm_df_per_obs()helper that computes per-row DF viammrm::df_1d()over the model matrix rows. - Update
get_df.mmrm()to honordf_per_obs(and optionaldata) and return a length-nrow(data)DF vector when requested. - Add test coverage validating lengths and matching
emmeansDF for both Satterthwaite and Kenward-Roger-fittedmmrmmodels, plus a NEWS entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/testthat/test-mmrm.R | Adds tests for df_per_obs behavior and validates against emmeans. |
| R/get_predicted_ci.R | Introduces .mmrm_df_per_obs() for computing per-observation DF. |
| R/get_df.R | Routes get_df.mmrm() to .mmrm_df_per_obs() when df_per_obs = TRUE. |
| NEWS.md | Documents the new df_per_obs support for mmrm. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+12
to
+14
| * `get_df()` now supports the `df_per_obs` argument for models of class `mmrm`, | ||
| returning one degree of freedom per row of `data` instead of one per | ||
| coefficient, using the method chosen when fitting the model. |
Member
There was a problem hiding this comment.
@vincentarelbundock maybe the only minor thing to be resolved, else it can be merged.
Contributor
Author
|
Thanks! |
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.
get_df.mmrm()ignoreddf_per_obsand always returned one DF per coefficient, so callers that need per-observation DF — such as confidence intervals around predictions — got a length-pvector instead of length-nrow(data). It now dispatches to.mmrm_df_per_obs(), which loopsmmrm::df_1d()over the model matrix rows, mirroring.satterthwaite_kr_df_per_obs()forlmerMod.Unlike
lmerMod, the new branch does not condition ontype:mmrmfixes the DF method when the model is fitted, sotypecannot select between Satterthwaite and Kenward-Roger. Validated againstemmeans.