This returns a new fit object with CWRES attached
addCwres(fit, focei = TRUE, updateObject = TRUE, envir = parent.frame(1))nlmixr2 fit without WRES/CWRES
Boolean indicating if the focei objective function is added. If not the foce objective function is added.
Boolean indicating if the original fit object should be updated. By default this is true.
Environment that should be checked for object to update. By default this is the global environment.
fit with CWRES
# \donttest{
one.cmt <- function() {
ini({
## You may label each parameter with a comment
tka <- 0.45 # Log 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)
})
}
f <- try(nlmixr2(one.cmt, theo_sd, "saem"))
#>
#>
#>
#>
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#>
#>
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#> ✔ done
#> → finding duplicate expressions in saem model...
#> ✔ done
#> using C compiler: ‘gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0’
#> ℹ calculate uninformed etas
#> ℹ done
#> params: tka tcl tv V(eta.ka) V(eta.cl) V(eta.v) add.sd
#> rxode2 4.1.1 using 2 threads (see ?getRxThreads)
#> no cache: create with `rxCreateCache()`
#>
#> Attaching package: ‘rxode2’
#> The following objects are masked from ‘package:nlmixr2est’:
#>
#> boxCox, yeoJohnson
#> 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
#>
#>
#> using C compiler: ‘gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0’
#> → Calculating residuals/tables
#> ✔ done
#> → compress origData in nlmixr2 object, save 5952
#> → compress parHistData in nlmixr2 object, save 13904
#> → compress phiM in nlmixr2 object, save 60752
print(f)
#> ── nlmixr² 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
#> elapsed 0.00232 0.008019 7.242 0.143 0.018 9.712661
#>
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#>
#> Parameter Est. SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka 0.46 0.195 42.3 1.58 (1.08, 2.32) 71.0 -0.606%
#> tcl 1.01 0.0838 8.31 2.74 (2.33, 3.23) 27.0 4.04%
#> tv log V 3.45 0.0453 1.31 31.6 (28.9, 34.6) 13.4 9.53%
#> 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
#> Information about run found ($runInfo):
#> • 'one.cmt' has the following user-defined boundaries: tcl which are ignored in 'saem'
#> Censoring ($censInformation): No censoring
#>
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 18
#> ID TIME DV PRED RES IPRED IRES IWRES eta.ka eta.cl eta.v depot
#> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 0 0.74 0 0.74 0 0.74 1.06 0.0883 -0.477 -0.0846 320.
#> 2 1 0.25 2.84 3.27 -0.431 3.84 -0.996 -1.43 0.0883 -0.477 -0.0846 208.
#> 3 1 0.57 6.57 5.85 0.722 6.77 -0.201 -0.290 0.0883 -0.477 -0.0846 119.
#> # ℹ 129 more rows
#> # ℹ 6 more variables: central <dbl>, ka <dbl>, cl <dbl>, v <dbl>, tad <dbl>,
#> # dosenum <dbl>
# even though you may have forgotten to add the cwres, you can add it to the data.frame:
if (!inherits(f, "try-error")) {
f <- try(addCwres(f))
print(f)
}
#>
#>
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of full model...
#> ✔ done
#> → calculate jacobian
#> → calculate ∂(f)/∂(η)
#> → calculate ∂(R²)/∂(η)
#> → finding duplicate expressions in inner model...
#> → optimizing duplicate expressions in inner model...
#> → finding duplicate expressions in EBE model...
#> → optimizing duplicate expressions in EBE model...
#> → compiling inner model...
#>
#>
#> using C compiler: ‘gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0’
#> ✔ done
#> → finding duplicate expressions in FD model...
#> → compiling EBE model...
#>
#>
#> using C compiler: ‘gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0’
#> ✔ done
#> → compiling events FD model...
#>
#>
#> using C compiler: ‘gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0’
#> ✔ done
#> → Calculating residuals/tables
#> ✔ done
#> ── nlmixr² SAEM OBJF by FOCEi approximation ──
#>
#> OBJF AIC BIC Log-likelihood Condition#(Cov) Condition#(Cor)
#> FOCEi 116.8908 373.4905 393.6702 -179.7453 19.16562 1.415804
#>
#> ── Time (sec $time): ──
#>
#> setup covariance saem table compress other
#> elapsed 0.00232 0.008019 7.242 0.143 0.018 9.712661
#>
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#>
#> Parameter Est. SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka 0.46 0.195 42.3 1.58 (1.08, 2.32) 71.0 -0.606%
#> tcl 1.01 0.0838 8.31 2.74 (2.33, 3.23) 27.0 4.04%
#> tv log V 3.45 0.0453 1.31 31.6 (28.9, 34.6) 13.4 9.53%
#> 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
#> Information about run found ($runInfo):
#> • 'one.cmt' has the following user-defined boundaries: tcl which are ignored in 'saem'
#> Censoring ($censInformation): No censoring
#>
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 22
#> ID TIME DV PRED RES IPRED IRES IWRES eta.ka eta.cl eta.v depot
#> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 0 0.74 0 0.74 0 0.74 1.06 0.0883 -0.477 -0.0846 320.
#> 2 1 0.25 2.84 3.27 -0.431 3.84 -0.996 -1.43 0.0883 -0.477 -0.0846 208.
#> 3 1 0.57 6.57 5.85 0.722 6.77 -0.201 -0.290 0.0883 -0.477 -0.0846 119.
#> # ℹ 129 more rows
#> # ℹ 10 more variables: central <dbl>, ka <dbl>, cl <dbl>, v <dbl>, tad <dbl>,
#> # dosenum <dbl>, WRES <dbl>, CPRED <dbl>, CRES <dbl>, CWRES <dbl>
# Note this also adds the FOCEi objective function
# }