Skip to contents

Time a part of a nlmixr operation and add to nlmixr object

Usage

nlmixrWithTiming(name, code, envir = NULL)

Arguments

name

Name of the timing to be integrated

code

Code to be evaluated and timed

envir

can be either the nlmixr2 fit data, the nlmixr2 fit environment or NULL, which implies it is going to be added to the nlmixr fit when it is finalized. If the function is being called after a fit is created, please supply this environmental variable

Value

Result of code

Author

Matthew L. Fidler

Examples


# \donttest{

one.cmt <- function() {
 ini({
   ## You may label each parameter with a comment
   tka <- 0.45 # Ka
   tcl <- log(c(0, 2.7, 100)) # Log Cl
   ## This works with interactive models
   ## You may also label the preceding line with label("label text")
   tv <- 3.45; label("log V")
   ## the label("Label name") works with all models
   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)
 })
}
fit <- nlmixr(one.cmt, theo_sd, est="saem")
#>  
#>  
#>  
#>  
#>  parameter labels from comments will be replaced by 'label()'
#>  
#>  
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#>  done
#> → finding duplicate expressions in saem model...
#>  done
#> params:	tka	tcl	tv	V(eta.ka)	V(eta.cl)	V(eta.v)	add.sd
#> Calculating covariance matrix
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#>  done
#> → finding duplicate expressions in saem predOnly model 0...
#> → finding duplicate expressions in saem predOnly model 1...
#> → finding duplicate expressions in saem predOnly model 2...
#>  done
#>  
#>  
#> → Calculating residuals/tables
#>  done
#> → compress origData in nlmixr2 object, save 5952
#> → compress phiM in nlmixr2 object, save 63664
#> → compress parHistData in nlmixr2 object, save 13816
#> → compress saem0 in nlmixr2 object, save 27336

nlmixrWithTiming("time1", {
   Sys.sleep(1)
   # note this can be nested, time1 will exclude the timing from time2
   nlmixrWithTiming("time2", {
      Sys.sleep(1)
   }, envir=fit)
}, envir=fit)

print(fit)
#> ── nlmix SAEM OBJF by FOCEi approximation ──
#> 
#>  Gaussian/Laplacian Likelihoods: AIC() or $objf etc. 
#>  FOCEi CWRES & Likelihoods: addCwres() 
#> 
#> ── Time (sec $time): ──
#> 
#>            setup covariance saem table compress    other time2 time1
#> elapsed 0.001049   0.008005 1.08 0.068    0.019 1.053946 1.002 1.002
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>        Parameter  Est.     SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka           Ka 0.453  0.195 43.1       1.57 (1.07, 2.31)     71.4    -0.445% 
#> tcl       Log Cl  1.02 0.0843 8.29       2.76 (2.34, 3.26)     27.2      3.88% 
#> tv         log V  3.45 0.0467 1.35       31.5 (28.8, 34.5)     13.9      10.2% 
#> add.sd           0.695                               0.695                     
#>  
#>   Covariance Type ($covMethod): linFim
#>   No correlations in between subject variability (BSV) matrix
#>   Full BSV covariance ($omega) or correlation ($omegaR; diagonals=SDs) 
#>   Distribution stats (mean/skewness/kurtosis/p-value) available in $shrink 
#>   Censoring ($censInformation): No censoring
#> 
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 16
#>   ID     TIME    DV  PRED    RES IPRED   IRES  IWRES eta.ka eta.cl   eta.v    ka
#>   <fct> <dbl> <dbl> <dbl>  <dbl> <dbl>  <dbl>  <dbl>  <dbl>  <dbl>   <dbl> <dbl>
#> 1 1      0     0.74  0     0.74   0     0.74   1.07   0.107 -0.485 -0.0809  1.75
#> 2 1      0.25  2.84  3.26 -0.424  3.87 -1.03  -1.49   0.107 -0.485 -0.0809  1.75
#> 3 1      0.57  6.57  5.84  0.726  6.82 -0.250 -0.360  0.107 -0.485 -0.0809  1.75
#> # ℹ 129 more rows
#> # ℹ 4 more variables: cl <dbl>, v <dbl>, tad <dbl>, dosenum <dbl>

# }