diff --git a/DESCRIPTION b/DESCRIPTION index d1f1985..7e07728 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: PKPDmap Type: Package Title: MAP Bayesian estimates -Version: 1.0.3 -Date: 2025-06-18 +Version: 1.1.4 +Date: 2025-07-12 Author: Ron Keizer, Jasmine Hughes, Kara Woo Maintainer: Ron Keizer Description: Obtain MAP Bayesian estimates based on individual data and diff --git a/R/calc_residuals.R b/R/calc_residuals.R index 46e3b19..b3c4173 100644 --- a/R/calc_residuals.R +++ b/R/calc_residuals.R @@ -18,6 +18,7 @@ calc_residuals <- function( parameters_population, covariates, regimen, + lagtime, omega_full, error, weights, @@ -60,6 +61,7 @@ calc_residuals <- function( iov_bins = iov_bins, output_include = output_include, t_init = t_init, + lagtime = lagtime, ... ) }) @@ -79,6 +81,7 @@ calc_residuals <- function( iov_bins = iov_bins, A_init = A_init_population, t_init = t_init, + lagtime = lagtime, ... ) }) diff --git a/R/get_individual_parameters_from_fit.R b/R/get_individual_parameters_from_fit.R index 25c7a8e..8be8792 100644 --- a/R/get_individual_parameters_from_fit.R +++ b/R/get_individual_parameters_from_fit.R @@ -1,7 +1,8 @@ #' Get the individual parameters from the fitted coefficients (etas) #' +#' @inheritParams get_map_estimates #' @param fit fit object -#' @param parameters list of population parameters +#' @param nonfixed vector of parameters that are not fixed (i.e. estimated) #' get_individual_parameters_from_fit <- function( fit, diff --git a/R/get_map_estimates.R b/R/get_map_estimates.R index 046e833..696c8ec 100755 --- a/R/get_map_estimates.R +++ b/R/get_map_estimates.R @@ -18,6 +18,8 @@ #' PKPDsim. #' @param error residual error, specified as list with arguments `add` and/or #' `prop` specifying the additive and proportional parts +#' @param lagtime vector of lagtimes for each compartment in the model, either +#' numeric vector, or vector of parameters. #' @param ltbs log-transform both sides? (`NULL` by default, meaning that it #' will be picked up from the PKPDsim model. Can be overridden with `TRUE`). #' Note: `error` should commonly only have additive part. @@ -39,7 +41,12 @@ #' @param ll_func likelihood function, default is `ll_func_PKPDsim` as included #' in this package. #' @param optimizer optimization library to use, default is `optim` -#' @param method optimization method, default `BFGS` +#' @param method optimization method, default `BFGS`. This method is a +#' gradient-based method, in which the gradients are computed using finite- +#' difference method. When the model contains a step-function where a +#' estimated parameter is involved in the step-function (such as in the case of +#' lagtime), it is advised to use a non-gradient-based estimation method +#' 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`, `ls`, and `np_hybrid` @@ -112,6 +119,7 @@ get_map_estimates <- function( include_omega = TRUE, include_error = TRUE, regimen = NULL, + lagtime = NULL, t_init = 0, int_step_size = 0.1, ll_func = ll_func_PKPDsim, @@ -137,6 +145,9 @@ get_map_estimates <- function( if(weight_prior_var == 0) { calc_ofv <- calc_ofv_ls } + + ## Make sure lagtime is properly formatted (potentially pulled from model) + lagtime <- PKPDsim:::parse_lagtime(lagtime, model, parameters) ## Misc checks: check_inputs(model, data, parameters, omega, regimen, censoring, type) @@ -211,6 +222,7 @@ get_map_estimates <- function( n_ind = 1, int_step_size = int_step_size, regimen = regimen, + lagtime = lagtime, t_obs = t_obs, obs_type = data$obs_type, checks = FALSE, @@ -250,6 +262,7 @@ get_map_estimates <- function( t_obs = t_obs, model = model, regimen = regimen, + lagtime = lagtime, error = error, omega_full = omega$est / weight_prior_var, omega_inv = solve(omega$est / weight_prior_var), @@ -305,6 +318,7 @@ get_map_estimates <- function( t_obs = t_obs, model = model, regimen = regimen, + lagtime = lagtime, error = error, nonfixed = omega$nonfixed, transf = transf, @@ -353,6 +367,7 @@ get_map_estimates <- function( obj = obj, model = model, regimen = regimen, + lagtime = lagtime, data = data, covariates = covariates, weights = weights, @@ -399,6 +414,7 @@ get_map_estimates <- function( covariates = covariates, int_step_size = int_step_size, regimen = regimen, + lagtime = lagtime, omega_full = omega$full, error = error, weights = weights, diff --git a/R/ll_func_PKPDsim.R b/R/ll_func_PKPDsim.R index 8028aa1..cd7f26e 100644 --- a/R/ll_func_PKPDsim.R +++ b/R/ll_func_PKPDsim.R @@ -1,29 +1,19 @@ #' Likelihood function for MAP optimization using PKPDsim #' -#' @param data vector of +#' @inheritParams get_map_estimates #' @param sim_object design (event-table) obtained from PKPDsim to be used in simulations/optimizations -#' @param parameters parameter list -#' @param covariates covariates list #' @param nonfixed non-fixed (i.e. estimated) parameters -#' @param error error model to use, e.g. `list(add = .5, prop = .15)` -#' @param model PKPDsim model #' @param omega_full full omega matrix #' @param omega_inv inverse of omega matrix. Passed to this function to avoid doing computations in each iteration of the search. #' @param omega_eigen eigenvalue decomposation (logged) of omega matrix. Passed to this function to avoid doing computations in each iteration of the search. #' @param sig signficance, used in optimization -#' @param weights weights for data, generally a vector of weights between 0 and 1. #' @param transf transformation function for data, if needed. E.g. `log(x)`. Default is `function(x) = x`. -#' @param as_eta implement as regular eta instead of exponential eta, can be vector. #' @param censoring_idx censoring indices, used for