Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions R/get_map_estimates.R
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,14 @@ 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,
start = omega$eta,
method = method,
optimizer = optimizer,
control = control,
skip_hessian = skip_hessian_mle,
skip_hessian = skip_hessian,
data = list(
data = data,
sim_object = sim_object,
Expand Down Expand Up @@ -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")) {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-get_map_estimates.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
Loading