Skip to content

get_df() gains df_per_obs support for mmrm - #1214

Merged
vincentarelbundock merged 2 commits into
easystats:mainfrom
vincentarelbundock:mmrm-df-per-obs
Aug 20, 2026
Merged

get_df() gains df_per_obs support for mmrm#1214
vincentarelbundock merged 2 commits into
easystats:mainfrom
vincentarelbundock:mmrm-df-per-obs

Conversation

@vincentarelbundock

Copy link
Copy Markdown
Contributor

get_df.mmrm() ignored df_per_obs and always returned one DF per coefficient, so callers that need per-observation DF — such as confidence intervals around predictions — got a length-p vector instead of length-nrow(data). It now dispatches to .mmrm_df_per_obs(), which loops mmrm::df_1d() over the model matrix rows, mirroring .satterthwaite_kr_df_per_obs() for lmerMod.

Unlike lmerMod, the new branch does not condition on type: mmrm fixes the DF method when the model is fitted, so type cannot select between Satterthwaite and Kenward-Roger. Validated against emmeans.

@strengejacke

Copy link
Copy Markdown
Member

Looks good to me, let copilot double check

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.

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 via mmrm::df_1d() over the model matrix rows.
  • Update get_df.mmrm() to honor df_per_obs (and optional data) and return a length-nrow(data) DF vector when requested.
  • Add test coverage validating lengths and matching emmeans DF for both Satterthwaite and Kenward-Roger-fitted mmrm models, 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 thread NEWS.md
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@vincentarelbundock maybe the only minor thing to be resolved, else it can be merged.

@vincentarelbundock
vincentarelbundock merged commit 0ced458 into easystats:main Aug 20, 2026
14 of 18 checks passed
@vincentarelbundock

Copy link
Copy Markdown
Contributor Author

Thanks!

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