Skip to contents

nlmixr

Changing models via piping

As in the running nlmixr vignette, Let’s start with a very simple PK example, using the single-dose theophylline dataset generously provided by Dr. Robert A. Upton of the University of California, San Francisco:

library(nlmixr2)

one.compartment <- function() {
  ini({
    tka <- 0.45 # Log Ka
    tcl <- 1 # Log Cl
    ## This works with interactive models
    ## You may also label the preceding line with label("label text")
    tv <- 3.45; # 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)
    d/dt(depot) = -ka * depot
    d/dt(center) = ka * depot - cl / v * center
    cp = center / v 
    cp ~ add(add.sd)
  })
}

We can try the First-Order Conditional Estimation with Interaction (FOCEi) method to find a good solution:

fit <- nlmixr(one.compartment, theo_sd, est="focei",
              control=list(print=0), 
              table=list(npde=TRUE, cwres=TRUE))
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> done

print(fit)
#> ── nlmixr FOCEi (outer: nlminb) ──
#> 
#>           OBJF      AIC      BIC Log-likelihood Condition Number
#> FOCEi 116.8139 373.4137 393.5933      -179.7068         73.85496
#> 
#> ── Time (sec $time): ──
#> 
#>            setup optimize covariance table compress    other
#> elapsed 0.015086 0.466084   0.466086 1.498     0.01 5.700744
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>        Parameter  Est.     SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka       Log Ka 0.474  0.209 44.1       1.61 (1.07, 2.42)     68.9     0.384% 
#> tcl       Log Cl  1.01 0.0943 9.32       2.75 (2.29, 3.31)     26.8      3.87% 
#> tv         log V  3.46 0.0403 1.16       31.8 (29.4, 34.4)     13.9      10.3% 
#> add.sd           0.696                               0.696                     
#>  
#>   Covariance Type ($covMethod): r,s
#>   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 
#>   Minimization message ($message):  
#>     false convergence (8) 
#>   In an ODE system, false convergence may mean "useless" evaluations were performed.
#>   See https://tinyurl.com/yyrrwkce
#>   It could also mean the convergence is poor, check results before accepting fit
#>   You may also try a good derivative free optimization:
#>     nlmixr2(...,control=list(outerOpt="bobyqa"))
#> 
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 28
#>   ID     TIME    DV  EPRED   ERES   NPDE     NPD    PDE    PD  PRED    RES
#>   <fct> <dbl> <dbl>  <dbl>  <dbl>  <dbl>   <dbl>  <dbl> <dbl> <dbl>  <dbl>
#> 1 1      0     0.74 0.0967  0.643  1.24   0.903  0.893  0.817  0     0.74 
#> 2 1      0.25  2.84 3.83   -0.986 -0.486 -0.385  0.313  0.35   3.29 -0.449
#> 3 1      0.57  6.57 6.15    0.422 -1.71   0.0920 0.0433 0.537  5.87  0.705
#> # … with 129 more rows, and 17 more variables: WRES <dbl>, IPRED <dbl>,
#> #   IRES <dbl>, IWRES <dbl>, CPRED <dbl>, CRES <dbl>, CWRES <dbl>,
#> #   eta.ka <dbl>, eta.cl <dbl>, eta.v <dbl>, depot <dbl>, center <dbl>,
#> #   ka <dbl>, cl <dbl>, v <dbl>, tad <dbl>, dosenum <dbl>

Changing and fixing parameter values in models

Something that you may want to do is change initial estimates with a model. It is simple to modify the model definition and change them yourself, but you may also want to change them in a specific way; For example try a range of starting values to see how the system behaves (either by full estimation or by a posthoc estimation). In these situations it can be come tedious to modify the models by hand.

nlmixr provides the ability to:

  1. Change parameter estimates before or after running a model. (ie ini(tka=0.5))
  2. Fix parameters to arbitrary values, or estimated values (ie ini(tka=fix(0.5)) or ini(tka=fix))

The easiest way to illustrate this is by showing a few examples of piping changes to the model:

## Example 1 -- Set inital estimate to 0.5 (shown w/posthoc)
one.ka.0.5 <- fit %>%
    ini(tka=0.5) %>% 
    nlmixr(est="posthoc", control=list(print=0), 
           table=list(cwres=TRUE, npde=TRUE))

