### Example: Launching and Cleaning Up Shiny App Source: https://nlmixr2.github.io/rxode2/reference/genShinyApp.template.html Demonstrates how to launch the generated Shiny application and clean up the created directory afterwards. Use `runApp(appDir)` to start the application. ```R # \donttest{ # remove myapp when the example is complete on.exit(unlink("myapp", recursive = TRUE, force = TRUE)) ``` -------------------------------- ### Integrate rxnbinomMu into rxode2 model Source: https://nlmixr2.github.io/rxode2/reference/rxnbinom.html This example shows how to incorporate `rxnbinomMu` with its mean parameterization into an `rxode2` model. Proper event table and simulation setup are required. ```R rx <- function() { model({ a <- rxnbinomMu(10, 40) }) } s <- rxSolve(rx, et) #> #> #> ℹ parameter labels from comments are typically ignored in non-interactive mode #> ℹ Need to run with the source intact to parse comments #> #> ``` -------------------------------- ### Install rxode2 Development Version from GitHub Source: https://nlmixr2.github.io/rxode2-manual/install.html Install development versions of rxode2 components directly from GitHub. Ensure you have the 'devtools' package installed. ```r devtools::install_github("nlmixr2/rxode2parse") devtools::install_github("nlmixr2/rxode2random") devtools::install_github("nlmixr2/rxode2et") devtools::install_github("nlmixr2/rxode2ll") devtools::install_github("nlmixr2/rxode2") ``` -------------------------------- ### Integrate rxnbinom into rxode2 model Source: https://nlmixr2.github.io/rxode2/reference/rxnbinom.html This example demonstrates how to use `rxnbinom` directly within an `rxode2` model definition. Ensure proper setup of event tables and simulation parameters. ```R rx <- function() { model({ a <- rxnbinom(10, 0.5) }) } et <- et(1, id = 1:100) s <- rxSolve(rx, et) #> #> #> ℹ parameter labels from comments are typically ignored in non-interactive mode #> ℹ Need to run with the source intact to parse comments #> #> ``` -------------------------------- ### Example: Simulate Progress Bar Usage Source: https://nlmixr2.github.io/rxode2/reference/rxProgress.html This example demonstrates the typical usage pattern of rxProgress functions within a loop. It initializes the progress bar, simulates work with Sys.sleep, and ensures cleanup with on.exit. ```R f <- function() { on.exit({ rxProgressAbort() }) rxProgress(100) for (i in 1:100) { rxTick() Sys.sleep(1 / 100) } rxProgressStop() } # \donttest{ f() # } ``` -------------------------------- ### Integrate rxbinom within rxode2 Model Source: https://nlmixr2.github.io/rxode2/reference/rxbinom.html This example demonstrates how to use rxbinom directly within an rxode2 model definition. Ensure proper setup of the model and event table for simulation. ```R rx <- function() { model({ a <- rxbinom(1, 0.5) }) } et <- et(1, id = 1:2) s <- rxSolve(rx, et) #> #> #> ℹ parameter labels from comments are typically ignored in non-interactive mode #> ℹ Need to run with the source intact to parse comments #> #> ``` -------------------------------- ### Example: Simulate from Multivariate Normal Source: https://nlmixr2.github.io/rxode2/reference/rxRmvn.html This example demonstrates how to use the rxRmvn function to simulate random vectors from a multivariate normal distribution. It sets up a dimension and a mean vector, similar to examples from the mvnfast package. ```R ## From mvnfast ## Unlike mvnfast, uses threefry simulation d <- 5 mu <- 1:d ``` -------------------------------- ### Install rxode2 Development Version Source: https://nlmixr2.github.io/rxode2/index.html Installs the development versions of rxode2 and rxode2ll from GitHub. Ensure your C++ toolchain supports C++14. ```R # install.packages("devtools") devtools::install_github("nlmixr2/rxode2ll") devtools::install_github("nlmixr2/rxode2") ``` -------------------------------- ### Example Usage with rxode2 Source: https://nlmixr2.github.io/rxode2/reference/dGELU.html Demonstrates how to use the GELU derivative functions within an rxode2 model. ```APIDOC ## Examples ```R # you can use rxode2 as well r <- rxode2({ r1 <- dGELU(time) r2 <- d2GELU(time) r3 <- d3GELU(time) r4 <- d4GELU(time) }) et <- et(c(-2, -1, 0, 1, 2)) rxSolve(r, et) ``` ``` -------------------------------- ### rxode2 Event Table Example Source: https://nlmixr2.github.io/rxode2/reference/et.html Demonstrates the creation of an event table using rxode2, including model definition and library loading. ```r if (FALSE) { # \dontrun{ library(rxode2) library(units) # Model from rxode2 tutorial ``` -------------------------------- ### Example Mixture Model Simulation and Plotting Source: https://nlmixr2.github.io/rxode2/reference/mix.html This example demonstrates a mixture model with two clearance populations. It includes the model definition, simulation using `rxSolve`, and plotting of the simulated results using `plot` and `ipredSim`. Ensure the model source is intact for comment parsing. ```R one.cmt <- function() { ini({ tka <- 0.45 # Log Ka tcl1 <- log(c(0, 2.7, 100)) # Log Cl tcl2 <- log(c(0, 0.1, 120)) # Log Cl tv <- 3.45; label("log V") p1 <- 0.3 eta.ka ~ 0.6 eta.cl ~ 0.3 eta.v ~ 0.1 add.sd <- 0.7 }) model({ ka <- exp(tka + eta.ka) # This is the example mixture model cl <- mix(exp(tcl1 + eta.cl), p1, exp(tcl2 + eta.cl)) v <- exp(tv + eta.v) me <- mixest # This is the assigned mixture estimate mn <- mixnum # This is the number of mixture estimate in the model # This is the uniform mixture estimate used in simualtion to # determine the population mu <- mixunif linCmt() ~ add(add.sd) }) } ``` ```R s <- rxSolve(one.cmt, et(amt=320, ii=12, addl=2, cmt=1) |> et(seq(0, 72)) |> et(id=1:20)) #> #> #> ℹ parameter labels from comments are typically ignored in non-interactive mode #> ℹ Need to run with the source intact to parse comments #> #> plot(s, ipredSim) ``` -------------------------------- ### Install rxode2 from CRAN Source: https://nlmixr2.github.io/rxode2-manual/install.html Use this command to install the stable release of rxode2 from CRAN. ```r install.packages("rxode2") ``` -------------------------------- ### Install rxode2 Development Version from GitHub (R 4.0+) Source: https://nlmixr2.github.io/rxode2-manual/install.html Installs the development version of rxode2 and its components from GitHub. This assumes your C++ toolchain is set up to support C++14, which is often required for packages using StanHeaders. ```r # install.packages("devtools") devtools::install_github("nlmixr2/rxode2parse") devtools::install_github("nlmixr2/rxode2random") devtools::install_github("nlmixr2/rxode2et") devtools::install_github("nlmixr2/rxode2ll") devtools::install_github("nlmixr2/rxode2") ``` -------------------------------- ### rxode2 Model Syntax Example Source: https://nlmixr2.github.io/rxode2-manual/syntax.html An example of rxode2 model syntax, defining parameters, calculating physiological variables, and setting up differential equations for compartments. This syntax is used to build complex pharmacokinetic models. ```rxode2 rxode2({ param(lKbBR, lKbMU, lKbAD, lCLint, eta.LClint, lKbBO, lKbRB, WT) KbBR = exp(lKbBR) KbMU = exp(lKbMU) KbAD = exp(lKbAD) CLint = exp(lCLint + eta.LClint) KbBO = exp(lKbBO) KbRB = exp(lKbRB) CO = (187 * WT^0.81) * 60/1000 QHT = 4 * CO/100 QBR = 12 * CO/100 QMU = 17 * CO/100 QAD = 5 * CO/100 QSK = 5 * CO/100 QSP = 3 * CO/100 QPA = 1 * CO/100 QLI = 25.5 * CO/100 QST = 1 * CO/100 QGU = 14 * CO/100 QHA = QLI - (QSP + QPA + QST + QGU) QBO = 5 * CO/100 QKI = 19 * CO/100 QRB = CO - (QHT + QBR + QMU + QAD + QSK + QLI + QBO + QKI) QLU = QHT + QBR + QMU + QAD + QSK + QLI + QBO + QKI + QRB VLU = (0.76 * WT/100)/1.051 VHT = (0.47 * WT/100)/1.03 VBR = (2 * WT/100)/1.036 VMU = (40 * WT/100)/1.041 VAD = (21.42 * WT/100)/0.916 VSK = (3.71 * WT/100)/1.116 VSP = (0.26 * WT/100)/1.054 VPA = (0.14 * WT/100)/1.045 VLI = (2.57 * WT/100)/1.04 VST = (0.21 * WT/100)/1.05 }) ``` -------------------------------- ### rxSolveSetup Source: https://nlmixr2.github.io/rxode2/reference/rxSolveSetup.html Checks if the memory is installed for a solve. Returns a boolean indicating if the memory is currently free for rxode2. ```APIDOC ## rxSolveSetup ### Description Checks if the memory is installed for a solve. ### Usage ``` rxSolveSetup() ``` ### Value boolean saying if the memnory is currently free for rxode2 ``` -------------------------------- ### Example Usage of rxUdfUiIniLhs Source: https://nlmixr2.github.io/rxode2/reference/rxUdfUiIniLhs.html Demonstrates the output of rxUdfUiIniLhs(). It returns NULL, indicating an empty or uninitialized state, ready for further definition. ```R rxUdfUiIniLhs() #> NULL ``` -------------------------------- ### Example Usage of Package Loading Functions Source: https://nlmixr2.github.io/rxode2/reference/rxode2parseAssignPackagesToLoad.html Demonstrates how to use rxode2parseGetPackagesToLoad() to see the current packages and then rxode2parseAssignPackagesToLoad() to set them (in this case, setting them to the current list). ```r rxode2parseGetPackagesToLoad() #> [1] "rxode2ll" "lotri" rxode2parseAssignPackagesToLoad(rxode2parseGetPackagesToLoad()) #> [1] "rxode2ll" "lotri" ``` -------------------------------- ### Customize Automatic Variable Detection Source: https://nlmixr2.github.io/rxode2/articles/Modifying-Models.html Customize the automatic variable detection in rxode2 models using rxSetPipingAuto(). This example sets the pattern to only include variables starting with 'te'. ```R rxSetPipingAuto(thetamodelVars = rex::rex("te")) mod9 <- mod |> model({ emax <- exp(temax) e0 <- exp(te0 + eta.e0) ec50 <- exp(tec50) kin <- exp(tkin) kout <- exp(tkout) }, append=FALSE) #> ℹ promote `temax` to population parameter with initial estimate 1 #> ℹ promote `te0` to population parameter with initial estimate 1 ``` -------------------------------- ### rxode2 Example: Bid and QD Dosing Regimens Source: https://nlmixr2.github.io/rxode2/reference/add.dosing.html Demonstrates creating bidirectional (bid) and once-daily (qd) dosing regimens for 5 days using rxode2's eventTable functions. ```R library(rxode2) library(units) mod1 <-function(){ ini({ KA <- 2.94E-01 CL <- 1.86E+01 V2 <- 4.02E+01 Q <- 1.05E+01 V3 <- 2.97E+02 Kin <- 1 Kout <- 1 EC50 <- 200 }) model({ C2 <- centr/V2 C3 <- peri/V3 d/dt(depot) <- -KA*depot d/dt(centr) <- KA*depot - CL*C2 - Q*C2 + Q*C3 d/dt(peri) <- Q*C2 - Q*C3 d/dt(eff) <- Kin - Kout*(1-C2/(EC50+C2))*eff }) } ## These are making the more complex regimens of the rxode2 tutorial ## bid for 5 days bid <- et(timeUnits="hr") |> et(amt=10000,ii=12,until=set_units(5, "days")) ## qd for 5 days qd <- et(timeUnits="hr") |> et(amt=20000,ii=24,until=set_units(5, "days")) ## bid for 5 days followed by qd for 5 days et <- seq(bid,qd) |> et(seq(0,11*24,length.out=100)) bidQd <- rxSolve(mod1, et) plot(bidQd, C2) ``` -------------------------------- ### rxode2 Model Setup and Solving Source: https://nlmixr2.github.io/rxode2/articles/rxode2-syntax.html Demonstrates how to define and use an rxode2 model in R. It shows model compilation, parameter definition, initial conditions, and the `solve()` function call with an event table. ```R m1 <- rxode2(model = ode, modName = "m1") # model parameters -- a named vector is required theta <- c(KA=0.29, CL=18.6, V2=40.2, Q=10.5, V3=297, Kin=1, Kout=1, EC50=200) # state variables and their amounts at time 0 (the use of names is # encouraged, but not required) inits <- c(depot=0, centr=0, peri=0, eff=1) # qd1 is an eventTable specification with a set of dosing and sampling # records (code not shown here) solve(theta, event = qd1, inits = inits) ``` -------------------------------- ### rxode2 Example: Infusion and Oral Dosing Regimens Source: https://nlmixr2.github.io/rxode2/reference/add.dosing.html Demonstrates creating infusion and oral (qd) dosing regimens for 5 days each, using rxode2's eventTable functions and specifying compartments by name. ```R ## Now Infusion for 5 days followed by oral for 5 days ## note you can dose to a named compartment instead of using the compartment number infusion <- et(timeUnits = "hr") |> et(amt=10000, rate=5000, ii=24, until=set_units(5, "days"), cmt="centr") qd <- et(timeUnits = "hr") |> et(amt=10000, ii=24, until=set_units(5, "days"), cmt="depot") et <- seq(infusion,qd) infusionQd <- rxSolve(mod1, et) plot(infusionQd, C2) ``` -------------------------------- ### Initialize User-Defined Function LHS Source: https://nlmixr2.github.io/rxode2/reference/rxUdfUiIniLhs.html Call rxUdfUiIniLhs() to get the initial language expression for a user-defined function's LHS. This is typically used as a starting point for defining custom functions in rxode2. ```R rxUdfUiIniLhs() ``` -------------------------------- ### Example Usage Source: https://nlmixr2.github.io/rxode2/reference/rxProgress.html Demonstrates how to use `rxProgress`, `rxTick`, and `rxProgressStop` to show progress during a simulated task. `rxProgressAbort` is used with `on.exit` to ensure the progress bar is handled even if errors occur. ```APIDOC ## Examples ```R f <- function() { on.exit({ rxProgressAbort() }) rxProgress(100) for (i in 1:100) { rxTick() Sys.sleep(1 / 100) } rxProgressStop() } # \donttest{ f() # } ``` ``` -------------------------------- ### Run rxode2 interactive tutorials Source: https://nlmixr2.github.io/rxode2/articles/rxode2-tutorials.html Launches interactive learnr tutorials for rxode2 syntax and event tables. These tutorials require the learnr package and are designed to be run from an R session. ```r learnr::run_tutorial("rxode2-00-syntax", "rxode2") ``` ```r learnr::run_tutorial("rxode2-00-events", "rxode2") ``` -------------------------------- ### Bolus Infusion Examples in RxODE Source: https://nlmixr2.github.io/rxode2/articles/rxode2-events-classic.html These examples show bolus infusions to compartment 1. The first example models bioavailability changes affecting infusion duration, while the second models bioavailability changes affecting the infusion rate. ```rxode2 0 | 10101 | 50 ---|---|--- 0.5 | 0 | 0 1 | 0 | 0 1.5 | 10101 | -50 ``` ```rxode2 0 | 20101 | 50 ---|---|--- 0.5 | 0 | 0 1 | 0 | 0 1.5 | 20101 | -50 ``` -------------------------------- ### Get List of Supported Functions Source: https://nlmixr2.github.io/rxode2/reference/rxSupportedFuns.html Call `rxSupportedFuns()` to get a list of supported functions in rxode2. This function requires no arguments. ```r rxSupportedFuns() ``` -------------------------------- ### Initialize a New Package for rxode2 Models Source: https://nlmixr2.github.io/rxode2/articles/rxode2-rxUse.html Set up a new R package to include rxode2 models. This involves creating the package structure, setting licenses, and declaring dependencies on `rxode2`. ```R library(rxode2) library(usethis) pkgPath <- file.path(rxTempDir(),"MyRxModel") create_package(pkgPath); use_gpl3_license("Matt") use_package("rxode2", "LinkingTo") use_package("rxode2", "Depends") ## library(rxode2) on load; Can use imports instead. use_roxygen_md() ##use_readme_md() ``` -------------------------------- ### Complex dosing regimen simulation Source: https://nlmixr2.github.io/rxode2/reference/etRep.html This example demonstrates creating a complex dosing regimen by combining bid and qd schedules, then simulating it using rxSolve. It requires the rxode2 and units packages. ```R library(rxode2) library(units) mod1 <-function(){ ini({ KA <- 2.94E-01 CL <- 1.86E+01 V2 <- 4.02E+01 Q <- 1.05E+01 V3 <- 2.97E+02 Kin <- 1 Kout <- 1 EC50 <- 200 }) model({ C2 <- centr/V2 C3 <- peri/V3 d/dt(depot) <- -KA*depot d/dt(centr) <- KA*depot - CL*C2 - Q*C2 + Q*C3 d/dt(peri) <- Q*C2 - Q*C3 d/dt(eff) <- Kin - Kout*(1-C2/(EC50+C2))*eff }) } ## These are making the more complex regimens of the rxode2 tutorial ## bid for 5 days bid <- et(timeUnits="hr") |> et(amt=10000,ii=12,until=set_units(5, "days")) ## qd for 5 days qd <- et(timeUnits="hr") |> et(amt=20000,ii=24,until=set_units(5, "days")) ## bid for 5 days followed by qd for 5 days et <- seq(bid,qd) |> et(seq(0,11*24,length.out=100)) bidQd <- rxSolve(mod1, et) plot(bidQd, C2) ``` -------------------------------- ### rxode2 EventTable Creation Source: https://nlmixr2.github.io/rxode2/reference/rxode2.html Demonstrates the creation of an EventTable for rxode2 simulations. It sets up QD dosing for 5 days and defines sampling times. ```R # Step 2 - Create the model input as an EventTable, # including dosing and observation (sampling) events # QD (once daily) dosing for 5 days. qd <- et(amountUnits = "ug", timeUnits = "hours") |> et(amt = 10000, addl = 4, ii = 24) # Sample the system hourly during the first day, every 8 hours # then after qd <- qd |> et(0:24) |> et(from = 24 + 8, to = 5 * 24, by = 8) ``` -------------------------------- ### Install Rtools on Windows Source: https://nlmixr2.github.io/rxode2-manual/install.html Installs Rtools on Windows using the 'installr' package. This is necessary for compiling R packages that require a C/C++ toolchain. ```r install.packages("installr") library(installr) install.rtools() ``` -------------------------------- ### Install symengine dependencies on macOS Source: https://nlmixr2.github.io/rxode2-manual/install.html Installs necessary dependencies (cmake, gmp, mpfr, libmpc) for compiling the 'symengine' package on macOS using Homebrew. ```bash brew install cmake gmp mpfr libmpc ``` -------------------------------- ### rxode2 String Handling Example 1 Source: https://nlmixr2.github.io/rxode2/reference/rxode2.html Demonstrates how strings are handled in rxode2 models. This example shows a conditional assignment to a string variable 'tAPGAR'. ```R if (APGAR == 10 || APGAR == 8 || APGAR == 9) { tAPGAR <- "High" } else if (APGAR == 1 || APGAR == 2 || APGAR == 3) { tAPGAR <- "Low" } else if (APGAR == 4 || APGAR == 5 || APGAR == 6 || APGAR == 7) { tAPGAR <- "Med" } else { tAPGAR<- "Med" } ``` -------------------------------- ### rxode2 Model Specification Example Source: https://nlmixr2.github.io/rxode2-manual/syntax.html This is a basic example of an rxode2 model specification, including conditional logic for bioavailability and differential equations for compartments and effect. ```rxode2 # An rxode2 model specification (this line is a comment). if(comed==0){ # concomitant medication (con-med)? F = 1.0; # full bioavailability w.o. con-med } else { F = 0.80; # 20% reduced bioavailability } C2 = centr/V2; # concentration in the central compartment C3 = peri/V3; # concentration in the peripheral compartment # ODE describing the PK and PD d/dt(depot) = -KA*depot; d/dt(centr) = F*KA*depot - CL*C2 - Q*C2 + Q*C3; d/dt(peri) = Q*C2 - Q*C3; d/dt(eff) = Kin - Kout*(1-C2/(EC50+C2))*eff; ``` -------------------------------- ### Simulate with Dosing Windows Source: https://nlmixr2.github.io/rxode2/articles/rxode2-event-table.html Simulate a model using an event table with defined dosing windows. This example adds sampling times to the previously defined event table and then solves and plots the simulation. ```R ev <- ev |> et(seq(0,48,length.out=200)) solve(m1, ev, params=data.frame(KA=0.294*exp(rnorm(4)), CL=18.6*exp(rnorm(4)))) |> plot(C2) ``` -------------------------------- ### RxODE2 Simulation with lapply Source: https://nlmixr2.github.io/rxode2/articles/rxode2-speed.html This example demonstrates a real-life scenario of running rxode2 simulations using `lapply` for parallel processing. It includes defining an ODE model, setting up population parameters with inter-individual variability, and generating simulation data. ```R library(rxode2) library(data.table) #Define the rxode2 model ode1 <- " d/dt(abs) = -KA*abs; d/dt(centr) = KA*abs-(CL/V)*centr; C2=centr/V; " #Create the rxode2 simulation object mod1 <- rxode2(model = ode1) ``` ```R #Population parameter values on log-scale paramsl <- c(CL = log(4), V = log(70), KA = log(1)) #make 10,000 subjects to sample from: nsubg <- 300 # subjects per dose doses <- c(10, 30, 60, 120) nsub <- nsubg * length(doses) #IIV of 30% for each parameter omega <- diag(c(0.09, 0.09, 0.09))# IIV covariance matrix sigma <- 0.2 #Sample from the multivariate normal set.seed(98176247) rxSetSeed(98176247) library(MASS) mv <- mvrnorm(nsub, rep(0, dim(omega)[1]), omega) # Sample from covariance matrix #Combine population parameters with IIV params.all <- data.table( "ID" = seq(1:nsub), "CL" = exp(paramsl['CL'] + mv[, 1]), "V" = exp(paramsl['V'] + mv[, 2]), "KA" = exp(paramsl['KA'] + mv[, 3]) ) #set the doses (looping through the 4 doses) params.all[, AMT := rep(100 * doses,nsubg)] ``` ```R Startlapply <- Sys.time() #Run the simulations using lapply for speed s = lapply(1:nsub, function(i) { #selects the parameters associated with the subject to be simulated params <- params.all[i] #creates an eventTable with 7 doses every 24 hours ev <- eventTable() ev$add.dosing( dose = params$AMT, nbr.doses = 1, dosing.to = 1, rate = NULL, start.time = 0 ) #generates 4 random samples in a 24 hour period ev$add.sampling(c(0, sort(round(sample(runif(600, 0, 1440), 4) / 60, 2)))) #runs the rxode2 simulation x <- as.data.table(mod1$run(params, ev)) #merges the parameters and ID number to the simulation output x[, names(params) := params] }) ``` ```R #runs the entire sequence of 100 subjects and binds the results to the object res res = as.data.table(do.call("rbind", s)) Stoplapply <- Sys.time() print(Stoplapply - Startlapply) ``` -------------------------------- ### Install rxode2 Development Version via r-universe Source: https://nlmixr2.github.io/rxode2-manual/install.html Install development versions of rxode2 and its dependencies using the nlmixr2 r-universe repository. This method compiles binaries for macOS and Windows. ```r install.packages(c("dparser", "rxode2ll", "rxode2parse", "rxode2random", "rxode2et", "rxode2"), repos=c(nlmixr2="https://nlmixr2.r-universe.dev", CRAN="https://cloud.r-project.org")) ``` -------------------------------- ### Standard Compilation and Documentation Workflow Source: https://nlmixr2.github.io/rxode2/articles/rxode2-rxUse.html The standard commands to load, document, and install an R package after making changes to rxode2 models or package code. ```R devtools::load_all() devtools::document() devtools::install() ``` -------------------------------- ### rxode2 String Handling Example 2 Source: https://nlmixr2.github.io/rxode2/reference/rxode2.html Shows an alternative to the first example where a string literal 'Med' is replaced by its integer representation '3', leveraging rxode2's automatic type conversion. ```R if (APGAR == 10 || APGAR == 8 || APGAR == 9) { tAPGAR <- "High" } else if (APGAR == 1 || APGAR == 2 || APGAR == 3) { tAPGAR <- "Low" } else if (APGAR == 4 || APGAR == 5 || APGAR == 6 || APGAR == 7) { tAPGAR <- "Med" } else { tAPGAR<- 3 } ``` -------------------------------- ### Steady State with Lagged Bolus Dose (Example) Source: https://nlmixr2.github.io/rxode2-manual/events.html An example of steady-state dosing with a lagged bolus dose, showing the use of event IDs 109 and 101 for trough calculation and dose application. ```rxode2 0 | 109 | 50 | 24 ---|---|---|--- 0 | 101 | 50 | 12 | 119 | 100 | 24 12 | 101 | 100 | ``` -------------------------------- ### mrgsolve $GLOBAL Block Example Source: https://nlmixr2.github.io/rxode2/articles/rxode2-mrgsolve-comparison.html Example of mrgsolve's $GLOBAL block for C++ declarations that persist across model functions. rxode2 lacks a direct equivalent at the model specification level. ```cpp // mrgsolve only $GLOBAL static int call_count = 0; ``` -------------------------------- ### Compile and Inspect Model Source: https://nlmixr2.github.io/rxode2/reference/rxLastCompile.html This example demonstrates compiling a simple rxode2 model and then using `rxLastCompile()` to inspect the compilation results. It shows the expected output format when a model compiles successfully. ```R rxode2({ a <- b }) #> #> #> rxode2 5.0.2 model named rx_56011c882132e5a394aa4d3d0463b63b model (✔ ready). #> value$params: b #> value$lhs: a rxLastCompile() #> using C compiler: ‘gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0’ ``` -------------------------------- ### Set Omega Parameters with ~ Source: https://nlmixr2.github.io/rxode2/reference/ini.html Demonstrates setting 'omega' parameters using the '~' operator for variance-covariance or correlation matrices. ```R etaCL ~ 0.1 ``` -------------------------------- ### Compare rxStateOde with rxState Source: https://nlmixr2.github.io/rxode2/reference/rxStateOde.html This example demonstrates the difference between rxStateOde, which returns only ODE states, and rxState, which returns all states including compartments and sensitivities. Use rxStateOde when you need a focused view of dynamic variables. ```R mod <- rxode2({ Cp <- linCmt(Cl, V, Q2, V2, Q3, V3) ke0 <- log(2)/(50) d/dt(Ce) <- (Cp-Ce)*ke0 }) rxStateOde(mod) #> [1] "Ce" rxState(mod) #> [1] "Ce" "central" "peripheral1" "peripheral2" ``` ```R mod <- rxode2({ Cp <- linCmt(Cl, V, Q2, V2, Q3, V3, ka) ke0 <- log(2)/(50) d/dt(Ce) <- (Cp-Ce)*ke0 }, linCmtSens="linCmtB") rxStateOde(mod) #> [1] "Ce" rxState(mod) #> [1] "Ce" "depot" #> [3] "central" "peripheral1" #> [5] "peripheral2" "rx__sens_central_BY_p1" #> [7] "rx__sens_central_BY_v1" "rx__sens_central_BY_p2" #> [9] "rx__sens_central_BY_p3" "rx__sens_central_BY_p4" #> [11] "rx__sens_central_BY_p5" "rx__sens_central_BY_ka" #> [13] "rx__sens_peripheral1_BY_p1" "rx__sens_peripheral1_BY_v1" #> [15] "rx__sens_peripheral1_BY_p2" "rx__sens_peripheral1_BY_p3" #> [17] "rx__sens_peripheral1_BY_p4" "rx__sens_peripheral1_BY_p5" #> [19] "rx__sens_peripheral1_BY_ka" "rx__sens_peripheral2_BY_p1" #> [21] "rx__sens_peripheral2_BY_v1" "rx__sens_peripheral2_BY_p2" #> [23] "rx__sens_peripheral2_BY_p3" "rx__sens_peripheral2_BY_p4" #> [25] "rx__sens_peripheral2_BY_p5" "rx__sens_peripheral2_BY_ka" #> [27] "rx__sens_depot_BY_ka" ``` -------------------------------- ### Modeled Rate and Duration Infusion in RxODE Source: https://nlmixr2.github.io/rxode2/articles/rxode2-events-classic.html Examples demonstrating modeled rate and duration for infusions. The first shows a modeled rate with a specific amount, and the second shows a modeled duration with a specific amount. ```rxode2 0 | 90101 | 50 ---|---|--- 0 | 70101 | 50 0.5 | 0 | 0 1 | 0 | 0 ``` ```rxode2 0 | 80101 | 50 ---|---|--- 0 | 60101 | 50 0.5 | 0 | 0 1 | 0 | 0 ``` -------------------------------- ### Example of rxUi model definition and assertions Source: https://nlmixr2.github.io/rxode2/reference/assertRxUi.html This example demonstrates how to define a simple one-compartment linear model using `one.cmt` and then apply `assertRxUi` and `assertRxUiSingleEndpoint` to validate its structure. It highlights the usage of these assertion functions in practice. ```R one.cmt <- function() { ini({ tka <- 0.45; label("Ka") tcl <- log(c(0, 2.7, 100)); label("Cl") tv <- 3.45; label("V") eta.ka ~ 0.6 eta.cl ~ 0.3 eta.v ~ 0.1 add.sd <- 0.7 }) model({ ka <- exp(tka + eta.ka) cl <- exp(tcl + eta.cl) v <- exp(tv + eta.v) linCmt() ~ add(add.sd) }) } assertRxUi(one.cmt) assertRxUiSingleEndpoint(one.cmt) ``` -------------------------------- ### Setup and Control Progress Bar Source: https://nlmixr2.github.io/rxode2/reference/rxProgress.html Initialize a progress bar with the total number of operations. Use rxTick to advance the bar, rxProgressStop to complete it, and rxProgressAbort to handle errors or interruptions. ```R rxProgress(num, core = 0L) rxTick() rxProgressStop(clear = TRUE) rxProgressAbort(error = "Aborted calculation") ``` -------------------------------- ### Steady State Dosing in RxODE Source: https://nlmixr2.github.io/rxode2/articles/rxode2-events-classic.html Examples for steady-state dosing. The first shows a simple steady-state dose to compartment 1. The second demonstrates steady-state dosing with superpositioning for morning and afternoon doses. ```rxode2 0 | 110 | 50 | 24 ---|---|---|--- ``` ```rxode2 0 | 110 | 50 | 24 ---|---|---|--- 12 | 120 | 100 | 24 ``` -------------------------------- ### String to Numeric Conversion in rxode2 Source: https://nlmixr2.github.io/rxode2/articles/rxode2-syntax.html Illustrates how strings are converted to numeric values in rxode2. The first example shows a typical R conditional structure for assigning string values. The subsequent examples demonstrate how these strings can be represented by their corresponding numeric indices, especially after pre-declaring levels. ```R if (APGAR == 10 || APGAR == 8 || APGAR == 9) { tAPGAR <- "High" } else if (APGAR == 1 || APGAR == 2 || APGAR == 3) { tAPGAR <- "Low" } else if (APGAR == 4 || APGAR == 5 || APGAR == 6 || APGAR == 7) { tAPGAR <- "Med" } else { tAPGAR<- "Med" } ``` ```R if (APGAR == 10 || APGAR == 8 || APGAR == 9) { tAPGAR <- "High" } else if (APGAR == 1 || APGAR == 2 || APGAR == 3) { tAPGAR <- "Low" } else if (APGAR == 4 || APGAR == 5 || APGAR == 6 || APGAR == 7) { tAPGAR <- "Med" } else { tAPGAR<- 3 } ``` ```R levels(tAPGAR) <- c("Med", "Low", "High") if (APGAR == 10 || APGAR == 8 || APGAR == 9) { tAPGAR <- 3 } else if (APGAR == 1 || APGAR == 2 || APGAR == 3) { tAPGAR <- 2 } else if (APGAR == 4 || APGAR == 5 || APGAR == 6 || APGAR == 7) { tAPGAR <- 1 } else { tAPGAR<- 1 } ``` -------------------------------- ### rxode2parseGetPointerAssignment Source: https://nlmixr2.github.io/rxode2/reference/rxode2parseGetPointerAssignment.html This function gets the currently assigned function pointer assignments. ```APIDOC ## rxode2parseGetPointerAssignment ### Description This function gets the currently assigned function pointer assignments. ### Usage ``` rxode2parseGetPointerAssignment() ``` ### Value The currently assigned pointer assignments ``` -------------------------------- ### Get rxode2 model from object Source: https://nlmixr2.github.io/rxode2/reference/rxGetrxode2.html Retrieves the rxode2 model from an rxode2 family object. ```APIDOC ## rxGetrxode2 ### Description Get rxode2 model from object ### Usage ```R rxGetrxode2(obj) ``` ### Arguments * `obj` (rxode2 family of objects): The input object from which to extract the model. ### Value rxode2 model ``` -------------------------------- ### Create QD dosing regimen for 5 days Source: https://nlmixr2.github.io/rxode2/reference/et.html Create a QD (once a day) dosing event table for 5 days. Ensure time units are set appropriately. ```R qd <- et(timeUnits="hr") |> et(amt=20000,ii=24,until=set_units(5, "days")) ``` -------------------------------- ### Simulate with Geom Distribution Log Likelihood in rxode2 Source: https://nlmixr2.github.io/rxode2/reference/llikGeom.html This example demonstrates how to integrate `llikGeom` and `llikGeomDprob` into an rxode2 model for simulation. It defines an `rxode2` model using a function, sets up an event table (`et`), and then solves the model using `rxSolve`. ```R et <- et(1:10) et$prob <- 0.2 model <- function() { model({ fx <- llikGeom(time, prob) dProb <- llikGeomDprob(time, prob) }) } rxSolve(model, et) ``` -------------------------------- ### get.sampling() - Get Sampling Records Source: https://nlmixr2.github.io/rxode2/reference/eventTable.html Returns a data.frame of sampling time observation records. ```APIDOC ## get.sampling() ### Description Returns a data.frame of sampled observation records. ### Usage ```R get.sampling() ``` ``` -------------------------------- ### Load rxode2 and lotri libraries Source: https://nlmixr2.github.io/rxode2/articles/rxode2-eta-eps-resampling.html Load the necessary libraries for rxode2 modeling and lotri for defining variance-covariance matrices. ```r library(rxode2) #> rxode2 5.0.2 using 2 threads (see ?getRxThreads) #> no cache: create with `rxCreateCache()` library(lotri) ``` -------------------------------- ### Initialize Model with Lotri-Type Syntax for Omega Source: https://nlmixr2.github.io/rxode2/articles/Modifying-Models.html Use lotri-type syntax to set initial estimates for parameters and their covariances within the omega matrix. This method is useful for defining the initial structure of between-subject variability. ```R f4 <- f |> ini(eta.ka + eta.v ~ c(0.6, 0.01, 0.2)) print(f4) ``` -------------------------------- ### get.nobs() - Get Number of Observations Source: https://nlmixr2.github.io/rxode2/reference/eventTable.html Returns the number of observation (not dosing) records in the event table. ```APIDOC ## get.nobs() ### Description Returns the number of observation (not dosing) records. ### Usage ```R get.nobs() ``` ``` -------------------------------- ### get.dosing() - Get Dosing Records Source: https://nlmixr2.github.io/rxode2/reference/eventTable.html Returns a data.frame of dosing records currently in the event table. ```APIDOC ## get.dosing() ### Description Returns a data.frame of dosing records. ### Usage ```R get.dosing() ``` ```