Skip to contents

This returns a new fit object with CWRES attached

Usage

addCwres(fit, focei = TRUE, updateObject = TRUE, envir = parent.frame(1))

Arguments

fit

nlmixr2 fit without WRES/CWRES

focei

Boolean indicating if the focei objective function is added. If not the foce objective function is added.

updateObject

Boolean indicating if the original fit object should be updated. By default this is true.

envir

Environment that should be checked for object to update. By default this is the global environment.

Value

fit with CWRES

Author

Matthew L. Fidler

Examples

# \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 will be replaced by 'label()'
#>  
#>  
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#>  done
#> → finding duplicate expressions in saem model...
#>  done
#> using C compiler: ‘gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0’
#> params:	tka	tcl	tv	V(eta.ka)	V(eta.cl)	V(eta.v)	add.sd
#> rxode2 2.0.13.9000 using 1 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`
#> 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 11.3.0-1ubuntu1~22.04) 11.3.0’
#> → Calculating residuals/tables
#>  done
#> → compress origData in nlmixr2 object, save 5952
#> → compress phiM in nlmixr2 object, save 63664
#> → compress parHist in nlmixr2 object, save 9544
#> → compress saem0 in nlmixr2 object, save 29088

print(f)
#> ── 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
#> elapsed 0.001579   0.010007 1.577 0.052    0.027 2.973414
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>        Parameter  Est.     SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka       Log 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>

# 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 11.3.0-1ubuntu1~22.04) 11.3.0’
#>  done
#> → finding duplicate expressions in FD model...
#> → compiling EBE model...
#>  
#>  
#> using C compiler: ‘gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0’
#>  done
#> → compiling events FD model...
#>  
#>  
#> using C compiler: ‘gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0’
#>  done
#> → Calculating residuals/tables
#>  done
#> ── nlmix SAEM OBJF by FOCEi approximation ──
#> 
#>           OBJF      AIC      BIC Log-likelihood Condition#(Cov) Condition#(Cor)
#> FOCEi 116.9949 373.5947 393.7743      -179.7973        18.15903        1.404028
#> 
#> ── Time (sec $time): ──
#> 
#>            setup covariance  saem table compress    other
#> elapsed 0.001579   0.010007 1.577 0.052    0.027 2.973414
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>        Parameter  Est.     SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka       Log 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 × 20
#>   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
#> # ℹ 8 more variables: cl <dbl>, v <dbl>, tad <dbl>, dosenum <dbl>, WRES <dbl>,
#> #   CPRED <dbl>, CRES <dbl>, CWRES <dbl>

# Note this also adds the FOCEi objective function
# }