print(one.ka.0.5)
## Example 2 -- Fix tka to 0.5 and re-estimate.
one.ka.0.5 <- fit %>%
    ini(tka=fix(0.5)) %>%
    nlmixr(est="focei", control=list(print=0),
           table=list(cwres=TRUE, npde=TRUE))
#> calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> done

print(one.ka.0.5)
#> ── nlmixr FOCEi (outer: nlminb) ──
#> 
#>           OBJF      AIC      BIC Log-likelihood Condition Number
#> FOCEi 116.8498 371.4495 388.7463      -179.7248         11.40363
#> 
#> ── Time (sec $time): ──
#> 
#>            setup optimize covariance table compress    other
#> elapsed 0.001931 0.261644   0.261646 0.996    0.045 0.273779
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>        Parameter  Est.     SE  %RSE Back-transformed(95%CI) BSV(CV%)
#> tka       Log Ka   0.5  FIXED FIXED                    1.65     68.9
#> tcl       Log Cl  1.01  0.113  11.1       2.75 (2.21, 3.43)     26.8
#> tv         log V  3.46 0.0539  1.56       31.8 (28.6, 35.3)     13.9
#> add.sd           0.696                                0.696         
#>        Shrink(SD)%
#> tka        0.309% 
#> tcl         3.89% 
#> tv          10.2% 
#> add.sd            
#>  
#>   Covariance Type ($covMethod): r,s
#>   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 
#>   Minimization message ($message):  
#>     false convergence (8) 
#>   In an ODE system, false convergence may mean "useless" evaluations were performed.
#>   See https://tinyurl.com/yyrrwkce
#>   It could also mean the convergence is poor, check results before accepting fit
#>   You may also try a good derivative free optimization:
#>     nlmixr2(...,control=list(outerOpt="bobyqa"))
#> 
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 28
#>   ID     TIME    DV  EPRED   ERES   NPDE     NPD   PDE    PD  PRED    RES   WRES
#>   <fct> <dbl> <dbl>  <dbl>  <dbl>  <dbl>   <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl>
#> 1 1      0     0.74 0.0967  0.643  1.24   0.903  0.893 0.817  0     0.74   1.06 
#> 2 1      0.25  2.84 3.90   -1.06  -0.440 -0.394  0.33  0.347  3.36 -0.520 -0.276
#> 3 1      0.57  6.57 6.23    0.342 -1.75   0.0837 0.04  0.533  5.96  0.611  0.248
#> # … with 129 more rows, and 16 more variables: IPRED <dbl>, IRES <dbl>,
#> #   IWRES <dbl>, CPRED <dbl>, CRES <dbl>, CWRES <dbl>, eta.ka <dbl>,
#> #   eta.cl <dbl>, eta.v <dbl>, depot <dbl>, center <dbl>, ka <dbl>, cl <dbl>,
#> #   v <dbl>, tad <dbl>, dosenum <dbl>
## Example 3 -- Fix tka to model estimated value and re-estimate.
one.ka.0.5 <- fit %>%
    ini(tka=fix) %>%
    nlmixr(est="focei", control=list(print=0),
           table=list(cwres=TRUE, npde=TRUE))
#> calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> done

