nlmixr

Adding Covariances between random effects

You can simply add co-variances between two random effects by adding the effects together in the model specification block, that is eta.cl+eta.v ~. After that statement, you specify the lower triangular matrix of the fit with c().

An example of this is the phenobarbitol data:

## Load phenobarbitol data
library(nlmixr)

Model Specification


pheno <- function() {
  ini({
    tcl <- log(0.008) # typical value of clearance
    tv <-  log(0.6)   # typical value of volume
    ## var(eta.cl)
    eta.cl + eta.v ~ c(1, 
                       0.01, 1) ## cov(eta.cl, eta.v), var(eta.v)
                      # interindividual variability on clearance and volume
    add.err <- 0.1    # residual variability
  })
  model({
    cl <- exp(tcl + eta.cl) # individual value of clearance
    v <- exp(tv + eta.v)    # individual value of volume
    ke <- cl / v            # elimination rate constant
    d/dt(A1) = - ke * A1    # model differential equation
    cp = A1 / v             # concentration in plasma
    cp ~ add(add.err)       # define error model
  })
}

Fit with SAEM

fit <- nlmixr(pheno, pheno_sd, "saem",
              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

print(fit)
#> ── nlmixr SAEM(ODE); OBJF by FOCEi approximation fit ───────────────────────────
#> 
#>           OBJF      AIC      BIC Log-likelihood Condition Number
#> FOCEi 688.9716 985.8425 1004.103      -486.9213         6.319407
#> 
#> ── Time (sec $time): ───────────────────────────────────────────────────────────
#> 
#>           saem    setup table cwres covariance    other
#> elapsed 13.287 3.927566 1.278 5.242      0.027 0.961434
#> 
#> ── Population Parameters ($parFixed or $parFixedDf): ───────────────────────────
#> 
#>                          Parameter  Est.     SE %RSE    Back-transformed(95%CI)
#> tcl     typical value of clearance -4.99 0.0729 1.46 0.00681 (0.00591, 0.00786)
#> tv         typical value of volume 0.341  0.055 16.1          1.41 (1.26, 1.57)
#> add.err       residual variability  2.79                                   2.79
#>         BSV(CV%) Shrink(SD)%
#> tcl         50.5      2.64% 
#> tv          42.0      1.42% 
#> add.err                     
#>  
#>   Covariance Type ($covMethod): linFim
#>   Fixed parameter correlations in $cor
#>   Correlations in between subject variability (BSV) matrix:
#>     cor:eta.v,eta.cl 
#>           0.959  
#>  
#> 
#>   Full BSV covariance ($omega) or correlation ($omegaR; diagonals=SDs) 
#>   Distribution stats (mean/skewness/kurtosis/p-value) available in $shrink 
#> 
#> ── Fit Data (object is a modified tibble): ─────────────────────────────────────
#> # A tibble: 155 x 24
#>   ID     TIME    DV EPRED  ERES   NPDE    NPD  PRED    RES    WRES IPRED  IRES
#>   <fct> <dbl> <dbl> <dbl> <dbl>  <dbl>  <dbl> <dbl>  <dbl>   <dbl> <dbl> <dbl>
#> 1 1        2   17.3  18.4 -1.12 -0.449 -0.449  17.6 -0.302 -0.0395  18.7 -1.35
#> 2 1      112.  31    28.9  2.11  0.350  0.350  27.9  3.08   0.253   30.0  1.01
#> 3 2        2    9.7  11.3 -1.55 -0.706 -0.706  10.6 -0.861 -0.169   12.5 -2.78
#> # … with 152 more rows, and 12 more variables: IWRES <dbl>, CPRED <dbl>,
#> #   CRES <dbl>, CWRES <dbl>, eta.cl <dbl>, eta.v <dbl>, A1 <dbl>, cl <dbl>,
#> #   v <dbl>, ke <dbl>, tad <dbl>, dosenum <dbl>

Basic Goodness of Fit Plots

plot(fit)

Those individual plots are not that great, it would be better to see the actual curves; You can with augPred

Two types of VPCs

library(ggplot2)
p1 <- nlmixr::vpc(fit, show=list(obs_dv=TRUE));
p1 <- p1+ ylab("Concentrations")

## A prediction-corrected VPC
p2 <- nlmixr::vpc(fit, pred_corr = TRUE, show=list(obs_dv=TRUE))
p2 <- p2+ ylab("Prediction-Corrected Concentrations")

library(patchwork)
p1 / p2