From 6d3e8e1a83f5483f55d97a3bd602a3109defb432 Mon Sep 17 00:00:00 2001 From: jasmineirx Date: Thu, 19 Nov 2026 14:58:12 -0500 Subject: [PATCH 1/5] Fix docs describing the `ls` estimation method README.md and CLAUDE.md described `ls` as "a special case of MAP Bayesian with (almost) fully flat prior", but get_map_estimates() actually swaps in calc_ofv_ls(), an objective function with no prior/omega term at all, and forces error = list(prop = 0, add = 1) regardless of user input (R/get_map_estimates.R). That description actually matches `type = "pls"` (parse_weight_prior.R), which the docs had mislabeled as `map_flat_prior` - not a real argument value. Co-Authored-By: Claude Sonnet 5 --- CLAUDE.md | 6 +++--- README.md | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 7d9b60a..2a5d3e4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -34,11 +34,11 @@ remotes::install_github("InsightRX/PKPDsim") ### Estimation Methods -The main entry point is `get_map_estimates()` (`R/get_map_estimates.R`), which supports five estimation methods via the `method` argument: +The main entry point is `get_map_estimates()` (`R/get_map_estimates.R`), which supports three estimation methods via the `type` argument (`method` is a separate argument that selects the `optim()` algorithm, e.g. `BFGS`): - `map` — standard MAP Bayesian with empirical Bayes (default) -- `map_flat_prior` — MAP with flattened priors (reduced shrinkage) -- `ls` — Least squares (nearly-flat MAP priors) +- `pls` — MAP with a flattened prior fixed internally to a small value (reduced shrinkage, not controlled by `weight_prior`) +- `ls` — least squares; has no prior/omega term in the objective at all (not a flat-prior MAP special case) and forces the error model to `add = 1, prop = 0` ### Estimation Pipeline diff --git a/README.md b/README.md index 6175250..5fdd9f8 100755 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ MAP Bayesian fitting for PK(PD) models. ## Description -This R library implements various methods for fitting of individual PK(PD) data. For simulation of PK(PD) profiles it uses the `PKPDsim` [package](https://github.com/insightrx/pkpdsim). The following estimation methods are implemented and available in the `get_map_estimates` function: +This R library implements various methods for fitting of individual PK(PD) data. For simulation of PK(PD) profiles it uses the `PKPDsim` [package](https://github.com/insightrx/pkpdsim). The following estimation methods are implemented and available in the `get_map_estimates` function via the `type` argument: -- `map`: MAP Bayesian: standard maximum a priori estimation of empirical Bayes estimates -- `map_flat_prior`: MAP Bayesian with flat prior: reduced weight of prior distribution, i.e. will put more trust in the data and hence reduce shrinkage (user can control the weighting). -- `ls`: Least Squares: not *truly* least squares but rather special case of MAP Bayesian with flat priors, i.e. with (almost) fully flat prior. +- `map`: MAP Bayesian: standard maximum a priori estimation of empirical Bayes estimates. +- `pls`: MAP Bayesian with a flattened prior: the prior weight is fixed internally to a small value (regardless of the `weight_prior` argument), putting more trust in the data and reducing shrinkage relative to `map`. +- `ls`: Least squares: unlike `pls`, this is *not* a flat-prior special case of MAP. The objective function has no prior/omega term at all, and the residual error model is forced to `add = 1, prop = 0` regardless of the `error` argument, so it minimizes unweighted squared residuals. ## Installation From 4ef4e5d59320afe9740db0f69ec022a785df74f5 Mon Sep 17 00:00:00 2001 From: jasmineirx Date: Thu, 19 Nov 2026 15:08:41 -0500 Subject: [PATCH 2/5] clearer wording --- CLAUDE.md | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 2a5d3e4..0237706 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -38,7 +38,7 @@ The main entry point is `get_map_estimates()` (`R/get_map_estimates.R`), which s - `map` — standard MAP Bayesian with empirical Bayes (default) - `pls` — MAP with a flattened prior fixed internally to a small value (reduced shrinkage, not controlled by `weight_prior`) -- `ls` — least squares; has no prior/omega term in the objective at all (not a flat-prior MAP special case) and forces the error model to `add = 1, prop = 0` +- `ls` — least squares; has no prior/omega term in the objective at all and forces the error model to `add = 1, prop = 0` ### Estimation Pipeline diff --git a/README.md b/README.md index 5fdd9f8..3be65b5 100755 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ MAP Bayesian fitting for PK(PD) models. This R library implements various methods for fitting of individual PK(PD) data. For simulation of PK(PD) profiles it uses the `PKPDsim` [package](https://github.com/insightrx/pkpdsim). The following estimation methods are implemented and available in the `get_map_estimates` function via the `type` argument: -- `map`: MAP Bayesian: standard maximum a priori estimation of empirical Bayes estimates. -- `pls`: MAP Bayesian with a flattened prior: the prior weight is fixed internally to a small value (regardless of the `weight_prior` argument), putting more trust in the data and reducing shrinkage relative to `map`. +- `map`: MAP Bayesian: standard maximum a priori estimation of empirical Bayes estimates. For MAP estimation with flattened priors, please use the `weight_prior` argument. +- `pls`: An approximate implementation of penalized least squares, or more precisely, MAP Bayesian with a flattened prior. The prior weight is fixed internally to a very small value (regardless of the `weight_prior` argument). - `ls`: Least squares: unlike `pls`, this is *not* a flat-prior special case of MAP. The objective function has no prior/omega term at all, and the residual error model is forced to `add = 1, prop = 0` regardless of the `error` argument, so it minimizes unweighted squared residuals. ## Installation From 1dc0a5dac84210cf20b39deb21469c3cec50df0d Mon Sep 17 00:00:00 2001 From: jasmineirx Date: Thu, 19 Nov 2026 19:19:36 -0500 Subject: [PATCH 3/5] ensure only supported is passed --- R/get_map_estimates.R | 6 +++-- tests/testthat/test-get_map_estimates.R | 31 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/R/get_map_estimates.R b/R/get_map_estimates.R index 9f29bed..c8556f5 100755 --- a/R/get_map_estimates.R +++ b/R/get_map_estimates.R @@ -49,7 +49,7 @@ #' such as `Nelder-Mead` to avoid estimation failures. #' @param control list of options passed to `optim()` function #' @param allow_obs_before_dose allow observation before first dose? -#' @param type estimation type, options are `map` and `ls` +#' @param type estimation type, one of `map` (default), `pls`, or `ls` #' @param cols column names #' @param residuals show residuals? This requires an additional simulation so #' will be slightly slower. @@ -123,7 +123,7 @@ get_map_estimates <- function( method = "BFGS", control = list(reltol = 1e-5), allow_obs_before_dose = FALSE, - type = "map", + type = c("map", "pls", "ls"), cols = list(x = "t", y = "y"), residuals = TRUE, verbose = FALSE, @@ -131,6 +131,8 @@ get_map_estimates <- function( skip_hessian = FALSE, output_include = list(covariates = FALSE, parameters = FALSE)) { + type <- match.arg(type) + ## get prior weight for scaling of variance term weight_prior_var <- parse_weight_prior(weight_prior, type) diff --git a/tests/testthat/test-get_map_estimates.R b/tests/testthat/test-get_map_estimates.R index bc407ae..a263268 100644 --- a/tests/testthat/test-get_map_estimates.R +++ b/tests/testthat/test-get_map_estimates.R @@ -1020,4 +1020,35 @@ test_that("Floating point precision issues don't raise warning", { ) ) expect_equal(round(out$parameters$CL, 3), 2.320) +}) + +test_that("unsupported `type` values are rejected", { + expect_error(get_map_estimates(type = "invalid"), "should be one of") + expect_error(get_map_estimates(type = "map_flat_prior"), "should be one of") +}) + +test_that("map, pls, and ls are all accepted as `type`", { + mod <- PKPDsim::new_ode_model("pk_1cmt_iv") + par <- list(CL = 5, V = 50) + reg <- PKPDsim::new_regimen(amt = 1000, times = 0, type = "bolus") + data <- PKPDsim::sim( + mod, + regimen = reg, + parameters = par, + t_obs = c(1, 4, 8, 16), + only_obs = TRUE + ) + for(type in c("map", "pls", "ls")) { + fit <- get_map_estimates( + model = mod, + parameters = par, + omega = c(0.1, 0.02, 0.1), + regimen = reg, + error = list(prop = 0.1, add = 0.1), + data = data, + type = type, + verbose = FALSE + ) + expect_true(!is.null(fit$parameters)) + } }) \ No newline at end of file From 2c3617b103bc052bd58ddd7b23505cad5d60b214 Mon Sep 17 00:00:00 2001 From: Jasmine Hughes <43552465+jasmineirx@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:33:19 -0500 Subject: [PATCH 4/5] bring function documentation in line with style guide. Co-authored-by: Michael McCarthy <51542091+mccarthy-m-g@users.noreply.github.com> --- R/get_map_estimates.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/get_map_estimates.R b/R/get_map_estimates.R index c8556f5..444834a 100755 --- a/R/get_map_estimates.R +++ b/R/get_map_estimates.R @@ -49,7 +49,7 @@ #' such as `Nelder-Mead` to avoid estimation failures. #' @param control list of options passed to `optim()` function #' @param allow_obs_before_dose allow observation before first dose? -#' @param type estimation type, one of `map` (default), `pls`, or `ls` +#' @param type estimation type, one of `"map"` (default), `"pls"`, or `"ls"` #' @param cols column names #' @param residuals show residuals? This requires an additional simulation so #' will be slightly slower. From b001f11fa82904f007c512e1754466b5950e8e4a Mon Sep 17 00:00:00 2001 From: jasmineirx Date: Fri, 20 Nov 2026 11:34:22 -0500 Subject: [PATCH 5/5] rerun roxygen (updated package) --- DESCRIPTION | 2 +- NAMESPACE | 28 ++++++++++++++++------------ man/check_inputs.Rd | 2 +- man/get_map_estimates.Rd | 4 ++-- man/log2pi.Rd | 5 ----- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4776bda..16c39e2 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,6 +12,6 @@ Depends: utils, stats Imports: PKPDsim, numDeriv, mvtnorm Suggests: testthat (>= 3.0.0) Remotes: InsightRX/PKPDsim -RoxygenNote: 7.3.3 Encoding: UTF-8 Config/testthat/edition: 3 +Config/roxygen2/version: 8.1.1 diff --git a/NAMESPACE b/NAMESPACE index b11408f..0f60116 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,15 +16,19 @@ export(plot_eta) export(replace_list_elements) export(run_sequential_map) export(weight_by_time) -importFrom(stats,coef) -importFrom(stats,cov) -importFrom(stats,cov2cor) -importFrom(stats,dnorm) -importFrom(stats,filter) -importFrom(stats,glm) -importFrom(stats,lm) -importFrom(stats,predict.lm) -importFrom(stats,weights) -importFrom(utils,setTxtProgressBar) -importFrom(utils,tail) -importFrom(utils,txtProgressBar) +importFrom(stats, + coef, + cov, + cov2cor, + dnorm, + filter, + glm, + lm, + predict.lm, + weights +) +importFrom(utils, + setTxtProgressBar, + tail, + txtProgressBar +) diff --git a/man/check_inputs.Rd b/man/check_inputs.Rd index 812d7ee..199cac2 100644 --- a/man/check_inputs.Rd +++ b/man/check_inputs.Rd @@ -21,7 +21,7 @@ lower triangle of the covariance matrix of random effects} \item{censoring}{label for column specifying censoring. If value in dataset in this column is < 0 then censoring is assumed 0 then >ULOQ.} -\item{type}{estimation type, options are `map` and `ls`} +\item{type}{estimation type, one of `"map"` (default), `"pls"`, or `"ls"`} } \description{ Some basic input checking diff --git a/man/get_map_estimates.Rd b/man/get_map_estimates.Rd index 87d9a51..8686b76 100755 --- a/man/get_map_estimates.Rd +++ b/man/get_map_estimates.Rd @@ -31,7 +31,7 @@ get_map_estimates( method = "BFGS", control = list(reltol = 1e-05), allow_obs_before_dose = FALSE, - type = "map", + type = c("map", "pls", "ls"), cols = list(x = "t", y = "y"), residuals = TRUE, verbose = FALSE, @@ -115,7 +115,7 @@ such as `Nelder-Mead` to avoid estimation failures.} \item{allow_obs_before_dose}{allow observation before first dose?} -\item{type}{estimation type, options are `map` and `ls`} +\item{type}{estimation type, one of `"map"` (default), `"pls"`, or `"ls"`} \item{cols}{column names} diff --git a/man/log2pi.Rd b/man/log2pi.Rd index 8e1e771..dd849a7 100644 --- a/man/log2pi.Rd +++ b/man/log2pi.Rd @@ -1,16 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/const.R -\docType{data} \name{log2pi} \alias{log2pi} \title{Constant used in some computations} -\format{ -An object of class \code{numeric} of length 1. -} \usage{ log2pi } \description{ Constant used in some computations } -\keyword{datasets}