print(one.ka.0.5)
#> ── nlmixr FOCEi (outer: nlminb) ──
#> 
#>          OBJF      AIC      BIC Log-likelihood Condition Number
#> FOCEi 116.814 371.4137 388.7106      -179.7069         13.60513
#> 
#> ── Time (sec $time): ──
#> 
#>            setup optimize covariance table compress   other
#> elapsed 0.001873 0.267483   0.267484 1.002     0.01 0.24816
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>        Parameter  Est.     SE  %RSE Back-transformed(95%CI) BSV(CV%)
#> tka       Log Ka 0.474  FIXED FIXED                    1.61     68.9
#> tcl       Log Cl  1.01  0.101  9.93       2.75 (2.26, 3.35)     26.8
#> tv         log V  3.46 0.0457  1.32       31.8 (29.1, 34.8)     13.9
#> add.sd           0.696                                0.696         
#>        Shrink(SD)%
#> tka        0.386% 
#> tcl         3.87% 
#> tv          10.3% 
#> add.sd            
#>  
#>   Covariance Type ($covMethod): r,s
#>   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 
#>   Minimization message ($message):  
#>     false convergence (8) 
#>   In an ODE system, false convergence may mean "useless" evaluations were performed.
#>   See https://tinyurl.com/yyrrwkce
#>   It could also mean the convergence is poor, check results before accepting fit
#>   You may also try a good derivative free optimization:
#>     nlmixr2(...,control=list(outerOpt="bobyqa"))
#> 
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 28
#>   ID     TIME    DV  EPRED   ERES   NPDE     NPD    PDE    PD  PRED    RES
#>   <fct> <dbl> <dbl>  <dbl>  <dbl>  <dbl>   <dbl>  <dbl> <dbl> <dbl>  <dbl>
#> 1 1      0     0.74 0.0967  0.643  1.24   0.903  0.893  0.817  0     0.74 
#> 2 1      0.25  2.84 3.83   -0.986 -0.486 -0.385  0.313  0.35   3.29 -0.449
#> 3 1      0.57  6.57 6.15    0.422 -1.71   0.0920 0.0433 0.537  5.87  0.705
#> # … with 129 more rows, and 17 more variables: WRES <dbl>, IPRED <dbl>,
#> #   IRES <dbl>, IWRES <dbl>, CPRED <dbl>, CRES <dbl>, CWRES <dbl>,
#> #   eta.ka <dbl>, eta.cl <dbl>, eta.v <dbl>, depot <dbl>, center <dbl>,
#> #   ka <dbl>, cl <dbl>, v <dbl>, tad <dbl>, dosenum <dbl>
## Example 4 -- Change tka to 0.7 in orginal model function and then estimate
one.ka.0.7 <- one.compartment %>%
    ini(tka=0.7) %>% 
    nlmixr(theo_sd, est="focei", control=list(print=0),
           table=list(cwres=TRUE, npde=TRUE))
#> calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> done

print(one.ka.0.7)
#> ── nlmixr FOCEi (outer: nlminb) ──
#> 
#>           OBJF      AIC      BIC Log-likelihood Condition Number
#> FOCEi 116.8133 373.4131 393.5927      -179.7065          49.0338
#> 
#> ── Time (sec $time): ──
#> 
#>            setup optimize covariance table compress    other
#> elapsed 0.001739 0.461534   0.461536 0.991    0.014 1.560191
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>        Parameter  Est.     SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka       Log Ka 0.471  0.202 42.8        1.6 (1.08, 2.38)     69.5     0.996% 
#> tcl       Log Cl  1.01 0.0757 7.49       2.75 (2.37, 3.19)     26.4      3.12% 
#> tv         log V  3.46 0.0543 1.57       31.9 (28.6, 35.4)     13.8      9.93% 
#> add.sd           0.697                               0.697                     
#>  
#>   Covariance Type ($covMethod): r,s
#>   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 
#>   Minimization message ($message):  
#>     false convergence (8) 
#>   In an ODE system, false convergence may mean "useless" evaluations were performed.
#>   See https://tinyurl.com/yyrrwkce
#>   It could also mean the convergence is poor, check results before accepting fit
#>   You may also try a good derivative free optimization:
#>     nlmixr2(...,control=list(outerOpt="bobyqa"))
#> 
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 28
#>   ID     TIME    DV  EPRED   ERES   NPDE    NPD   PDE    PD  PRED    RES   WRES
#>   <fct> <dbl> <dbl>  <dbl>  <dbl>  <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl>
#> 1 1      0     0.74 0.0968  0.643  1.24   0.903 0.893 0.817  0     0.74   1.06 
#> 2 1      0.25  2.84 3.82   -0.979 -0.468 -0.376 0.32  0.353  3.28 -0.438 -0.235
#> 3 1      0.57  6.57 6.13    0.437 -1.75   0.100 0.04  0.54   5.85  0.722  0.293
#> # … with 129 more rows, and 16 more variables: IPRED <dbl>, IRES <dbl>,
#> #   IWRES <dbl>, CPRED <dbl>, CRES <dbl>, CWRES <dbl>, eta.ka <dbl>,
#> #   eta.cl <dbl>, eta.v <dbl>, depot <dbl>, center <dbl>, ka <dbl>, cl <dbl>,
#> #   v <dbl>, tad <dbl>, dosenum <dbl>

Changing model features

