Skip to content

Using dose in a model causes it to have a Symengine parse error #935

@billdenney

Description

@billdenney

It would be better if dose were allowed as a variable in a model. Changing dose to dosex made this work. Is there a reason we cannot use dose?

library(nlmixr2)

min_df <- data.frame(
  ID = as.factor(c(1, 1, 2, 2)),
  AMT = c(10, 20, 10, 20),
  DV = c(1, 2, 3, 4),                            # Number of successes
  total_trials = as.integer(c(5, 5, 6, 6))  # Number of trials
)
min_df_expanded <-
  min_df |>
  rename(
    DV_orig = DV,
    # AMT is a reserved column name for the dose to be administered
    dose = AMT
  ) |>
  # make each success and failure one row
  mutate(
    dosex = dose,
    DV =
      pmap(
        .l = list(success = DV_orig, total = total_trials),
        .f = function(success, total) c(rep(1, success), rep(0, total - success))
      )
  ) |>
  unnest(cols = DV) |>
  mutate(
    # must have TIME and CMT even when it is meaningless
    TIME = 1,
    cmt = "arbitrary"
  )

min_model_dose <- function() {
  ini({
    t_bot <- 0.1
    t_top <- 0.9
    t_ic50 <- 10.0
    t_hill <- 1.5
    size_est <- 5
    eta.bot ~ 0.1
    eta.top ~ 0.1
    eta.ic50 ~ 0.1
    eta.hill ~ 0.1
  })
  model({
    bot <- exp(t_bot + eta.bot)
    top <- exp(t_top + eta.top)
    ic50 <- exp(t_ic50 + eta.ic50)
    hill <- exp(t_hill + eta.hill)
    prob <- bot + (top - bot) / (1 + (dose / ic50)^hill)
    DV ~ dbinom(size_est, prob)
  })
}

min_model_dosex <- function() {
  ini({
    t_bot <- 0.1
    t_top <- 0.9
    t_ic50 <- 10.0
    t_hill <- 1.5
    size_est <- 5
    eta.bot ~ 0.1
    eta.top ~ 0.1
    eta.ic50 ~ 0.1
    eta.hill ~ 0.1
  })
  model({
    bot <- exp(t_bot + eta.bot)
    top <- exp(t_top + eta.top)
    ic50 <- exp(t_ic50 + eta.ic50)
    hill <- exp(t_hill + eta.hill)
    prob <- bot + (top - bot) / (1 + (dosex / ic50)^hill)
    DV ~ dbinom(size_est, prob)
  })
}

nlmixr2(min_model_dose,
        data = min_df_expanded,
        est = "focei"
        )
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of full model...
#> ✔ done
#> Error in s4vecbasic_mut_append(ans, x) : SymEngine exception: Parse error
#> Error: SymEngine exception: Parse error
nlmixr2(min_model_dosex,
        data = min_df_expanded,
        est = "focei"
)
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
# Edit: removed a bunch of lines
#> → compress parHistData in nlmixr2 object, save 9400

Created on 2025-09-29 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions