Skip to contents

Add random effects to a model

Usage

addEta(
  ui,
  eta,
  priorName = getOption("rxode2.priorEta", getOption("nlmixr2lib.priorEta", TRUE)),
  etaCombineType = c("default", "snake", "camel", "dot", "blank"),
  model
)

Arguments

ui

The model as a function

eta

vector with the parameters to add random effects (sometimes referred to as inter-individual variability, IIV) on

priorName

logical, if TRUE, the parameter name specified in eta will be used to add the eta value prior name is used instead of the left handed side of the equation. Defaults to options(rxode2.priorEta=) (or the legacy nlmixr2lib.priorEta).

etaCombineType

the option for the how to combine the eta with the parameter name. Can be: "default", "snake", "camel", "dot", "blank". When missing it is taken from options(rxode2.etaCombineType=) (or the legacy nlmixr2lib.etaCombineType).

model

Deprecated alias for ui. Supplying model instead of ui still works but emits a deprecation warning.

Value

The model with eta added to the requested parameters

Author

Bill Denney, Richard Hooijmaijers & Matthew L. Fidler

Examples

pk1cmt <- function() {
  ini({
    lka <- 0.45; label("Absorption rate (Ka)")
    lcl <- 1; label("Clearance (CL)")
    lvc <- 3.45; label("Central volume of distribution (V)")
    propSd <- 0.5; label("Proportional residual error (fraction)")
  })
  model({
    ka <- exp(lka)
    cl <- exp(lcl)
    vc <- exp(lvc)
    Cc <- linCmt()
    Cc ~ prop(propSd)
  })
}

library(rxode2)
pk1cmt |> addEta("ka")
#>  
#>  
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#> → Adding eta to lka instead of ka due to mu-referencing
#>  
#>  
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#>  
#>  
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#> ℹ promote `etaKa` to between subject variability with initial estimate 0.1
#> ℹ change initial estimate of `etaKa` to `0.1`
#> function () 
#> {
#>     ini({
#>         lka <- 0.45
#>         label("Absorption rate (Ka)")
#>         lcl <- 1
#>         label("Clearance (CL)")
#>         lvc <- 3.45
#>         label("Central volume of distribution (V)")
#>         propSd <- c(0, 0.5)
#>         label("Proportional residual error (fraction)")
#>         etaKa ~ 0.1
#>     })
#>     model({
#>         ka <- exp(lka + etaKa)
#>         cl <- exp(lcl)
#>         vc <- exp(lvc)
#>         Cc <- linCmt()
#>         Cc ~ prop(propSd)
#>     })
#> }
#> <environment: 0x61cbbfba1068>