When developing models, often you add and remove between subject variability to parameters, add covariates to the effects, and/or change the residual errors. You can change lines in the model by piping the fit or the nlmixr model specification function to a model

Adding or Removing between subject variability

Often in developing a model you add and remove between subject variability to certain model parameters. For example, you could remove the between subject variability in the ka parameter by changing that line in the model;

For example to remove a eta from a prior fit or prior model specification function, simply pipe it to the model function. You can then re-estimate by piping it to the nlmixr function again.

## Remove eta.ka on ka
noEta <- fit %>%
    model(ka <- exp(tka)) %>%
    nlmixr(est="focei", control=list(print=0),
           table=list(cwres=TRUE, npde=TRUE))
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> done

print(noEta)
#> ── nlmixr FOCEi (outer: nlminb) ──
#> 
#>           OBJF     AIC      BIC Log-likelihood Condition Number
#> FOCEi 176.5812 431.181 448.4778      -209.5905         34.87439
#> 
#> ── Time (sec $time): ──
#> 
#>           setup optimize covariance table compress    other
#> elapsed 0.00241  0.28821   0.288212 1.682     0.01 3.275168
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>        Parameter  Est.     SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka       Log Ka 0.431   0.17 39.5        1.54 (1.1, 2.15)                     
#> tcl       Log Cl 0.991 0.0745 7.51        2.7 (2.33, 3.12)     30.3      7.76% 
#> tv         log V  3.48 0.0485 1.39       32.4 (29.5, 35.7)     15.6      7.93% 
#> add.sd            1.02                                1.02                     
#>  
#>   Covariance Type ($covMethod): r,s
#>   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 
#>   Minimization message ($message):  
#>     false convergence (8) 
#>   In an ODE system, false convergence may mean "useless" evaluations were performed.
#>   See https://tinyurl.com/yyrrwkce
#>   It could also mean the convergence is poor, check results before accepting fit
#>   You may also try a good derivative free optimization:
#>     nlmixr2(...,control=list(outerOpt="bobyqa"))
#> 
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 27
#>   ID     TIME    DV EPRED   ERES   NPDE    NPD   PDE    PD  PRED    RES   WRES
#>   <fct> <dbl> <dbl> <dbl>  <dbl>  <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl>
#> 1 1      0     0.74 0.142  0.598  0.915  0.643 0.82  0.74   0     0.74   0.726
#> 2 1      0.25  2.84 3.24  -0.397 -0.593 -0.288 0.277 0.387  3.12 -0.277 -0.246
#> 3 1      0.57  6.57 5.70   0.872 -0.449  0.613 0.327 0.73   5.61  0.959  0.723
#> # … with 129 more rows, and 15 more variables: IPRED <dbl>, IRES <dbl>,
#> #   IWRES <dbl>, CPRED <dbl>, CRES <dbl>, CWRES <dbl>, eta.cl <dbl>,
#> #   eta.v <dbl>, depot <dbl>, center <dbl>, ka <dbl>, cl <dbl>, v <dbl>,
#> #   tad <dbl>, dosenum <dbl>

Of course you could also add an eta on a parameter in the same way;

addBackKa <- noEta %>%
    model({ka <- exp(tka + bsv.ka)}) %>%
    ini(bsv.ka=0.1) %>%
    nlmixr(est="focei", control=list(print=0),
           table=list(cwres=TRUE, npde=TRUE))
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> done

