Skip to contents

This page shows a simple work-flow for directly simulating a different dosing paradigm than what was modeled.

Step 1: Import the model

library(nonmem2rx)
library(rxode2)

library(nonmem2rx)

# First we need the location of the nonmem control stream Since we are running an example, we will use one of the built-in examples in `nonmem2rx`
ctlFile <- system.file("mods/cpt/runODE032.ctl", package="nonmem2rx")
# You can use a control stream or other file. With the development
# version of `babelmixr2`, you can simply point to the listing file

mod <- nonmem2rx(ctlFile, lst=".res", save=FALSE, determineError=FALSE)
#>  getting information from  '/home/runner/work/_temp/Library/nonmem2rx/mods/cpt/runODE032.ctl'
#>  reading in xml file
#>  done
#>  reading in ext file
#>  done
#>  reading in phi file
#>  done
#>  reading in lst file
#>  abbreviated list parsing
#>  done
#>  done
#>  splitting control stream by records
#>  done
#>  Processing record $INPUT
#>  Processing record $MODEL
#>  Processing record $gTHETA
#>  Processing record $OMEGA
#>  Processing record $SIGMA
#>  Processing record $PROBLEM
#>  Processing record $DATA
#>  Processing record $SUBROUTINES
#>  Processing record $PK
#>  Processing record $DES
#>  Processing record $ERROR
#>  Processing record $ESTIMATION
#>  Ignore record $ESTIMATION
#>  Processing record $COVARIANCE
#>  Ignore record $COVARIANCE
#>  Processing record $TABLE
#>  change initial estimate of `theta1` to `1.37034036528946`
#>  change initial estimate of `theta2` to `4.19814911033061`
#>  change initial estimate of `theta3` to `1.38003493562413`
#>  change initial estimate of `theta4` to `3.87657341967489`
#>  change initial estimate of `theta5` to `0.196446108190896`
#>  change initial estimate of `eta1` to `0.101251418415006`
#>  change initial estimate of `eta2` to `0.0993872449483344`
#>  change initial estimate of `eta3` to `0.101302674763154`
#>  change initial estimate of `eta4` to `0.0730497519364148`
#>  read in nonmem input data (for model validation): /home/runner/work/_temp/Library/nonmem2rx/mods/cpt/Bolus_2CPT.csv
#>  ignoring lines that begin with a letter (IGNORE=@)'
#>  applying names specified by $INPUT
#>  subsetting accept/ignore filters code: .data[-which((.data$SD == 0)),]
#>  done
#>  read in nonmem IPRED data (for model validation): /home/runner/work/_temp/Library/nonmem2rx/mods/cpt/runODE032.csv
#>  done
#>  changing most variables to lower case
#>  done
#>  replace theta names
#>  done
#>  replace eta names
#>  done (no labels)
#>  renaming compartments
#>  done
#>  solving ipred problem
#>  done
#>  solving pred problem
#>  done

Step 2: Look at a different dosing paradigm

Lets say that in this case instead of a single dose, we want to see what the concentration profile is with a single day of BID dosing. In this case is done by creating a quick event table:

ev <- et(amt=120000, ii=12, until=24) %>%
  et(list(c(0, 2), # add observations in windows
          c(4, 6),
          c(8, 12),
          c(14, 18),
          c(20, 26),
          c(28, 32),
          c(32, 36),
          c(36, 44))) %>%
  et(id=1:10)

Step 3: solve using rxode2

In this step, we solve the model with the new event table for the 10 subjects:

s <- rxSolve(mod, ev)
#>  using nocb interpolation like NONMEM, specify directly to change
#>  using addlKeepsCov=TRUE like NONMEM, specify directly to change
#>  using addlDropSs=TRUE like NONMEM, specify directly to change
#>  using ssAtDoseTime=TRUE like NONMEM, specify directly to change
#>  using safeZero=FALSE since NONMEM does not use protection by default
#>  using safePow=FALSE since NONMEM does not use protection by default
#>  using safeLog=FALSE since NONMEM does not use protection by default
#>  using ss2cancelAllPending=FALSE since NONMEM does not cancel pending doses with SS=2
#>  using sigma from NONMEM
#>  using NONMEM specified atol=1e-12
#>  using NONMEM specified rtol=1e-06
#>  using NONMEM specified ssAtol=1e-12

Note that since this is a nonmem2rx model, the default solving will match the tolerances and methods specified in your NONMEM model.

Step 4: exploring the simulation (by plotting)

This solved object acts the same as any other rxode2 solved object, so you can use the plot() function to see the individual profiles you simulated:

library(ggplot2)
plot(s, ipred) +
  ylab("Concentrations")