### Install babelmixr2 from r-universe Source: https://nlmixr2.github.io/babelmixr2/index.html Installation method using the nlmixr2 r-universe repository. ```R # Download and install babelmixr2 in R install.packages('babelmixr2', repos = c( nlmixr2 = 'https://nlmixr2.r-universe.dev', CRAN = 'https://cloud.r-project.org')) ``` -------------------------------- ### Load babelmixr2 library Source: https://nlmixr2.github.io/babelmixr2/articles/new-estimation.html Initial setup required to access the estimation method framework. ```R library(babelmixr2) ``` -------------------------------- ### Usage of rxUiGet.nlmerStart Source: https://nlmixr2.github.io/babelmixr2/reference/rxUiGet.nlmerStart.html The S3 method for class nlmerStart retrieves starting values from the provided UI object. ```R # S3 method for class 'nlmerStart' rxUiGet(x, ...) ``` -------------------------------- ### rxUiGet.nlmerStart(x, ...) Source: https://nlmixr2.github.io/babelmixr2/reference/rxUiGet.nlmerStart.html Retrieves starting values for nlmer fixed effects from the provided UI object. ```APIDOC ## rxUiGet.nlmerStart ### Description Retrieves starting values for nlmer fixed effects. This method extracts initial estimates for thetas and sets non-Mu etas to 0. ### Signature `rxUiGet(x, ...)` ### Arguments - **x** (rxUiGet list) - Required - The UI object containing the model information. - **...** (dots) - Optional - Additional arguments (currently ignored). ### Value Returns a named numeric vector containing the iniDf estimates for thetas and 0 for nonMuEtas. ``` -------------------------------- ### Install babelmixr2 from CRAN Source: https://nlmixr2.github.io/babelmixr2/index.html Standard installation method for the released version of the package. ```R install.packages("babelmixr2") ``` -------------------------------- ### Example: Retrieving a population parameter index Source: https://nlmixr2.github.io/babelmixr2/reference/babelBpopIdx.html Demonstrates creating a PopED database using nlmixr2 and retrieving the index for the 'pedCL' parameter. ```R if (requireNamespace("PopED", quietly=TRUE)) { f <- function() { ini({ tV <- 72.8 tKa <- 0.25 tCl <- 3.75 tF <- fix(0.9) pedCL <- 0.8 eta.v ~ 0.09 eta.ka ~ 0.09 eta.cl ~0.25^2 prop.sd <- fix(sqrt(0.04)) add.sd <- fix(sqrt(5e-6)) }) model({ V<-tV*exp(eta.v) KA<-tKa*exp(eta.ka) * (pedCL**isPediatric) # add covariate for pediatrics CL<-tCl*exp(eta.cl) Favail <- tF N <- floor(t/TAU)+1 y <- (DOSE*Favail/V)*(KA/(KA - CL/V)) * (exp(-CL/V * (t - (N - 1) * TAU)) * (1 - exp(-N * CL/V * TAU))/(1 - exp(-CL/V * TAU)) - exp(-KA * (t - (N - 1) * TAU)) * (1 - exp(-N * KA * TAU))/(1 - exp(-KA * TAU))) y ~ prop(prop.sd) + add(add.sd) }) } e <- et(c( 1,8,10,240,245)) babel.db <- nlmixr2(f, e, "poped", popedControl(m = 2, groupsize=20, bUseGrouped_xt=TRUE, a=list(c(DOSE=20,TAU=24,isPediatric = 0), c(DOSE=40, TAU=24,isPediatric = 0)))) babelBpopIdx(babel.db, "pedCL") } ``` -------------------------------- ### Display default NONMEM control options Source: https://nlmixr2.github.io/babelmixr2/reference/nonmemControl.html This example shows the default configuration returned by nonmemControl(). ```R nonmemControl() #> $est #> [1] "focei" #> #> $cov #> [1] "r,s" #> #> $advanOde #> [1] "advan13" #> #> $maxeval #> [1] 1e+05 #> #> $print #> [1] 1 #> #> $noabort #> [1] TRUE #> #> $iniSigDig #> [1] 5 #> #> $tol #> [1] 6 #> #> $atol #> [1] 12 #> #> $sstol #> [1] 6 #> #> $ssatol #> [1] 12 #> #> $sigl #> [1] 12 #> #> $muRef #> [1] TRUE #> #> $sigdig #> [1] 3 #> #> $protectZeros #> [1] FALSE #> #> $runCommand #> [1] "" #> #> $outputExtension #> [1] ".lst" #> #> $addProp #> [1] "combined2" #> #> $rxControl #> $scale #> NULL #> #> $method #> liblsoda #> 2 #> #> $atol #> [1] 1e-12 #> #> $rtol #> [1] 1e-06 #> #> $maxsteps #> [1] 70000 #> #> $hmin #> [1] 0 #> #> $hmax #> [1] NA #> #> $hini #> [1] 0 #> #> $maxordn #> [1] 12 #> #> $maxords #> [1] 5 #> #> $covsInterpolation #> nocb #> 2 #> #> $addCov #> [1] TRUE #> #> $returnType #> rxSolve #> 0 #> #> $sigma #> NULL #> #> $sigmaDf #> NULL #> #> $nCoresRV #> [1] 1 #> #> $sigmaIsChol #> [1] FALSE #> #> $sigmaSeparation #> [1] "auto" #> #> $sigmaXform #> identity #> 4 #> #> $nDisplayProgress #> [1] 10000 #> #> $amountUnits #> [1] NA #> #> $timeUnits #> [1] "hours" #> #> $addDosing #> [1] FALSE #> #> $stateTrim #> [1] Inf #> #> $updateObject #> [1] FALSE #> #> $omega #> NULL #> #> $omegaDf #> NULL #> #> $omegaIsChol #> [1] FALSE #> #> $omegaSeparation #> [1] "auto" #> #> $omegaXform #> variance #> 6 #> #> $nSub #> [1] 1 #> #> $thetaMat #> NULL #> #> $thetaDf #> NULL #> #> $thetaIsChol #> [1] FALSE #> #> $nStud #> [1] 1 #> #> $dfSub #> [1] 0 #> #> $dfObs #> [1] 0 #> #> $seed #> NULL #> #> $nsim #> NULL #> #> $minSS #> [1] 10 #> #> $maxSS #> [1] 10000 #> #> $strictSS #> [1] 1 #> #> $infSSstep #> [1] 12 #> #> $istateReset #> [1] TRUE #> #> $subsetNonmem #> [1] TRUE #> #> $hmaxSd #> [1] 0 #> #> $maxAtolRtolFactor #> [1] 0.1 #> #> $from #> NULL #> #> $to #> NULL #> #> $by #> NULL #> #> $length.out #> NULL #> #> $iCov #> NULL #> #> $keep #> NULL #> #> $keepF #> character(0) #> #> $drop #> NULL #> #> $warnDrop #> [1] TRUE #> #> $omegaLower #> [1] -Inf #> #> $omegaUpper #> [1] Inf #> #> $sigmaLower #> [1] -Inf #> #> $sigmaUpper #> [1] Inf #> #> $thetaLower #> [1] -Inf #> #> $thetaUpper #> [1] Inf #> #> $indLinPhiM #> [1] 0 #> #> $indLinPhiTol #> [1] 1e-07 #> #> $indLinMatExpType #> expokit #> 2 #> #> $indLinMatExpOrder #> [1] 6 #> #> $idFactor #> [1] TRUE #> #> $mxhnil #> [1] 0 #> #> $hmxi #> [1] 0 #> #> $warnIdSort #> [1] TRUE #> #> $ssAtol #> [1] 1e-12 #> #> $ssRtol #> [1] 1e-06 #> #> $safeZero #> [1] 0 #> #> $sumType #> pairwise #> 1 #> #> $prodType #> long double #> 1 #> #> $resample #> NULL #> #> $resampleID #> [1] TRUE #> #> $maxwhile #> [1] 100000 #> #> $cores #> [1] 0 #> #> $atolSens #> [1] 1e-08 #> #> $rtolSens #> [1] 1e-06 #> #> $ssAtolSens #> [1] 1e-08 #> #> $ssRtolSens #> [1] 1e-06 #> #> $simVariability #> [1] NA #> #> $nLlikAlloc #> NULL #> #> $useStdPow #> [1] 0 #> #> $naTimeHandle #> ignore #> 1 #> #> $addlKeepsCov #> [1] FALSE #> #> $addlDropSs #> [1] TRUE #> #> $ssAtDoseTime #> [1] TRUE #> #> $ss2cancelAllPending #> [1] FALSE #> #> $naInterpolation #> locf #> 1 #> #> $keepInterpolation #> na #> 2 #> #> $safeLog #> [1] 1 #> #> $safePow #> [1] 1 #> #> $ssSolved #> [1] TRUE #> #> $linCmtSensType #> auto #> 100 #> #> $linCmtSensH #> [1] 1e-04 #> #> $linCmtGillFtol #> [1] 0 #> #> $linCmtGillK #> [1] 20 #> #> $linCmtGillStep #> [1] 4 #> #> $linCmtGillRtol #> [1] 1.490116e-08 #> #> $linCmtShiErr #> [1] 1.490116e-08 #> #> $linCmtShiMax #> [1] 20 #> #> $linCmtScale #> [1] 0 0 0 0 0 0 0 #> #> $linCmtHcmt #> [1] 1 #> #> $linCmtHmeanI #> geometric #> 2 #> #> $linCmtHmeanO #> geometric #> 2 #> #> $linCmtSuspect #> [1] 1e-06 #> #> $linCmtForwardMax #> [1] 2 #> #> $indOwnAlloc #> [1] -1 #> #> $maxExtra #> [1] 1000 #> #> $tolFactor #> NULL #> #> $serializeFile #> NULL #> #> $dense #> [1] FALSE #> #> $cvodeLinSolver #> dense #> 1 #> #> $stiff2 #> [1] 0 #> #> $autoSwitchMaxStiff #> [1] 10 #> #> $autoSwitchMaxNonstiff #> [1] 3 ``` -------------------------------- ### Example of modelUnitConversion Source: https://nlmixr2.github.io/babelmixr2/reference/modelUnitConversion.html Demonstrates how to call the function with specific unit strings to obtain conversion factors and parameter units. ```R modelUnitConversion(dvu = "ng/mL", amtu = "mg", timeu = "hr", volumeu = "L") #> Loading required namespace: testthat #> $amtu #> [1] "mg" #> #> $clearanceu #> [1] "L/h" #> #> $volumeu #> [1] "L" #> #> $timeu #> [1] "hr" #> #> $dvu #> [1] "ng/mL" #> #> $cmtu #> [1] "mg/L" #> #> $dvConversion #> [1] 1000 ``` -------------------------------- ### nlmixr2Est.pknca(env, ...) Source: https://nlmixr2.github.io/babelmixr2/reference/nlmixr2Est.pknca.html Estimates starting parameters for an nlmixr2 model using PKNCA analysis. ```APIDOC ## nlmixr2Est.pknca(env, ...) ### Description Estimates starting parameters for nlmixr2 estimation routines using PKNCA. The function updates the model with new starting parameters and includes an 'nca' element containing the calculation results. ### Arguments - **env** (Environment) - Required - The environment for the nlmixr2 estimation routines. Must contain an `rxode2` ui object in `$ui`, the data to fit in `$data`, and control options in `$ui`. - **...** (dots) - Optional - Additional arguments provided for flexibility, currently not used. ### Value A model object with updated starting parameters and a new 'nca' element containing the PKNCA results. ``` -------------------------------- ### Populate Multiple Endpoint Parameters Source: https://nlmixr2.github.io/babelmixr2/reference/popedMultipleEndpointParam.html Example usage of popedMultipleEndpointParam with defined parameters, times, model switches, and maximum time points. ```R p <- c(1.0, 2.0, 3.0) times <- c(0.5, 1.5, 2.5) modelSwitch <- c(1, 2, 3) maxMT <- 5 popedMultipleEndpointParam(p, times, modelSwitch, maxMT) ``` -------------------------------- ### Example of mapping data frame columns Source: https://nlmixr2.github.io/babelmixr2/reference/getStandardColNames.html Demonstrates mapping specific input columns like ID, DV, Time, and CmT to their standardized rxode2 equivalents. ```R getStandardColNames(data.frame(ID=1, DV=2, Time=3, CmT=4)) #> id time amt rate dur evid cmt ss ii addl dv #> "ID" "Time" NA NA NA NA "CmT" NA NA NA "DV" #> mdv dvid cens limit #> NA NA NA NA ``` -------------------------------- ### Convert Dataset to Monolix Format Source: https://nlmixr2.github.io/babelmixr2/reference/bblDatToMonolix.html Example of using bblDatToNonmem to process a dataset. ```R bblDatToNonmem(pk.turnover.emax3, nlmixr2data::warfarin) #> #> #> ℹ parameter labels from comments are typically ignored in non-interactive mode #> ℹ Need to run with the source intact to parse comments #> ID TIME EVID AMT DV CMT DVID nlmixrRowNums #> 1 1 0.0 1 100.0 NA 1 NA 1 ``` -------------------------------- ### Convert nlmixr2 model and data to Monolix format Source: https://nlmixr2.github.io/babelmixr2/reference/bblDatToMonolix.html This example demonstrates defining a PK/PD turnover model and converting it along with the warfarin dataset into a Monolix-compatible structure. ```R pk.turnover.emax3 <- function() { ini({ tktr <- log(1) tka <- log(1) tcl <- log(0.1) tv <- log(10) ## eta.ktr ~ 1 eta.ka ~ 1 eta.cl ~ 2 eta.v ~ 1 prop.err <- 0.1 pkadd.err <- 0.1 ## temax <- logit(0.8) tec50 <- log(0.5) tkout <- log(0.05) te0 <- log(100) ## eta.emax ~ .5 eta.ec50 ~ .5 eta.kout ~ .5 eta.e0 ~ .5 ## pdadd.err <- 10 }) model({ ktr <- exp(tktr + eta.ktr) ka <- exp(tka + eta.ka) cl <- exp(tcl + eta.cl) v <- exp(tv + eta.v) emax = expit(temax+eta.emax) ec50 = exp(tec50 + eta.ec50) kout = exp(tkout + eta.kout) e0 = exp(te0 + eta.e0) ## DCP = center/v PD=1-emax*DCP/(ec50+DCP) ## effect(0) = e0 kin = e0*kout ## d/dt(depot) = -ktr * depot d/dt(gut) = ktr * depot -ka * gut d/dt(center) = ka * gut - cl / v * center d/dt(effect) = kin*PD -kout*effect ## cp = center / v cp ~ prop(prop.err) + add(pkadd.err) effect ~ add(pdadd.err) | pca }) } bblDatToMonolix(pk.turnover.emax3, nlmixr2data::warfarin) ``` -------------------------------- ### Define a compartmental model for nlmixr2 Source: https://nlmixr2.github.io/babelmixr2/articles/running-pknca.html Setup a standard nlmixr2 model structure including initial estimates and differential equations. ```R library(nlmixr2) library(babelmixr2) one.compartment <- function() { ini({ tka <- log(1.57); label("Ka (1/hr)") tcl <- log(2.72); label("Cl (L/hr)") tv <- log(31.5); label("V (L)") eta.ka ~ 0.6 eta.cl ~ 0.3 eta.v ~ 0.1 add.sd <- 0.7; label("additive residual error (mg/L)") }) # and a model block with the error specification and model specification model({ ka <- exp(tka + eta.ka) cl <- exp(tcl + eta.cl) vc <- exp(tv + eta.v) d/dt(depot) <- -ka * depot d/dt(center) <- ka * depot - cl / vc * center cp <- center / vc cp ~ add(add.sd) }) } ``` -------------------------------- ### Run NONMEM with model piping Source: https://nlmixr2.github.io/babelmixr2/articles/running-nonmem.html Uses model piping to remove parameters and execute a NONMEM run starting from the previous model's best estimates. ```R f2 <- f %>% model(ktr <- exp(tktr)) %>% model(ka <- exp(tka)) %>% model(emax = expit(temax)) %>% nlmixr(data=nlmixr2data::warfarin, est="nonmem", control=nonmemControl(readRounding=FALSE, modelName="pk.turnover.emax4")) ``` -------------------------------- ### Usage of .setupPopEDdatabase Source: https://nlmixr2.github.io/babelmixr2/reference/dot-setupPopEDdatabase.html Initializes the PopED database using the provided UI, design data, and control settings. ```R .setupPopEDdatabase(ui, data, control) ``` -------------------------------- ### .setupPopEDdatabase(ui, data, control) Source: https://nlmixr2.github.io/babelmixr2/reference/dot-setupPopEDdatabase.html Initializes and sets up a PopED database object for use in population design evaluation. ```APIDOC ## .setupPopEDdatabase(ui, data, control) ### Description Sets up the PopED database using the provided UI, design data, and control parameters. ### Arguments - **ui** (rxode2 ui function) - The rxode2 user interface function. - **data** (babelmixr2 design data) - The design data for the PopED model. - **control** (PopED control) - The control parameters for PopED. ### Value Returns a PopED database object. ``` -------------------------------- ### rxUiGet(x, ...) Source: https://nlmixr2.github.io/babelmixr2/reference/rxUiGet.nlmerEnv.html Retrieves the full nlmer symengine environment with sensitivities. ```APIDOC ## rxUiGet(x, ...) ### Description Retrieves the full nlmer symengine environment with sensitivities for the specified object. ### Usage ```R # S3 method for class 'nlmerEnv' rxUiGet(x, ...) ``` ### Arguments - **x** (rxUiGet list) - The ui object. - **...** (dots) - Additional arguments (currently ignored). ``` -------------------------------- ### Create a PopED database Source: https://nlmixr2.github.io/babelmixr2/articles/PopED.html Initializes a PopED database from an nlmixr2 model object with specified design parameters. ```R poped_db_ode_babelmixr2 <- nlmixr(f, e, "poped", popedControl(a=list(c(DOSE=20), c(DOSE=40)), maxa=c(DOSE=200), mina=c(DOSE=0))) ``` -------------------------------- ### Usage of nlmixr2Est for pknca Source: https://nlmixr2.github.io/babelmixr2/reference/nlmixr2Est.pknca.html The S3 method for class pknca used to estimate starting parameters within the nlmixr2 estimation environment. ```R # S3 method for class 'pknca' nlmixr2Est(env, ...) ``` -------------------------------- ### Inspect the prepared model Source: https://nlmixr2.github.io/babelmixr2/articles/running-pknca.html Access the updated model UI after running the PKNCA estimation. ```R prepared$ui ``` -------------------------------- ### babel.poped.database(popedInput, ..., optTime = NA) Source: https://nlmixr2.github.io/babelmixr2/reference/babel.poped.database.html Expands a babelmixr2 PopED database with additional parameters and configuration options. ```APIDOC ## babel.poped.database ### Description Expands a babelmixr2 generated PopED database. ### Usage `babel.poped.database(popedInput, ..., optTime = NA)` ### Arguments - **popedInput** - The babelmixr2 generated PopED database. - **...** - Other parameters sent to `PopED::create.poped.database()`. - **optTime** (boolean) - Optional. Indicates if the global time indexer inside of babelmixr2 is reset if the times are different. Defaults to TRUE. ### Value Returns a babelmixr2 PopED database (with $babelmixr2 in database). ``` -------------------------------- ### Inspect PopED model for general scenarios Source: https://nlmixr2.github.io/babelmixr2/articles/PopED.html Displays the rxode2 model summary used for solving scenarios with arbitrary time points. ```R summary(poped_db_ode_babelmixr2$babelmixr2$modelF) #> rxode2 5.1.4 model named rx_577a57d12b3ff2241d58f46e855615ec model (✔ ready). #> DLL: /tmp/Rtmp1KJ91H/rxode2/rx_577a57d12b3ff2241d58f46e855615ec__.rxd/rx_577a57d12b3ff2241d58f46e855615ec_.so #> NULL #> #> Calculated Variables: #> [1] "rx_pred_" "rx_r_" #> ── rxode2 Model Syntax ── #> rxode2({ #> param(rx__tKA, rx__tCL, rx__tV, rx__eta.ka, rx__eta.v, rx__eta.cl, #> DOSE) #> ka ~ rx__tKA * exp(rx__eta.ka) #> v ~ rx__tV * exp(rx__eta.v) #> cl ~ rx__tCL * exp(rx__eta.cl) #> d/dt(depot) = -ka * depot #> d/dt(central) = ka * depot - cl/v * central #> cp ~ central/v #> f(depot) = DOSE * 0.9 #> rx_yj_ ~ 2 #> rx_lambda_ ~ 1 #> rx_low_ ~ 0 #> rx_hi_ ~ 1 #> rx_pred_f_ ~ cp #> rx_pred_ = rx_pred_f_ #> rx_r_ = (0.05)^2 + (rx_pred_f_)^2 * (0.2)^2 #> }) ``` -------------------------------- ### Obtain initial estimates with PKNCA Source: https://nlmixr2.github.io/babelmixr2/index.html Use PKNCA to calculate scaling factors and initial conditions for an nlmixr2 model. ```R mod <- nlmixr2( nlmixrFun, nlmmixrData, est = "pknca", control = pkncaControl(concu = "ng/mL", doseu = "mg", timeu = "hr", volumeu = "L") ) ``` -------------------------------- ### Logit Regression with Emax Model using pseudoOptim Source: https://nlmixr2.github.io/babelmixr2/reference/pseudoOptimControl.html Demonstrates fitting a model using the pseudoOptim estimation method. Requires all parameters to be bounded within the ini block. ```R # \donttest{ # A logit regression example with emax model dsn <- data.frame(i=1:1000) dsn$time <- exp(rnorm(1000)) dsn$DV=rbinom(1000,1,exp(-1+dsn$time)/(1+exp(-1+dsn$time))) mod <- function() { ini({ # This estimation method requires all parameters # to be bounded: E0 <- c(-100, 0.5, 100) Em <- c(0, 0.5, 10) E50 <- c(0, 2, 20) g <- fix(c(0.1, 2, 10)) }) model({ v <- E0+Em*time^g/(E50^g+time^g) ll(bin) ~ DV * v - log(1 + exp(v)) }) } fit2 <- nlmixr(mod, dsn, est="pseudoOptim") print(fit2) ``` -------------------------------- ### Benchmarking PopED methods Source: https://nlmixr2.github.io/babelmixr2/articles/PopED.html Compare the speed of different PopED evaluation methods using microbenchmark. ```R library(ggplot2) library(microbenchmark) compare <- microbenchmark( evaluate_design(poped_db_analytic), evaluate_design(poped_db_analytic_babelmixr2), evaluate_design(poped_db_ode_babelmixr2), evaluate_design(poped_db_ode_mrg), evaluate_design(poped_db_ode_pkpdsim), evaluate_design(poped_db_ode_rx), times = 100L) autoplot(compare) + theme_bw() #> Warning: `aes_string()` was deprecated in ggplot2 3.0.0. #> ℹ Please use tidy evaluation idioms with `aes()`. #> ℹ See also `vignette("ggplot2-in-packages")` for more information. #> ℹ The deprecated feature was likely used in the microbenchmark package. #> Please report the issue at #> . #> This warning is displayed once per session. #> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was #> generated. ``` -------------------------------- ### Initialize nlmixr2NlmerControl Source: https://nlmixr2.github.io/babelmixr2/reference/nlmixr2NlmerControl.html Displays the default configuration object returned by calling the nlmixr2NlmerControl function. ```R nlmixr2NlmerControl() ``` -------------------------------- ### Usage of rxUiGet for nlmerEnv Source: https://nlmixr2.github.io/babelmixr2/reference/rxUiGet.nlmerEnv.html Retrieves the full nlmer symengine environment with sensitivities using the S3 method for the nlmerEnv class. ```R # S3 method for class 'nlmerEnv' rxUiGet(x, ...) ``` -------------------------------- ### Inspect PopED model with time points Source: https://nlmixr2.github.io/babelmixr2/articles/PopED.html Displays the rxode2 model summary configured for solving at specific design times. ```R summary(poped_db_ode_babelmixr2$babelmixr2$modelMT) #> rxode2 5.1.4 model named rx_7b71512a0bee458b095ac54be664665b model (✔ ready). #> DLL: /tmp/Rtmp1KJ91H/rxode2/rx_7b71512a0bee458b095ac54be664665b__.rxd/rx_7b71512a0bee458b095ac54be664665b_.so #> NULL #> #> Calculated Variables: #> [1] "rx_pred_" "rx_r_" #> ── rxode2 Model Syntax ── #> rxode2({ #> param(rx__tKA, rx__tCL, rx__tV, rx__eta.ka, rx__eta.v, rx__eta.cl, #> DOSE, rxXt_1, rxXt_2, rxXt_3, rxXt_4, rxXt_5) #> ka ~ rx__tKA * exp(rx__eta.ka) #> v ~ rx__tV * exp(rx__eta.v) #> cl ~ rx__tCL * exp(rx__eta.cl) #> d/dt(depot) = -ka * depot #> d/dt(central) = ka * depot - cl/v * central #> cp ~ central/v #> f(depot) = DOSE * 0.9 #> rx_yj_ ~ 2 #> rx_lambda_ ~ 1 #> rx_low_ ~ 0 #> rx_hi_ ~ 1 #> rx_pred_f_ ~ cp #> rx_pred_ = rx_pred_f_ #> rx_r_ = (0.05)^2 + (rx_pred_f_)^2 * (0.2)^2 #> mtime(rxXt_1_v) ~ rxXt_1 #> mtime(rxXt_2_v) ~ rxXt_2 #> mtime(rxXt_3_v) ~ rxXt_3 #> mtime(rxXt_4_v) ~ rxXt_4 #> mtime(rxXt_5_v) ~ rxXt_5 #> }) ``` -------------------------------- ### Logit regression with Emax model using fmeMcmc Source: https://nlmixr2.github.io/babelmixr2/reference/fmeMcmcControl.html Demonstrates setting up a dataset and model, then fitting it using the fmeMcmc estimation method. ```R dsn <- data.frame(i=1:1000) dsn$time <- exp(rnorm(1000)) dsn$DV=rbinom(1000,1,exp(-1+dsn$time)/(1+exp(-1+dsn$time))) mod <- function() { ini({ E0 <- 0.5 Em <- 0.5 E50 <- 2 g <- fix(2) }) model({ v <- E0+Em*time^g/(E50^g+time^g) ll(bin) ~ DV * v - log(1 + exp(v)) }) } fit2 <- nlmixr(mod, dsn, est="fmeMcmc") print(fit2) ``` -------------------------------- ### Usage of popedGetMultipleEndpointModelingTimes and popedMultipleEndpointIndexDataFrame Source: https://nlmixr2.github.io/babelmixr2/reference/popedGetMultipleEndpointModelingTimes.html Demonstrates how to define times and model switches to retrieve sorted modeling times and visualize the internal endpoint index data frame. ```R times <- c(1.1, 1.2, 1.3, 2.1, 2.2, 3.1) modelSwitch <- c(1, 1, 1, 2, 2, 3) sortedTimes <- popedGetMultipleEndpointModelingTimes(times, modelSwitch, TRUE) print(sortedTimes) #> [1] 1.1 1.2 1.3 2.1 2.2 3.1 # now show the output of the data frame representing the model # switch to endpoint index popedMultipleEndpointIndexDataFrame() #> time MS:1 N:1 MS:3 N:3 MS:5 N:5 #> 1 1.1 1 1 NA NA NA NA #> 2 1.2 2 1 NA NA NA NA #> 3 1.3 3 1 NA NA NA NA #> 4 2.1 NA NA 4 1 NA NA #> 5 2.2 NA NA 5 1 NA NA #> 6 3.1 NA NA NA NA 6 1 # now show a more complex example with overlaps etc. times <- c(1.1, 1.2, 1.3, 0.5, 2.2, 1.1, 0.75,0.75) modelSwitch <- c(1, 1, 1, 2, 2, 2, 3, 3) sortedTimes <- popedGetMultipleEndpointModelingTimes(times, modelSwitch, TRUE) print(sortedTimes) #> [1] 0.50 0.75 1.10 1.20 1.30 2.20 popedMultipleEndpointIndexDataFrame(TRUE) # Print to show individual matching #> modelSwitch: 2 time: 0.500000: 4 #> modelSwitch: 3 time: 0.750000: 7, 8 #> modelSwitch: 2 time: 1.100000: 6 #> modelSwitch: 1 time: 1.100000: 1 #> modelSwitch: 1 time: 1.200000: 2 #> modelSwitch: 1 time: 1.300000: 3 #> modelSwitch: 2 time: 2.200000: 5 #> time MS:1 N:1 MS:3 N:3 MS:5 N:5 #> 1 0.50 NA NA 4 1 NA NA #> 2 0.75 NA NA NA NA 7 2 #> 3 1.10 1 1 6 1 NA NA #> 4 1.20 2 1 NA NA NA NA #> 5 1.30 3 1 NA NA NA NA #> 6 2.20 NA NA 5 1 NA NA ``` -------------------------------- ### rxUiGet.nlmerFormula(x, ...) Source: https://nlmixr2.github.io/babelmixr2/reference/rxUiGet.nlmerFormula.html Builds the full 3-part nlmer formula for use with lme4::nlmer. ```APIDOC ## rxUiGet.nlmerFormula ### Description Builds the full 3-part nlmer formula required for lme4::nlmer estimation. ### Usage ```R # S3 method for class 'nlmerFormula' rxUiGet(x, ...) ``` ### Arguments - **x** (rxUiGet list) - Required - The ui object. - **...** (dots) - Optional - Additional arguments (currently ignored). ### Value Returns a 3-part formula object compatible with lme4::nlmer. ``` -------------------------------- ### Create saemixControl structure Source: https://nlmixr2.github.io/babelmixr2/reference/saemixControl.html Initializes the control object with a specified random seed. ```R # \donttest{ # Example showing control creation: ctrl <- saemixControl(seed = 123456) # } ``` -------------------------------- ### Run Monolix model via nlmixr2 Source: https://nlmixr2.github.io/babelmixr2/index.html Convert an nlmixr2 model to Monolix, execute it, and import the results back. ```R mod <- nlmixr(nlmixrFun, nlmmixrData, est="monolix") ``` -------------------------------- ### Cite the nlmixr algorithm performance article Source: https://nlmixr2.github.io/babelmixr2/authors.html BibTeX entry for the 2019 CPT: Pharmacometrics & Systems Pharmacology article comparing SAEM and FOCEI algorithms. ```bibtex @Article{, title = {Performance of the SAEM and FOCEI Algorithms in the Open-Source, Nonlinear Mixed Effect Modeling Tool nlmixr}, author = {Rik Schoemaker and Matthew Fidler and Christian Laveille and Justin Wilkins and Richard Hooijmaijers and Teun Post and Mirjam Trame and Yuan Xiong and Wenping Wang}, journal = {CPT: Pharmacometrics \& Systems Pharmacology}, year = {2019}, volume = {8}, pages = {923--930}, number = {12}, month = {dec}, abstract = {The free and open-source package nlmixr implements pharmacometric nonlinear mixed effects model parameter estimation in R. It provides a uniform language to define pharmacometric models using ordinary differential equations. Performances of the stochastic approximation expectation-maximization (SAEM) and first order-conditional estimation with interaction (FOCEI) algorithms in nlmixr were compared with those found in the industry standards, Monolix and NONMEM, using the following two scenarios: a simple model fit to 500 sparsely sampled data sets and a range of more complex compartmental models with linear and nonlinear clearance fit to data sets with rich sampling. Estimation results obtained from nlmixr for FOCEI and SAEM matched the corresponding output from NONMEM/FOCEI and Monolix/SAEM closely both in terms of parameter estimates and associated standard errors. These results indicate that nlmixr may provide a viable alternative to existing tools for pharmacometric parameter estimation.}, } ```