print(addBackKa)
#> ── nlmixr FOCEi (outer: nlminb) ──
#> 
#>           OBJF      AIC     BIC Log-likelihood Condition Number
#> FOCEi 116.8217 373.4214 393.601      -179.7107         159.1738
#> 
#> ── Time (sec $time): ──
#> 
#>            setup optimize covariance table compress    other
#> elapsed 0.002396 0.448845   0.448847 1.473     0.01 4.318912
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>        Parameter  Est.     SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
#> tka       Log Ka 0.484  0.196 40.4       1.62 (1.11, 2.38)     69.6     0.891% 
#> tcl       Log Cl  1.01   0.62 61.1       2.76 (0.819, 9.3)     26.8      4.10% 
#> tv         log V  3.46 0.0872 2.52       31.8 (26.8, 37.7)     14.1      10.9% 
#> add.sd           0.694                               0.694                     
#>  
#>   Covariance Type ($covMethod): r,s
#>   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 
#>   Minimization message ($message):  
#>     false convergence (8) 
#>   In an ODE system, false convergence may mean "useless" evaluations were performed.
#>   See https://tinyurl.com/yyrrwkce
#>   It could also mean the convergence is poor, check results before accepting fit
#>   You may also try a good derivative free optimization:
#>     nlmixr2(...,control=list(outerOpt="bobyqa"))
#> 
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 28
#>   ID     TIME    DV  EPRED   ERES   NPDE    NPD   PDE    PD  PRED    RES   WRES
#>   <fct> <dbl> <dbl>  <dbl>  <dbl>  <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl>
#> 1 1      0     0.74 0.0964  0.644  1.50   0.928 0.933 0.823  0     0.74   1.07 
#> 2 1      0.25  2.84 3.67   -0.826 -0.706 -0.297 0.24  0.383  3.32 -0.480 -0.255
#> 3 1      0.57  6.57 5.95    0.621 -1.88   0.314 0.03  0.623  5.91  0.663  0.267
#> # … with 129 more rows, and 16 more variables: IPRED <dbl>, IRES <dbl>,
#> #   IWRES <dbl>, CPRED <dbl>, CRES <dbl>, CWRES <dbl>, eta.cl <dbl>,
#> #   eta.v <dbl>, bsv.ka <dbl>, depot <dbl>, center <dbl>, ka <dbl>, cl <dbl>,
#> #   v <dbl>, tad <dbl>, dosenum <dbl>

You can see the name change by examining the omega matrix:

addBackKa$omega
#>            eta.cl      eta.v    bsv.ka
#> eta.cl 0.06918013 0.00000000 0.0000000
#> eta.v  0.00000000 0.01968171 0.0000000
#> bsv.ka 0.00000000 0.00000000 0.3946166

Note that new between subject variability parameters are distinguished from other types of parameters (ie population parameters, and individual covariates) by their name. Parameters starting or ending with the following names are assumed to be between subject variability parameters:

  • eta (from NONMEM convention)
  • ppv (per patient variability)
  • psv (per subject variability)
  • iiv (inter-individual variability)
  • bsv (between subject variability)
  • bpv (between patient variability)

Adding Covariate effects

## Note currently cov is needed as a prefix so nlmixr knows this is an
## estimated parameter not a parameter
wt70 <- fit %>% 
  model({cl <- exp(tcl + eta.cl)*(WT/70)^covWtPow}) %>%
  ini(covWtPow=fix(0.75)) %>%
  ini(tka=fix(0.5)) %>%
  nlmixr(est="focei", control=list(print=0),
         table=list(cwres=TRUE, npde=TRUE))
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> done

print(wt70)
#> ── nlmixr FOCEi (outer: nlminb) ──
#> 
#>           OBJF      AIC      BIC Log-likelihood Condition Number
#> FOCEi 116.2107 370.8105 388.1073      -179.4053         10.72451
#> 
#> ── Time (sec $time): ──
#> 
#>            setup optimize covariance table compress    other
#> elapsed 0.002335 0.274865   0.274866 1.569    0.011 3.936934
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>          Parameter  Est.     SE  %RSE Back-transformed(95%CI) BSV(CV%)
#> tka         Log Ka   0.5  FIXED FIXED                    1.65     68.9
#> tcl         Log Cl  1.01 0.0761   7.5        2.76 (2.38, 3.2)     26.7
#> tv           log V  3.46 0.0293 0.846         31.7 (30, 33.6)     13.8
#> add.sd             0.696                                0.696         
#> covWtPow            0.75  FIXED FIXED                    0.75         
#>          Shrink(SD)%
#> tka          0.822% 
#> tcl           6.36% 
#> tv            12.1% 
#> add.sd              
#> covWtPow            
#>  
#>   Covariance Type ($covMethod): r,s
#>   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 
#>   Minimization message ($message):  
#>     false convergence (8) 
#>   In an ODE system, false convergence may mean "useless" evaluations were performed.
#>   See https://tinyurl.com/yyrrwkce
#>   It could also mean the convergence is poor, check results before accepting fit
#>   You may also try a good derivative free optimization:
#>     nlmixr2(...,control=list(outerOpt="bobyqa"))
#> 
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 29
#>   ID     TIME    DV  EPRED   ERES   NPDE     NPD   PDE    PD  PRED    RES   WRES
#>   <fct> <dbl> <dbl>  <dbl>  <dbl>  <dbl>   <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl>
#> 1 1      0     0.74 0.0967  0.643  1.23   0.903   0.89 0.817  0     0.74   1.06 
#> 2 1      0.25  2.84 3.90   -1.06  -0.468 -0.394   0.32 0.347  3.36 -0.522 -0.277
#> 3 1      0.57  6.57 6.22    0.351 -1.64   0.0837  0.05 0.533  5.95  0.617  0.251
#> # … with 129 more rows, and 17 more variables: IPRED <dbl>, IRES <dbl>,
#> #   IWRES <dbl>, CPRED <dbl>, CRES <dbl>, CWRES <dbl>, eta.ka <dbl>,
#> #   eta.cl <dbl>, eta.v <dbl>, depot <dbl>, center <dbl>, ka <dbl>, cl <dbl>,
#> #   v <dbl>, tad <dbl>, dosenum <dbl>, WT <dbl>

