Skip to contents

Appends a new empty model to the MB state object and makes this new model the active model.

Usage

MB_new_element(state)

Arguments

state

MB state from MB_fetch_state()

Value

MB state object containing a new model and that model is set as the current active model. See the help for MB_fetch_state() for model format.

Examples

#library(ruminate)
# This will get the full session:
sess_res = MB_test_mksession(session=list(), full_session=TRUE)
#> → MB: including file
#> → MB:   source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → MB:   dest:   file.path("config","report.docx")
#> → MB: including file
#> → MB:   source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → MB:   dest:   file.path("config","report.pptx")
#> → MB: including file
#> → MB:   source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → MB:   dest:   file.path("config","report.yaml")
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.R not found (skipping)
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.ctl not found (skipping)
#> → MB: module checksum updated:24933f86b657b9503f22440e8c4d3cac
#> → MB: State initialized
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.R not found (skipping)
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.ctl not found (skipping)
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#> → MB: model checksum updated: 567fe35aac84d6eccd4ce9fb17b00985
#> → MB: module checksum updated:c09fbcf95189690a2c471f5b66516173
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#> → MB: model checksum updated: 105c616bf887dbebe1bf0ee3cc188700
#> → MB: module checksum updated:5ac395697fa8d178e34e72783a9944e1
# This is just for CRAN
#sess_res = MB_test_mksession(session=list())
session = sess_res$session
input   = sess_res$input

# Configuration files
FM_yaml_file  = system.file(package = "formods", "templates", "formods.yaml")
MOD_yaml_file = system.file(package = "ruminate", "templates", "MB.yaml")

# Creating an empty state object
state = MB_fetch_state(id              = "MB",
                       input           = input,
                       session         = session,
                       FM_yaml_file    = FM_yaml_file,
                       MOD_yaml_file   = MOD_yaml_file,
                       react_state     = NULL)

