Skip to content

Commit 2c6187e

Browse files
roninsightrxclaude
andcommitted
Add test verifying FOCE vcov matches numDeriv Hessian vcov
Runs the same fit with both methods and checks the variance-covariance matrix values are equal within 1% tolerance. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 07556e6 commit 2c6187e

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/testthat/test-get_map_estimates.R

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,42 @@ test_that("Precision / uncertainty of MAP estimates is calculated", {
886886
expect_true(all(fit$vcov != 0))
887887
})
888888

889+
test_that("FOCE vcov matches numDeriv Hessian vcov", {
890+
dat <- read.table(file=test_path("nm", "pktab1"), skip=1, header=TRUE)
891+
colnames(dat)[1:3] <- c("id", "t", "y")
892+
dat <- dat[dat$id <= 20,]
893+
par <- list(CL = 7.67, V = 97.7)
894+
omega <- c(0.0406,
895+
0.0623, 0.117)
896+
reg <- PKPDsim::new_regimen(amt = 100000, times=c(0, 24), type="bolus")
897+
data1 <- dat[dat$id == 1 & dat$EVID == 0,]
898+
899+
# FOCE vcov (residuals=TRUE, default)
900+
fit_foce <- get_map_estimates(
901+
parameters = par,
902+
model = mod,
903+
regimen = reg,
904+
omega = omega,
905+
weights = rep(1, nrow(data1)),
906+
error = list(prop = 0, add = sqrt(1.73E+04)),
907+
data = data1
908+
)
909+
910+
# numDeriv vcov (residuals=FALSE)
911+
fit_numderiv <- get_map_estimates(
912+
parameters = par,
913+
model = mod,
914+
regimen = reg,
915+
omega = omega,
916+
weights = rep(1, nrow(data1)),
917+
error = list(prop = 0, add = sqrt(1.73E+04)),
918+
data = data1,
919+
residuals = FALSE
920+
)
921+
922+
expect_equal(fit_foce$vcov, fit_numderiv$vcov, tolerance = 0.01)
923+
})
924+
889925
test_that("Floating point precision issues don't raise warning", {
890926
# the output of PKPDsim::sim will have different floating point precision
891927
# values for the time column relative to the tdms$t column due to how the

0 commit comments

Comments
 (0)