From 968b9177e34537a7ebd27522a9a42823d5586145 Mon Sep 17 00:00:00 2001 From: jasmineirx Date: Tue, 2 Jun 2026 16:25:55 -0400 Subject: [PATCH] minimal change to undo breaking change in PR#59 --- R/get_map_estimates.R | 17 +++++------------ tests/testthat/test-get_map_estimates.R | 1 + 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/R/get_map_estimates.R b/R/get_map_estimates.R index dae07b5..ae7a18c 100755 --- a/R/get_map_estimates.R +++ b/R/get_map_estimates.R @@ -299,10 +299,6 @@ get_map_estimates <- function( likelihood = like ) } else { - # When residuals=TRUE, the FOCE Jacobian computed in calc_residuals - # provides both CWRES and the Hessian/vcov, so we can skip the more - # expensive numDeriv::hessian here. - skip_hessian_mle <- skip_hessian || residuals output <- tryCatch({ fit <- mle_wrapper( ll_func, @@ -310,7 +306,7 @@ get_map_estimates <- function( method = method, optimizer = optimizer, control = control, - skip_hessian = skip_hessian_mle, + skip_hessian = skip_hessian, data = list( data = data, sim_object = sim_object, @@ -436,14 +432,11 @@ get_map_estimates <- function( } ## Add variance-covariance matrix to output object. - ## When residuals were computed, the FOCE vcov from the Jacobian is - ## preferred over numDeriv::hessian (faster, same FOCE approximation). - vcov_source <- obj$fit$vcov - if (!is.null(obj$foce_vcov)) { - vcov_source <- obj$foce_vcov - } + ## foce_vcov (computed from the FOCE Jacobian) is stored for diagnostics + ## but not used as the primary vcov source — it has known issues with + ## observation weights and proportional error that need to be fixed first. obj$vcov_full <- get_varcov_matrix( - vcov_source, + obj$fit$vcov, fallback = omega$full ) if(inherits(obj$vcov_full, "matrix")) { diff --git a/tests/testthat/test-get_map_estimates.R b/tests/testthat/test-get_map_estimates.R index dfdcebf..e59dc64 100644 --- a/tests/testthat/test-get_map_estimates.R +++ b/tests/testthat/test-get_map_estimates.R @@ -596,6 +596,7 @@ test_that("FOCE vcov is positive definite even when numDeriv Hessian would fail" expect_false(is.null(fit$foce_vcov)) expect_true(PKPDsim::is_positive_definite(fit$foce_vcov)) expect_true(PKPDsim::is_positive_definite(fit$vcov_full)) + skip("Skipping until weights are added to FOCE") expect_equal(fit$vcov_full, fit$foce_vcov) })