# This will provide a list of the available models
models = MB_fetch_catalog(state)
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.R not found (skipping)
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.ctl not found (skipping)
# This is a summary of the tables in the model:
models$summary
#>    ana_sol depends mod_id                            Name
#> 1      yes    <NA>  mod_1                         PK_1cmt
#> 2       no    <NA>  mod_2                     PK_1cmt_des
#> 3      yes    <NA>  mod_3                         PK_2cmt
#> 4       no    <NA>  mod_4                     PK_2cmt_des
#> 5       no    <NA>  mod_5                PK_2cmt_no_depot
#> 6       no    <NA>  mod_6                PK_2cmt_tdcl_des
#> 7      yes    <NA>  mod_7                         PK_3cmt
#> 8       no    <NA>  mod_8                     PK_3cmt_des
#> 9       no    <NA>  mod_9  phenylalanine_charbonneau_2021
#> 10      no    <NA> mod_10         indirect_0cpt_transitEx
#> 11     yes    <NA> mod_11          PK_2cmt_mAb_Davda_2014
#> 12     yes    <NA> mod_12  CarlssonPetri_2021_liraglutide
#> 13      no    <NA> mod_13        Kovalenko_2020_dupilumab
#> 14     yes    <NA> mod_14       Soehoel_2022_tralokinumab
#> 15     yes    <NA> mod_15           Zhu_2017_lebrikizumab
#> 16      no      Cc mod_16          oncology_sdm_lobo_2002
#> 17      no      Cc mod_17 oncology_xenograft_simeoni_2004
#>                             Object   Type
#> 1                          PK_1cmt rxode2
#> 2                      PK_1cmt_des rxode2
#> 3                          PK_2cmt rxode2
#> 4                      PK_2cmt_des rxode2
#> 5                 PK_2cmt_no_depot rxode2
#> 6                 PK_2cmt_tdcl_des rxode2
#> 7                          PK_3cmt rxode2
#> 8                      PK_3cmt_des rxode2
#> 9   phenylalanine_charbonneau_2021 rxode2
#> 10         indirect_0cpt_transitEx rxode2
#> 11          PK_2cmt_mAb_Davda_2014 rxode2
#> 12  CarlssonPetri_2021_liraglutide rxode2
#> 13        Kovalenko_2020_dupilumab rxode2
#> 14       Soehoel_2022_tralokinumab rxode2
#> 15           Zhu_2017_lebrikizumab rxode2
#> 16          oncology_sdm_lobo_2002 rxode2
#> 17 oncology_xenograft_simeoni_2004 rxode2
#>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Model
#> 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               PK_1cmt <- function() {\n  description <- "One compartment PK model with linear clearance"\n  ini({\n    lka <- 0.45 ; label("Absorption rate (Ka)")\n    lcl <- 1 ; label("Clearance (CL)")\n    lvc  <- 3.45 ; label("Central volume of distribution (V)")\n    propSd <- 0.5 ; label("Proportional residual error (fraction)")\n  })\n  model({\n    ka <- exp(lka)\n    cl <- exp(lcl)\n    vc  <- exp(lvc)\n\n    Cc <- linCmt()\n    Cc ~ prop(propSd)\n  })\n}
#> 2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        PK_1cmt_des <- function() {\n  description <- "One compartment PK model with linear clearance using differential equations"\n  dosing<-c("central", "depot")\n  ini({\n    lka <- 0.45 ; label("Absorption rate (Ka)")\n    lcl <- 1 ; label("Clearance (CL)")\n    lvc  <- 3.45 ; label("Central volume of distribution (V)")\n    propSd <- 0.5 ; label("Proportional residual error (fraction)")\n  })\n  model({\n    ka <- exp(lka)\n    cl <- exp(lcl)\n    vc  <- exp(lvc)\n\n    kel <- cl / vc\n\n    d/dt(depot) <- -ka*depot\n    d/dt(central) <- ka*depot-kel*central\n\n    Cc <- central / vc\n    Cc ~ prop(propSd)\n  })\n}
#> 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                PK_2cmt <- function() {\n  description <- "Two compartment PK model with linear clearance"\n  ini({\n    lka <- 0.45 ; label("Absorption rate (Ka)")\n    lcl <- 1 ; label("Clearance (CL)")\n    lvc  <- 3 ; label("Central volume of distribution (V)")\n    lvp  <- 5 ; label("Peripheral volume of distribution (Vp)")\n    lq  <- 0.1 ; label("Intercompartmental clearance (Q)")\n    propSd <- 0.5 ; label("Proportional residual error (fraction)")\n  })\n  model({\n    ka <- exp(lka)\n    cl <- exp(lcl)\n    vc <- exp(lvc)\n    vp <- exp(lvp)\n    q  <- exp(lq)\n\n    Cc<- linCmt()\n    Cc ~ prop(propSd)\n  })\n}
#> 4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              PK_2cmt_des <- function() {\n  description <- "Two compartment PK model with linear clearance using differential equations"\n  ini({\n    lka <- 0.45 ; label("Absorption rate (Ka)")\n    lcl <- 1 ; label("Clearance (CL)")\n    lvc  <- 3 ; label("Central volume of distribution (V)")\n    lvp  <- 5 ; label("Peripheral volume of distribution (Vp)")\n    lq  <- 0.1 ; label("Intercompartmental clearance (Q)")\n    propSd <- 0.5 ; label("Proportional residual error (fraction)")\n  })\n  model({\n    ka <- exp(lka)\n    cl <- exp(lcl)\n    vc <- exp(lvc)\n    vp <- exp(lvp)\n    q  <- exp(lq)\n\n    kel <- cl/vc\n    k12 <- q/vc\n    k21 <- q/vp\n\n    d/dt(depot) <- -ka*depot\n    d/dt(central) <-  ka*depot - kel*central - k12*central + k21*peripheral1\n    d/dt(peripheral1) <- k12*central - k21*peripheral1\n    Cc <- central / vc\n\n    Cc ~ prop(propSd)\n  })\n}
#> 5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     PK_2cmt_no_depot <- function() {\n  description <- "Two compartment PK model with linear clearance using differential equations"\n  ini({\n    lcl <- 1 ; label("Clearance (CL)")\n    lvc  <- 3 ; label("Central volume of distribution (V)")\n    lvp  <- 5 ; label("Peripheral volume of distribution (Vp)")\n    lq  <- 0.1 ; label("Intercompartmental clearance (Q)")\n    propSd <- 0.5 ; label("Proportional residual error (fraction)")\n  })\n  model({\n    cl <- exp(lcl)\n    vc <- exp(lvc)\n    vp <- exp(lvp)\n    q  <- exp(lq)\n    \n    kel <- cl/vc\n    k12 <- q/vc\n    k21 <- q/vp\n    \n  \n    d/dt(central) <-  - kel*central - k12*central + k21*peripheral1\n    d/dt(peripheral1) <- k12*central - k21*peripheral1\n    Cc <- central / vc\n    \n    Cc ~ prop(propSd)\n  })\n}
#> 6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         PK_2cmt_tdcl_des <- function() {\n  description <- "Two compartment PK model with time-dependent clearance using differential equations (structured like nivolumab PK model)"\n  reference <- "C Liu, J Yu, H Li, J Liu, Y Xu, P Song, Q Liu, H Zhao, J Xu, V E Maher, B P Booth, G Kim, A Rahman, Y Wang; Association of time-varying clearance of nivolumab with disease dynamics and its implications on exposure response analysis.  Clin Pharmacol Ther May 2017; 101(5): 657-666. https://doi.org/10.1002/cpt.656"\n  ini({\n    lcl <- log(0.2) ; label("Time-stationary clearance (CLTS)")\n    lcltmax <- log(0.22) ; label("Typical value of the maximal change of clearance relative to baseline (Tmax)")\n    lclgamma <- log(1) ; label("Hill coefficient for time-dependent clearance")\n    lclt50 <- log(30) ; label("Time for 50% of maximal CL change")\n    lvc  <- log(20) ; label("Central volume of distribution (V)")\n    lvp  <- log(150) ; label("Peripheral volume of distribution (Vp)")\n    lq  <- log(0.75) ; label("Intercompartmental clearance (Q)")\n    propSd <- 0.5 ; label("Proportional residual error (fraction)")\n  })\n  model({\n    clts <- exp(lcl)\n    cltmax <- exp(lcltmax)\n    clgamma <- exp(lclgamma)\n    clt50 <- exp(lclt50)\n    vc <- exp(lvc)\n    vp <- exp(lvp)\n    q  <- exp(lq)\n\n    cl <- clts*exp(cltmax*time^clgamma/(clt50^clgamma+time^clgamma))\n\n    kel <- cl/vc\n    k12 <- q/vc\n    k21 <- q/vp\n\n    d/dt(central)     <- - kel*central - k12*central + k21*peripheral1\n    d/dt(peripheral1) <- k12*central - k21*peripheral1\n    Cc <- central / vc\n\n    Cc ~ prop(propSd)\n  })\n}
#> 7                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  PK_3cmt <- function() {\n  description <- "Three compartment PK model with linear clearance"\n  ini({\n    lka <- 0.45 ; label("Absorption rate (Ka)")\n    lcl <- 1 ; label("Clearance (CL)")\n    lvc  <- 3 ; label("Central volume of distribution (V)")\n    lvp  <- 5 ; label("Peripheral volume of distribution (Vp)")\n    lvp2  <- 8 ; label("Second peripheral volume of distribution (Vp2)")\n    lq  <- 0.1 ; label("Intercompartmental clearance (Q)")\n    lq2  <- 0.5 ; label("Second intercompartmental clearance (Q2)")\n    propSd <- 0.5 ; label("Proportional residual error (fraction)")\n  })\n  model({\n    ka <- exp(lka)\n    cl <- exp(lcl)\n    vc <- exp(lvc)\n    vp <- exp(lvp)\n    vp2 <- exp(lvp2)\n    q   <- exp(lq)\n    q2  <- exp(lq2)\n\n    Cc <- linCmt()\n    Cc ~ prop(propSd)\n  })\n}
#> 8                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     PK_3cmt_des <- function() {\n  description <- "Three compartment PK model with linear clearance using differential equations"\n  ini({\n    lka <- 0.45 ; label("Absorption rate (Ka)")\n    lcl <- 1 ; label("Clearance (CL)")\n    lvc  <- 3 ; label("Central volume of distribution (V)")\n    lvp  <- 5 ; label("Peripheral volume of distribution (Vp)")\n    lvp2  <- 8 ; label("Second peripheral volume of distribution (Vp2)")\n    lq  <- 0.1 ; label("Intercompartmental clearance (Q)")\n    lq2  <- 0.5 ; label("Second intercompartmental clearance (Q2)")\n    propSd <- 0.5 ; label("Proportional residual error (fraction)")\n  })\n  model({\n    ka <- exp(lka)\n    cl <- exp(lcl)\n    vc <- exp(lvc)\n    vp <- exp(lvp)\n    vp2 <- exp(lvp2)\n    q  <- exp(lq)\n    q2  <- exp(lq2)\n\n    kel <- cl/vc\n    k12 <- q/vc\n    k21 <- q/vp\n    k13 <- q2/vc\n    k31 <- q2/vp2\n\n    d/dt(depot) <- -ka*depot\n    d/dt(central) <-  ka*depot - kel*central - k12*central + k21*peripheral1 - k13*central + k31*peripheral2\n    d/dt(peripheral1) <- k12*central - k21*peripheral1\n    d/dt(peripheral2) <- k13*central - k31*peripheral2\n    Cc <- central / vc\n\n    Cc ~ prop(propSd)\n  })\n}
#> 9                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      phenylalanine_charbonneau_2021 <- function() {\n  description <- "Phenylalanine model for absorption and metabolism in healthy subjects and patients with PKU"\n  reference <- "Charbonneau, M.R., Denney, W.S., Horvath, N.G. et al. Development of a mechanistic model to predict synthetic biotic activity in healthy volunteers and patients with phenylketonuria. Commun Biol 4, 898 (2021). https://doi.org/10.1038/s42003-021-02183-1"\n  covariates <-\n    list(\n      WT = "Body weight in kg",\n      time = "Time in hours",\n      f_pah = "Fraction of healthy PAH activity (healthy = 1; PKU patient = 0 to 0.03)",\n      bl_phe = "Typical values are about 0.075 mmol/L in healthy subjects and 1.18 mmol/L in patients"\n    )\n  # parameters come from Table 4 in paper\n  ini({\n    bl_phe <- 1.18; label("Baseline Phenylalanine (Phe) concentration (mmol/L)")\n    bl_gut <- 0; label("Baseline Phe in the gut (mg)")\n\n    ka_gut <- 0.25; label("Absorption rate from gut to plasma")\n    v_npd <- 0.015; label("Rate of net protein breakdown ((mmol/L)/hr)")\n\n    vmax_pah <- 0.9; label("Maximum rate of Phe breakdown by PAH in a healthy subject ((mmol/L)/hr)")\n    f_pah <- 0; label("Fraction of healthy PAH activity (PKU patient = 0 to 0.02)")\n    km_pah <- 0.51; label("Michaelis-Menten constant for Phe with PAH (mmol/L)")\n    kact_pah <- 0.54; label("Phe activation constant for PAH")\n\n    vmax_trans <- 0.063; label("Maximum rate of Phe breakdown by transaminase ((mmol/L)/hr)")\n    km_trans <- 1.37; label("Michaelis-Menten constant for Phe with transaminase (mmol/L)")\n\n    cl_renal <- 5.696e-4; label("Renal clearance of Phe per body weight ((L/kg)/hr)")\n\n    vd <- 0.5; label("Body-weight normalized volume distribution of Phe (L/kg)")\n  })\n  model({\n    # Molecular weight of Phe (g/mol)\n    mw_phe <- 165.19\n    # Unit conversion adjustment from Gut to Plasma concentrations (mmol/L)/mg\n    f_gut_plasma <- 1/(mw_phe * vd_phe * WT)\n\n    v_pah <- vmax_pah*f_pah / (1 + km_pah/phe + km_pah*kact_pah/(phe^2)) # units: (mmol/L)/hr\n    v_trans <- vmax_trans / (1 + km_trans/phe) # units: (mmol/L)/hr\n    v_renal <- phe * cl_renal * vd # units: (mmol/L)/hr\n\n    d/dt(gut) <- -ka_gut*gut\n    d/dt(phe) <- ka*gut*f_gut_plasma + v_npd - v_pah - v_trans - v_renal\n    gut(0) <- bl_gut\n    phe(0) <- bl_phe\n    phe_umol <- phe * 1000 # units: umol/L (more commonly used in clinical laboratories)\n\n    # The following is an augmentation of the model reported in the paper.  It\n    # indicates the approximate daily Phe intake (in mg) to achieve\n    # steady-state.\n    daily_phe_intake <- 24 * vd * (v_pah + v_trans + v_renal - v_npd) / f_gut_plasma\n  })\n}
#> 10                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              indirect_0cpt_transitEx <- function() {\n  description <- "Two compartment PK model with Michealis-Menten clearance using differential equations"\n  ini({\n    lka <- 0.45 ; label("Absorption rate (Ka)")\n    lktr1 <- c(0, 0.05)\n    lktr2 <- c(0, 0.05)\n    lktr3 <- c(0, 0.05)\n    lktr4 <- c(0, 0.05)\n    lktr5 <- c(0, 0.05)\n    lktr6 <- c(0, 0.05)\n    lktr7 <- c(0, 0.05)\n    lktr8 <- c(0, 0.05)\n    lktr9 <- c(0, 0.05)\n    lktr10 <- c(0, 0.05)\n    lvm <- 0.04\n    label("maximum target-mediated rate of elimination (mg/L/d)")\n    lkm <- 0.01\n    label("Michaelis-Menten constant (mg/L)")\n    lvc <- 3\n    label("central volume of distribution (Vc)")\n    lvp <- 5\n    label("Peripheral volume of distribution (Vp)")\n    lq <- 0.1\n    label("Intercompartmental clearance (Q)")\n    propSd <- c(0, 0.5)\n    label("Proportional residual error (fraction)")\n\n  })\n  model({\n    ka <- exp(lka)\n    ktr1 <- exp(lktr1)\n    ktr2 <- exp(lktr2)\n    ktr3 <- exp(lktr3)\n    ktr4 <- exp(lktr4)\n    ktr5 <- exp(lktr5)\n    ktr6 <- exp(lktr6)\n    ktr7 <- exp(lktr7)\n    ktr8 <- exp(lktr8)\n    ktr9 <- exp(lktr9)\n    ktr10 <- exp(lktr10)\n    km <- exp(lkm)\n    vm <- exp(lvm)\n    vc <- exp(lvc)\n    vp <- exp(lvp)\n    q <- exp(lq)\n    k12 <- q/vc\n    k21 <- q/vp\n    d/dt(depot) <- -ka*depot\n    d/dt(transit1) <- ka * depot - ktr1 * transit1\n    d/dt(transit2) <- ktr1 * transit1 - ktr2 * transit2\n    d/dt(transit3) <- ktr2 * transit2 - ktr3 * transit3\n    d/dt(transit4) <- ktr3 * transit3 - ktr4 * transit4\n    d/dt(transit5) <- ktr4 * transit4 - ktr5 * transit5\n    d/dt(transit6) <- ktr5 * transit5 - ktr6 * transit6\n    d/dt(transit7) <- ktr6 * transit6 - ktr7 * transit7\n    d/dt(transit8) <- ktr7 * transit7 - ktr8 * transit8\n    d/dt(transit9) <- ktr8 * transit8 - ktr9 * transit9\n    d/dt(transit10) <- ktr9 * transit9 - ktr10 * transit10\n    d/dt(central) <- ktr10 * transit10 - (vm/(km + central/vc)) * \n      central - k12 * central + k21 * peripheral1\n    d/dt(peripheral1) <- k12 * central - k21 * peripheral1\n    Cc <- central/vc\n    Cc ~ prop(propSd)\n  })\n}
#> 11                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    PK_2cmt_mAb_Davda_2014 <- function() {\n  description <- "Two compartment PK model with linear clearance for average monoclonal antibodies (Davda 2014)"\n  reference <- "Davda JP, Dodds MG, Gibbs MA, Wisdom W, Gibbs JP. A model-based meta-analysis of monoclonal antibody pharmacokinetics to guide optimal first-in-human study design. MAbs. 2014;6(4):1094-1102. doi:10.4161/mabs.29095"\n  units = list(time="day", dosing="mg")\n  ini({\n    lfdepot <- log(0.744) ; label("Subcutaneous bioavailability (fraction)")\n    lka <- log(0.282) ; label("Absorption rate (Ka, 1/day)")\n    lcl <- log(0.200) ; label("Clearance (CL, L/day)")\n    lv  <- log(3.61) ; label("Central volume of distribution (V, L)")\n    lvp  <- log(2.75) ; label("Peripheral volume of distribution (Vp, L)")\n    lq  <- log(0.747) ; label("Intercompartmental clearance (Q, L/day)")\n\n    allocl <- 0.865 ; label("Allometric exponent on clearance and intercompartmental clearance (unitless)")\n    allov <- 0.957 ; label("Allometric exponent on volumes of distribution (unitless)")\n\n    etafdepot ~ 0\n    etaka ~ 0.416\n    etacl + etav + etavp ~ c(0.0987,\n                             0.0786, 0.116,\n                             0.0377, 0.0619, 0.0789)\n    etaq ~ 0.699\n\n    prop.err <- 0.144 ; label("Proportional residual error (fraction)")\n  })\n  model({\n    # WT is body weight in kg\n    fdepot <- exp(lfdepot + etafdepot)\n    ka <- exp(lka + etaka)\n    wtnorm <- log(WT/70)\n    cl <- exp(lcl + allocl*wtnorm + etacl)\n    q  <- exp(lq + allocl*wtnorm + etaq)\n    v <- exp(lv + allov*wtnorm + etav)\n    vp <- exp(lvp + allov*wtnorm + etavp)\n    Cc <- linCmt()\n    \n    f(depot) <- fdepot  # Units are dosing units/L (typically mg/L = ug/mL)\n    Cc ~ prop(prop.err)\n    \n  })\n}
#> 12                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                CarlssonPetri_2021_liraglutide <- function() {\n  description <- "Liraglutide PK model in adolescents (Carlsson Petri 2021)"\n  reference <- "Carlsson Petri KC, Hale PM, Hesse D, Rathor N, Mastrandrea LD. Liraglutide pharmacokinetics and exposure-response in adolescents with obesity. Pediatric Obesity. 2021;16(10):e12799. doi:10.1111/ijpo.12799"\n  units <-list(time="hr", dosing="mg")\n  covariateData <-\n    list(\n      WT = "Baseline body weight in kg",\n      CHILD = "Is the subject a child? (1 for yes, 0 for no)",\n      ADOLESCENT = "Is the subject an adolescent? (1 for yes, 0 for no)",\n      SEXM = "1 for male, 0 for female"\n    )\n  ini({\n    lka <- fixed(log(0.0813)) ; label("Absorption rate (1/hr)")\n    lcl <- log(1.01) ; label("Apparent clearance (L/h)")\n    e_wt_cl <- 0.762; label("Body weight exponent on CL/F")\n    e_sex_cl <- 1.12; label("Sex contrast (male/female) on CL/F")\n    e_age_child_cl <- 1.11; label("Age contrast (child/adult) on CL/F")\n    e_age_adolescent_cl <- 1.06; label("Age contrast (adolescent/adult) on CL/F")\n    lvc  <- fixed(log(13.8)) ; label("Apparent central volume of distribution (L)")\n    e_wt_vc <- 0.587; label("Body weight exponent on Vc/F")\n    \n    etalcl ~ log(1.312)\n    etalvc ~ log(1.317)\n    propSd <- 0.433 ; label("Proportional residual error (fraction)")\n  })\n  model({\n    ka <- exp(lka)\n    cl_wt <- (WT/100)^e_wt_cl # Equation 2 in the paper\n    cl_sex <- SEXM^e_sex_cl # Equation 3 in the paper\n    cl_age <- CHILD^e_age_child_cl * ADOLESCENT^e_age_adolescent_cl # Equation 4 in the paper\n    cl <- exp(lcl + etalcl)*cl_wt*cl_sex*cl_age # Equation 1 in the paper\n    vc_wt <- (WT/100)^e_wt_vc # Not in the paper, based on Equation 2 in the paper\n    vc  <- exp(lvc + etalvc)*vc_wt # Equation 5 in the paper\n    \n    Cc <- linCmt()\n    Cc ~ prop(propSd)\n  })\n}
#> 13                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Kovalenko_2020_dupilumab <- function() {\n  description <- "Dupilumab PK model (Kovalenko 2020)"\n  reference <- "Kovalenko P, Davis JD, Li M, et al. Base and Covariate Population Pharmacokinetic Analyses of Dupilumab Using Phase 3 Data. Clinical Pharmacology in Drug Development. 2020;9(6):756-767. doi:10.1002/cpdd.780"\n  units<-list(time="day", dosing="mg")\n  # Model 1 from table 1 and supplementary Table 2 in the publication and its\n  # supplement.\n  covariateData <-\n    list(\n      WT = "Body weight in kg"\n    )\n  ini({\n    lvc <- log(2.48); label("central volume (L)")\n    lke <- log(0.0534); label("elimination rate (1/d)")\n    lkcp <- log(0.213); label("central-to-peripheral rate (1/d)")\n    Mpc <- 0.686; label("ratio of kcp and kpc (kpc is peripheral to central rate with units of 1/d)")\n    lka <- log(0.256); label("absorption rate (1/d)")\n    lMTT <- log(0.105); label("mean transit time (d)")\n    lVm <- log(1.07); label("maximum target-mediated rate of elimination (mg/L/d)")\n    Km <- fixed(0.01); label("Michaelis-Menten constant (mg/L)")\n    lfdepot <- log(0.643); label("Bioavailability (fraction)")\n    e_wt_vc <- 0.711; label("Exponent of weight on central volume (unitless)")\n\n    etalvc ~ 0.192\n    etalke ~ 0.285\n    etalka ~ 0.474\n    etalvm ~ 0.236\n    etamtt ~ 0.525 # etamtt is assumed to be on log-scale MTT to prevent negative values; this is a difference relative to Supplementary Table 2\n\n    CcpropSd <- 0.15; label("Proportional residual error (fraction)")\n    CcaddSd <- fixed(0.03); label("Additive residual error (mg/L)")\n  })\n  model({\n    # Weight normalization to 75 kg is assumed based on prior publication.  It\n    # is not specified in the current publication:\n    # Kovalenko P, DiCioccio AT, Davis JD, et al. Exploratory Population PK\n    # Analysis of Dupilumab, a Fully Human Monoclonal Antibody Against\n    # IL-4Ralpha, in Atopic Dermatitis Patients and Normal Volunteers. CPT\n    # Pharmacometrics Syst Pharmacol. 2016;5(11):617-624. doi:10.1002/psp4.12136\n    vc <- exp(lvc + etalvc)*(WT/75)^e_wt_vc\n    ke <- exp(lke + etalke)\n    kcp <- exp(lkcp)\n    ka <- exp(lka + etalka)\n    MTT <- exp(lMTT + etamtt)\n    Vm <- exp(lVm + etalvm)\n\n    # Derived parameters\n    kpc <- kcp/Mpc\n    ktr <- (3 + 1)/MTT\n\n    d/dt(depot) <- -ktr*depot\n    d/dt(transit1) <- ktr*(depot - transit1)\n    d/dt(transit2) <- ktr*(transit1 - transit2)\n    d/dt(transit3) <- ktr*transit2 - ka*transit3\n    # Linear and Michaelis-Menten clearance\n    d/dt(central) <-                 ka*transit3 - ke*central - kcp*central + kpc*periph - central*(Vm/(Km + central/vc))\n    d/dt(periph) <-                                             kcp*central - kpc*periph\n\n    f(depot) <- exp(lfdepot)\n    # No unit conversion is required to change mg/L (dosing amount/central\n    # volume unit) to mg/L (measurement unit)\n    Cc <- central/vc\n    Cc ~ add(CcaddSd) + prop(CcpropSd)\n  })\n}
#> 14                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Soehoel_2022_tralokinumab <- function() {\n  description <- "Tralokinumab PK model (Soehoel 2022)"\n  reference <- "Soehoel A, Larsen MS, Timmermann S. Population Pharmacokinetics of Tralokinumab in Adult Subjects With Moderate to Severe Atopic Dermatitis. Clinical Pharmacology in Drug Development. 2022;11(8):910-921. doi:10.1002/cpdd.1113"\n  units<-list(time="day",dosing="mg") \n  # From Table 2 footnotes\n  covariateData <-\n    list(\n      nonECZTRA = "1 = any study other than ECZTRA; 0 = ECZTRA study",\n      WT = "Body weight in kg",\n      dilution = "Was the drug diluted as it was in study D2213C00001? 1 = yes, 0 = no (0 is typical)"\n    )\n  ini({\n    lka <- log(0.184); label("Absorption rate (1/day)")\n    lvc <- log(2.71); label("Central volume of distribution (L)")\n    lcl <- log(0.149); label("Clearance (L/day)")\n    lvp <- log(1.44); label("Peripheral volume of distribution (L)")\n    lq <- log(0.159); label("Intercompartmental clearance (L/day)")\n    lfdepot <- log(0.761); label("Subcutaneous bioavailability (fraction)")\n    CcaddSd <- 0.238; label("Additive residual error (ug/mL)")\n    CcpropSd <- 0.216; label("Proportional residual error (fraction)")\n\n    e_wt_vcvp <- 0.793; label("Effect of body weight on central and peripheral volumes (unitless)")\n    e_wt_clq <- 0.873; label("Effect of body weight on clearance and intercompartmental clearance (unitless)")\n    e_nonECZTRA_cl <- 0.344; label("Effect of non-ECZTRA trials on clearance (unitless)")\n    e_nonECZTRA_vc <- 0.258; label("Effect of non-ECZTRA trials on central volume (unitless)")\n    e_f_dilution <- 0.354; label("Effect of dilution on bioavailability (unitless)")\n    e_ka_dilution <- -0.519; label("Effect of dilution trials on absorption rate (unitless)")\n\n    etavc + etacl ~ c(0.386148, 0.2683494, 0.3057157)\n  })\n  model({\n    fdepot <- exp(lfdepot)*(1 + e_f_dilution*dilution)\n    ka <- exp(lka)*(1 + e_ka_dilution*dilution)\n    cl <- exp(lcl + etacl)*(WT/75)^e_wt_clq * (1 + e_nonECZTRA_cl*nonECZTRA)\n    vc <- exp(lvc + etavc)*(WT/75)^e_wt_vcvp * (1 + e_nonECZTRA_vc*nonECZTRA)\n    q <- exp(lq)*(WT/75)^e_wt_clq\n    vp <- exp(lvp)*(WT/75)^e_wt_vcvp\n\n    # No unit conversion is required to change mg/L (dosing amount/central\n    # volume unit) to ug/mL (measurement unit)\n    Cc <- linCmt()\n    f(depot) <- fdepot\n    Cc ~ add(CcaddSd) + prop(CcpropSd)\n  })\n}\n\n# etavc, etacl, and the covariance were calculated from the Table 2 footnotes\n# as:\n# etavc: sqrt(log(0.313^2 + 1)) = 0.386148\n# etacl: sqrt(log(0.401^2 + 1)) = 0.3057157\n# cov(etavc, etacl): sqrt(0.61*0.386148*0.3057157)
#> 15 Zhu_2017_lebrikizumab <- function() {\n  description <- "Lebrikizumab PK model (Zhu 2017)"\n  reference <- "Zhu R, Zheng Y, Dirks NL, et al. Model-based clinical pharmacology profiling and exposure-response relationships of the efficacy and biomarker of lebrikizumab in patients with moderate-to-severe asthma. Pulmonary Pharmacology & Therapeutics. 2017;46:88-98. doi:10.1016/j.pupt.2017.08.010"\n  units <- list(time="day", dosing="mg")\n  covariateData <-\n    list(\n      WT = "Baseline body weight in kg",\n      AGE = "Age in years",\n      SEXF = "1 for female, 0 for male",\n      FORM_NS0 = "Is the formulation NS0? 1 for yes, 0 for no (typically no)",\n      FORM_CHO_PHASE2 = "Is the formulation CHO from Phase 2? 1 for yes, 0 for no (typically no)",\n      ADA = "Is the subject ADA positive ever? 1 for yes, 0 for no",\n      RACE_BLACK = "Is the race of the subject black or African American? 1 for yes, 0 for no",\n      RACE_ASIAN = "Is the race of the subject Asian? 1 for yes, 0 for no",\n      RACE_OTHER = "Is the race of the subject 'other'? 1 for yes, 0 for no"\n    )\n  ini({\n    lcl <- log(0.156); label("Clearance (L/day)")\n    lvc <- log(4.10); label("Central volume of distribution (L)")\n    lvp <- log(1.45); label("Peripheral volume of distribution (L)")\n    lq <- log(0.284); label("Intercompartmental clearance (L/day)")\n    lka <- log(0.239); label("Absorption rate (1/day)")\n    lfdepot <- log(0.856); label("Subcutaneous bioavailability (fraction)")\n\n    e_cl_wt <- 1.00; label("Effect of body weight on clearance (unitless)")\n    e_vc_wt <- 0.814; label("Effect of body weight on central volume (unitless)")\n    e_vp_wt <- 0.692; label("Effect of body weight on peripheral volume (unitless)")\n    e_q_wt <- 0.479; label("Effect of body weight on intercompartmentl clearance (unitless)")\n    e_cl_age <- 0.0241; label("Effect of age on clearance (unitless)")\n    e_cl_sexf <- 1.06; label("Effect of sex on clearance (unitless)")\n    e_cl_race_black <- 1.07; label("Effect of race (black or African American) on clearance (unitless)")\n    e_cl_race_asian <- 1.09; label("Effect of race (Asian) on clearance (unitless)")\n    e_cl_race_other <- 1.11; label("Effect of race (other) on clearance (unitless)")\n    e_ka_form_nso <- 0.981; label("Effect of NSO formulation on absorption rate (unitless)")\n    e_ka_form_cho_phase2 <- 0.989; label("Effect of CHO formulation used during Phase 2 on absorption rate (unitless)")\n    e_f_form_nso <- 1.00; label("Effect of NSO formulation on bioavailability (unitless)")\n    e_f_form_cho_phase2 <- 0.973; label("Effect of CHO formulation used during Phase 2 on bioavailability (unitless)")\n    e_cl_ada_positive<- 1.04; label("Effect of anti-drug antibody (ADA) positivity on clearance (unitless)")\n\n    # converted from covariance matrix reported in Table 3\n    etacl + etavc + etaka ~\n      c(\n        0.32403703,\n        0.28844410, 0.35213634,\n        0.04505552, 0.06625708, 0.39242834\n      )\n\n    CcpropSd <- 0.0490; label("Proportional residual error (fraction)")\n    CcaddSd <- 0.00154; label("Additive residual error (ug/mL)")\n  })\n  model({\n    # Normalized continuous covariate values based on footnote to Table 3\n    WTNORM <- WT/70\n    AGENORM <- AGE/40\n\n    cl <-\n      exp(lcl + etacl) *\n      WTNORM^e_cl_wt * AGENORM^e_cl_age * e_cl_sexf^SEXF *\n      e_cl_race_black^RACE_BLACK * e_cl_race_asian^RACE_ASIAN * e_cl_race_other^RACE_OTHER *\n      e_cl_ada_positive^ADA\n    vc <- exp(lvc + etavc) * WTNORM^e_vc_wt\n    vp <- exp(lvp) * WTNORM^e_vp_wt\n    q <- exp(lq) * WTNORM^e_q_wt\n    ka <- exp(lka + etaka) * e_ka_form_nso^FORM_NSO * e_ka_form_cho_phase2^FORM_CHO_PHASE2\n    fdepot <- exp(lfdepot) * e_f_form_nso^FORM_NSO * e_f_form_cho_phase2^FORM_CHO_PHASE2\n    Cc <- linCmt()\n    f(depot) <- fdepot\n    Cc ~ add(CcaddSd) + prop(CcpropSd)\n  })\n}
#> 16                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    oncology_sdm_lobo_2002 <- function() {\n  description <- "Signal transduction model for delayed concentration effects on cancer cell growth"\n  reference <- "Lobo ED, Balthasar JP. Pharmacodynamic modeling of chemotherapeutic effects: Application of a transit compartment model to characterize methotrexate effects in vitro. AAPS J. 2002;4(4):212-222. doi:10.1208/ps040442"\n  depends<-"Cc"\n  units<-list(time="hr")\n  # Values for lkng, ltau, lec50, and kmax are for methotrexate from Lobo 2002,\n  # Table 2.  propErr and addErr are added as reasonable values though not from\n  # Lobo 2002 where no value is apparent in the paper.\n  ini({\n    lkng <- log(0.02) ; label("Cell net growth rate (growth minus death) (1/hr)")\n    ltau <- log(34.1) ; label("Mean transit time of each transit compartment (hr)")\n    lec50 <- log(0.1) ; label("Drug concentration reducing the cell growth by 50% (ug/mL)")\n    kmax <- 0.29 ; label("Maximum drug-related reduction in cell growth (1/hr)")\n\n    tumorVolpropSd <- c(0, 0.3) ; label("Proportional residual error (fraction)")\n    tumorVoladdSd <- c(0, 50, 1000) ; label("Additive residual error (tumor volume units)")\n  })\n  model({\n    # Cc is the drug concentration\n    kng <- exp(lkng)\n    tau <- exp(ltau)\n    ec50 <- exp(lec50)\n\n    drugEffectTumorVol <- kmax*Cc/(ec50 + Cc)\n\n    tumorVol(0) <- tumorVol0\n    d/dt(tumorVol) <- kng*tumorVol - transit4*tumorVol\n    d/dt(transit1) <- (drugEffectTumorVol - transit1)/tau\n    d/dt(transit2) <- (transit1 - transit2)/tau\n    d/dt(transit3) <- (transit2 - transit3)/tau\n    d/dt(transit4) <- (transit3 - transit4)/tau\n    tumorVol ~ prop(tumorVolpropSd) + add(tumorVoladdSd)\n  })\n}
#> 17                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       oncology_xenograft_simeoni_2004 <- function() {\n  description <- "Oncology tumor growth model in xenograft models"\n  reference <- "Monica Simeoni, Paolo Magni, Cristiano Cammia, Giuseppe De Nicolao, Valter Croci, Enrico Pesenti, Massimiliano Germani, Italo Poggesi, Maurizio Rocchetti; Predictive Pharmacokinetic-Pharmacodynamic Modeling of Tumor Growth Kinetics in Xenograft Models after Administration of Anticancer Agents. Cancer Res 1 February 2004; 64 (3): 1094–1101. https://doi.org/10.1158/0008-5472.CAN-03-2524"\n  depends<- "Cc"\n  units<-list(time="day")\n  # Values for damageTransit (k1), drugSlope (k2), tumorExpGrowth (lambda0),\n  # tumorLinGrowth (lambda1) are from paclitaxel experiment 1 reported in Table\n  # 2 from the reference (limits are not from the reference). The values from\n  # Table 2 will be estimated on the log scale to ensure positive values.\n  # Residual errors are not in the original reference.\n  ini({\n    ldamageTransit <- log(c(0.1, 0.968, 10)) ; label("Transit rate through damage (1/day)")\n    ldrugSlope <- log(c(0.00001, 0.000629, 0.1)) ; label("Linear drug effect on cycling cells (1/(day*ng/mL))")\n    ltumorExpGrowth <- log(c(0.001, 0.273, 2)) ; label("Tumor exponential growth rate (1/day)")\n    ltumorLinGrowth <- log(c(0.01, 0.814, 5)) ; label("Tumor linear growth rate (tumor volume/day)")\n    tumorVolpropSd <- 0.2 ; label("Proportional residual error (fraction)")\n    tumorVoladdSd <- 30 ; label("Additive residual error (tumor volume)")\n  })\n  model({\n    damageTransit <- exp(ldamageTransit)\n    drugSlope <- exp(ldrugSlope)\n    tumorExpGrowth <- exp(ltumorExpGrowth)\n    tumorLinGrowth <- exp(ltumorLinGrowth)\n\n    # tumorVol0 is provided in the data as the initial volume of the tumor.  It\n    # can also be estimated.\n    cyclingCells(0) <- tumorVol0\n    psi <- 20 # psi is defined in the paper to cause a rapid switch between exponential and linear regimes\n    tumorVol <- cyclingCells + damagedCells1 + damagedCells2 + damagedCells3\n    # Cc is provided in the data (or in an appended model) as the drug\n    # concentration.  Units for Cc will be apply to k2.\n    drugEffectCyclingCells <- drugSlope*Cc\n    d/dt(cyclingCells) <- tumorExpGrowth*cyclingCells/(1 + (tumorExpGrowth/tumorLinGrowth * tumorVol)^psi)^(1/psi) - drugEffectCyclingCells*cyclingCells\n    d/dt(damagedCells1) <- drugEffectCyclingCells*cyclingCells - damageTransit*damagedCells1\n    d/dt(damagedCells2) <- damageTransit*(damagedCells1 - damagedCells2)\n    d/dt(damagedCells3) <- damageTransit*(damagedCells2 - damagedCells3)\n    tumorVol ~ prop(tumorVolpropSd) + add(tumorVoladdSd)\n  })\n}\n\nattr(oncology_xenograft_simeoni_2004, "message") <- "You can modify the number of damaged cell compartments in the model using the function updateOncologyXenograftSimeoni2004(model, ncmt)"\noncology_xenograft_simeoni_2004
#>                                                                                                                 Description
#> 1                                                                            One compartment PK model with linear clearance
#> 2                                               One compartment PK model with linear clearance using differential equations
#> 3                                                                            Two compartment PK model with linear clearance
#> 4                                               Two compartment PK model with linear clearance using differential equations
#> 5                                               Two compartment PK model with linear clearance using differential equations
#> 6  Two compartment PK model with time-dependent clearance using differential equations (structured like nivolumab PK model)
#> 7                                                                          Three compartment PK model with linear clearance
#> 8                                             Three compartment PK model with linear clearance using differential equations
#> 9                               Phenylalanine model for absorption and metabolism in healthy subjects and patients with PKU
#> 10                                    Two compartment PK model with Michealis-Menten clearance using differential equations
#> 11                            Two compartment PK model with linear clearance for average monoclonal antibodies (Davda 2014)
#> 12                                                                Liraglutide PK model in adolescents (Carlsson Petri 2021)
#> 13                                                                                      Dupilumab PK model (Kovalenko 2020)
#> 14                                                                                     Tralokinumab PK model (Soehoel 2022)
#> 15                                                                                         Lebrikizumab PK model (Zhu 2017)
#> 16                                        Signal transduction model for delayed concentration effects on cancer cell growth
#> 17                                                                          Oncology tumor growth model in xenograft models