Changing residual errors

Changing the residual errors is also just as easy, by simply specifying the error you wish to change:

## Since there are 0 predictions in the data, these are changed to
## 0.0150 to show proportional error change.
d <- theo_sd
d$DV[d$EVID == 0 & d$DV == 0] <- 0.0150

addPropModel <- fit %>%
    model({cp ~ add(add.err)+prop(prop.err)}) %>%
    ini(prop.err=0.1) %>%
    nlmixr(d,est="focei",
           control=list(print=0),
           table=list(cwres=TRUE, npde=TRUE))
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> 
#> calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00 
#> done

print(addPropModel)
#> ── nlmixr FOCEi (outer: nlminb) ──
#> 
#>           OBJF      AIC      BIC Log-likelihood Condition Number
#> FOCEi 104.3506 362.9504 386.0128      -173.4752         58.88045
#> 
#> ── Time (sec $time): ──
#> 
#>            setup optimize covariance table compress    other
#> elapsed 0.002321 0.465786   0.465788 1.507    0.011 4.972105
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ──
#> 
#>          Parameter  Est.     SE %RSE Back-transformed(95%CI) BSV(CV%)
#> tka         Log Ka 0.391  0.196 50.2       1.48 (1.01, 2.17)     69.0
#> tcl         Log Cl  1.02  0.074 7.23       2.79 (2.41, 3.22)     25.8
#> tv           log V  3.47 0.0464 1.34         32 (29.2, 35.1)     12.6
#> add.err            0.273                               0.273         
#> prop.err           0.134                               0.134         
#>          Shrink(SD)%
#> tka           2.00% 
#> tcl           1.18% 
#> tv            15.6% 
#> add.err             
#> prop.err            
#>  
#>   Covariance Type ($covMethod): r,s
#>   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 
#>   Minimization message ($message):  
#>     false convergence (8) 
#>   In an ODE system, false convergence may mean "useless" evaluations were performed.
#>   See https://tinyurl.com/yyrrwkce
#>   It could also mean the convergence is poor, check results before accepting fit
#>   You may also try a good derivative free optimization:
#>     nlmixr2(...,control=list(outerOpt="bobyqa"))
#> 
#> ── Fit Data (object is a modified tibble): ──
#> # A tibble: 132 × 28
#>   ID     TIME    DV  EPRED   ERES   NPDE    NPD   PDE    PD  PRED    RES   WRES
#>   <fct> <dbl> <dbl>  <dbl>  <dbl>  <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl>
#> 1 1      0     0.74 0.0380  0.702  2.13   2.22  0.983 0.987  0     0.74   2.71 
#> 2 1      0.25  2.84 3.59   -0.748 -0.915 -0.271 0.18  0.393  3.05 -0.212 -0.126
#> 3 1      0.57  6.57 5.86    0.712 -0.830  0.262 0.203 0.603  5.53  1.04   0.428
#> # … with 129 more rows, and 16 more variables: IPRED <dbl>, IRES <dbl>,
#> #   IWRES <dbl>, CPRED <dbl>, CRES <dbl>, CWRES <dbl>, eta.ka <dbl>,
#> #   eta.cl <dbl>, eta.v <dbl>, depot <dbl>, center <dbl>, ka <dbl>, cl <dbl>,
#> #   v <dbl>, tad <dbl>, dosenum <dbl>