RXR-3164: Pass observation-level weights to covariance matrix calcs, and re-activate FOCE-type vcov#61
Merged
Conversation
jasmineirx
reviewed
Jun 30, 2026
jasmineirx
left a comment
Contributor
There was a problem hiding this comment.
lgtm, a couple suggestions for better tests
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes variance–covariance (vcov) computation for MAP estimation by ensuring per-observation weights are incorporated into the FOCE-style Hessian/vcov, and by re-preferencing the FOCE-derived vcov (aligned with NONMEM’s FOCE-I behavior) for speed and positive-definiteness.
Changes:
- Thread per-observation
weightsinto FOCE Hessian/vcov computation (calc_cwres()viacalc_residuals()), and prefer FOCE vcov inget_map_estimates(). - Correct numDeriv-based vcov scaling in
mle_wrapper()for an objective on the-2*logLikscale. - Add/adjust tests to validate FOCE vcov vs NONMEM reference values and to ensure weights affect vcov curvature.
Reviewed changes
Copilot reviewed 7 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/testthat/test-nonmem-vcov-comparison.R | Adds a hard-coded NONMEM cross-check for FOCE vcov under unit vs weighted observations. |
| tests/testthat/test-get_map_estimates.R | Updates MAP expectations and adds a FOCE vs numDeriv vcov comparison. |
| tests/testthat/test-calc_cwres.R | Adds a focused regression test that weights influence FOCE vcov but not CWRES. |
| R/mle_wrapper.R | Adjusts vcov scaling to match a -2*logLik objective. |
| R/get_map_estimates.R | Skips numDeriv Hessian when residuals/FOCE Jacobian is available; prefers FOCE vcov source. |
| R/calc_residuals.R | Forwards weights into calc_cwres() so FOCE Hessian curvature matches the weighted OFV. |
| R/calc_cwres.R | Applies per-observation weights in the FOCE Hessian likelihood term. |
| man/parse_residuals_from_predictions.Rd | Updates weights parameter documentation. |
| man/calc_residuals.Rd | Updates weights parameter documentation. |
| man/calc_cwres.Rd | Documents new weights argument in calc_cwres(). |
Files not reviewed (3)
- man/calc_cwres.Rd: Generated file
- man/calc_residuals.Rd: Generated file
- man/parse_residuals_from_predictions.Rd: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ure readers are not confused
jasmineirx
approved these changes
Jul 9, 2026
jasmineirx
left a comment
Contributor
There was a problem hiding this comment.
lgtm. thanks for adding the NONMEM equivalence test
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.
There were two issues with the covariance matrix computation:
Note: PR to update the handful of failing f-tests. After merging this PR, immediately rerun f-tests there.