# This will test the models in the catalog, set as_cran
# to FALSE to test all the models.
mtres = MB_test_catalog(state, as_cran=TRUE)
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.R not found (skipping)
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.ctl not found (skipping)
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments
#>  MB: PK_1cmt
mtres$isgood
#> [1] TRUE


# Creates a new empty element
state = MB_new_element(state)

# Delete the current element
state = MB_del_current_element(state)

# Fetch a list of the current element
element = MB_fetch_current_element(state)

# This will attach a model to it:
# Pulling the first model from the catalog
fcn_def  = models[["summary"]][1, ][["Model"]]
fcn_obj  = models[["summary"]][1, ][["Object"]]
mdl_type = models[["summary"]][1, ][["Type"]]
fcn_desc = models[["summary"]][1, ][["Description"]]

# This will build the rxode2 object from the model
mk_rx_res = mk_rx_obj(
  type  = mdl_type,
  model = list(fcn_def = fcn_def,
               fcn_obj = fcn_obj))
#>  
#>  
#>  parameter labels from comments are typically ignored in non-interactive mode
#>  Need to run with the source intact to parse comments

# This will attach the model to the current element
element = MB_update_model(
  state       = state,
  session     = session,
  current_ele = element,
  rx_obj      = mk_rx_res[["capture"]][["rx_obj"]],
  note        = fcn_desc,
  reset       = TRUE)

