Skip to content
Open
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
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pharmr.extra
Title: Extension of pharmr (Pharmpy) functionality
Version: 0.0.0.9072
Version: 0.0.0.9081
Authors@R: c(
person("Ron", "Keizer", email = "ron@insight-rx.com", role = c("cre", "aut")),
person("Michael", "McCarthy", email = "michael.mccarthy@insight-rx.com", role = "ctb"),
Expand Down Expand Up @@ -35,6 +35,7 @@ Imports:
tidyr,
tidyselect
Suggests:
callr,
mockery,
nlmixr2,
nlmixr2data,
Expand Down
22 changes: 17 additions & 5 deletions R/create_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,15 @@ create_model <- function(
add_sir(options = sir_options)
}

## MU referencing?
apply_mu <- (isTRUE(mu_reference) ||
(identical(mu_reference, "auto") && "saem" %in% tolower(estimation_method))) &&
tool == "nonmem"
## MU referencing? Pharmpy supports MU-referencing for both NONMEM and
## nlmixr2 backends. For nlmixr2 SAEM the rewrite is critical for stability
## — pharmpy emits `mu_n <- log(POP_X); X <- exp(ETA_X + mu_n)` which keeps
## the parameter on log scale during the MCMC E-step, preventing the M-step
## from drifting positive THETAs through zero (the source of the lsoda
## warning cascade and POP_* divergence we used to see on the admiral
## SAEM run).
apply_mu <- isTRUE(mu_reference) ||
(identical(mu_reference, "auto") && "saem" %in% tolower(estimation_method))
if(apply_mu && !pharmr::has_mu_reference(mod)) {
mod <- pharmr::mu_reference_model(mod)
}
Expand Down Expand Up @@ -563,6 +568,13 @@ create_model <- function(
if(!is.null(original_data)) {
attr(mod, "original_data") <- original_data
}
## For nlmixr, stash the stacked/standard-name dataset instead — rxode2
## references columns by name and cannot auto-stack encounters, so the raw
## pre-stacking input would conflate periods in a crossover trial and drive
## SAEM into the lsoda step-limit cascade.
if(tool == "nlmixr" && inherits(data, "data.frame")) {
attr(mod, "original_data") <- data
}

## For nlmixr models, cache an SAEM-safe rewrite of the generated R code as
## an attribute so run_nlme() / run_sim() can use it verbatim. Pharmpy emits
Expand All @@ -572,7 +584,7 @@ create_model <- function(
## internal state). NB: subsequent pharmpy operations on this model will
## drop this attribute; re-run create_model() if the model is modified.
if(tool == "nlmixr") {
nlmixr_code <- inline_nlmixr_residual_aliases(mod$code)
nlmixr_code <- make_nlmixr_saem_safe(mod$code)
if(!is.null(scale_observations)) {
nlmixr_code <- inject_nlmixr_scaling(nlmixr_code, scale_observations)
}
Expand Down
1 change: 1 addition & 0 deletions R/run_nlme.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ run_nlme <- function(
save_summary = save_summary,
save_final = save_final,
clean = clean,
mu_reference = mu_reference,
verbose = verbose
))
}
Expand Down
Loading
Loading