# You can now place element back in the state
state = MB_set_current_element(state, element)
#> → MB: model checksum updated: 0b09f84fe84da5f2d6447e200a7eab29
#> → MB: module checksum updated:32b0a661fac4db960e766c6e71c62d58

# This will fetch the current component
component = MB_fetch_component(state, element)


fares = MB_fetch_appends(state, element) 

# You can use the component to build the code to generate the model:
gen_code =
  MB_build_code(state        = state, session = session,
              fcn_def      = component[["fcn_def"]],
              fcn_obj_name = "my_fcn_obj",
              rx_obj_name  = "my_obj_name")
#> Error in MB_build_code(state = state, session = session, fcn_def = component[["fcn_def"]],     fcn_obj_name = "my_fcn_obj", rx_obj_name = "my_obj_name"): argument "ts_obj_name" is missing, with no default

# Model code to be included in a larger script
message(paste0(gen_code$model_code, collapse="\n"))
#> Error in eval(expr, envir, enclos): object 'gen_code' not found

# Stand-alone model code
message(paste0(gen_code$model_code_sa, collapse="\n"))
#> Error in eval(expr, envir, enclos): object 'gen_code' not found

# This will fetch the code to regenerate all of the components of this module
message(MB_fetch_code(state))
#> # Model Building ----
#> # Base model: manual====
#> MB_obj_1_fcn = function () 
#> {
#>     description <- "One compartment PK model with linear clearance"
#>     ini({
#>         lka <- 0.45
#>         label("Absorption rate (Ka)")
#>         lcl <- 1
#>         label("Clearance (CL)")
#>         lvc <- 3.45
#>         label("Central volume of distribution (V)")
#>         propSd <- c(0, 0.5)
#>         label("Proportional residual error (fraction)")
#>     })
#>     model({
#>         ka <- exp(lka)
#>         cl <- exp(lcl)
#>         vc <- exp(lvc)
#>         Cc <- linCmt()
#>         Cc ~ prop(propSd)
#>     })
#> }
#> 
#> MB_obj_1_rx =  rxode2::rxode2(MB_obj_1_fcn)
#> 
#> MB_obj_1_ts = list(
#>   system  = "weeks",
#>   details = 
#>     list(months = list(verb = "Months", conv = 2419200), weeks = list(
#>         verb = "Weeks", conv = 604800), days = list(verb = "Days", 
#>         conv = 86400), hours = list(verb = "Hours", conv = 3600))
#> )
#> 
#> 
#> # Base model: user====
#> MB_obj_2_fcn = function () 
#> {
#>     ini({
#>         TV_F1 <- fix(2.22044604925031e-16, 0.744, Inf)
#>         TV_ka <- c(2.22044604925031e-16, 0.282, Inf)
#>         TV_CL <- c(-36.0436533891172, -1.6094379124341, 709.782712893384)
#>         TV_Vc <- c(-36.0436533891172, 1.28370777234479, 709.782712893384)
#>         TV_Vp <- c(-36.0436533891172, 1.01160091167848, 709.782712893384)
#>         TV_Q <- c(-36.0436533891172, -0.29169009384932, 709.782712893384)
#>         TV_MW <- fix(2.22044604925031e-16, 140, Inf)
#>         TV_BM_IC <- c(2.22044604925031e-16, 1000, Inf)
#>         TV_kdeg_BM <- fix(2.22044604925031e-16, 0.1, Inf)
#>         TV_Emax <- c(2.22044604925031e-16, 100, Inf)
#>         TV_EC50 <- fix(2.22044604925031e-16, 300, Inf)
#>         prop_err_PK <- c(2.22044604925031e-16, 0.1, Inf)
#>         add_err_PK <- c(2.22044604925031e-16, 0.1, Inf)
#>         add_err_BM <- c(2.22044604925031e-16, 0.1, Inf)
#>         ETAka ~ 0.416
#>         ETACL + ETAVc + ETAVp ~ c(0.09875, 0.0786, 0.116, 0.0619, 
#>             0.0377, 0.0789)
#>         ETAQ ~ 0.699
#>         ETABM_IC ~ 0.05
#>         ETAEmax ~ 0.1
#>     })
#>     model({
#>         F1 = TV_F1
#>         ka = TV_ka * exp(ETAka)
#>         CL = exp(TV_CL) * exp(ETACL)
#>         Vc = exp(TV_Vc) * exp(ETAVc)
#>         Cc = Ac/(Vc)
#>         Vp = exp(TV_Vp) * exp(ETAVp)
#>         Q = exp(TV_Q) * exp(ETAQ)
#>         MW = TV_MW
#>         BM_IC = TV_BM_IC * exp(ETABM_IC)
#>         kdeg_BM = TV_kdeg_BM
#>         Emax = TV_Emax * exp(ETAEmax)
#>         EC50 = TV_EC50
#>         Dinf = 0
#>         WTTV = 70
#>         CL_IND = CL * (1 + SEX_ID * 0.1) * (1 + SUBTYPE_ID * 
#>             0.1)
#>         kel = CL_IND/Vc * ((WT/WTTV))^(-0.35)
#>         kcp = Q/Vc * ((WT/WTTV))^(-0.35)
#>         kpc = Q/Vp * ((WT/WTTV))^(-0.35)
#>         ksyn_BM = kdeg_BM * BM_IC
#>         STIM = 1 + Emax * Cc/(EC50 + Cc)
#>         BM(0) = BM_IC
#>         d/dt(At) = (-ka * At)
#>         d/dt(Ac) = ((ka * At * F1/Vc - kel * Cc - kcp * Cc + 
#>             kpc * Cp * Vp/Vc + Dinf/Vc)) * Vc
#>         d/dt(Cp) = (kcp * Cc * Vc/Vp - kpc * Cp)
#>         d/dt(BM) = ksyn_BM * STIM - (kdeg_BM * BM)
#>         C_ng_ml = Cc * MW
#>         C_ng_ml ~ add(add_err_PK) + prop(prop_err_PK)
#>         BM_obs = BM
#>         BM_obs ~ add(add_err_BM)
#>     })
#> }
#> 
#> MB_obj_2_rx =  rxode2::rxode2(MB_obj_2_fcn)
#> 
#> MB_obj_2_ts = list(
#>   system  = "weeks",
#>   details = 
#>     list(months = list(verb = "Months", conv = 2419200), weeks = list(
#>         verb = "Weeks", conv = 604800), days = list(verb = "Days", 
#>         conv = 86400), hours = list(verb = "Hours", conv = 3600))
#> )
#>