Skip to contents

Add residual error to a model

Usage

addResErr(model, reserr)

Arguments

model

The model as a function

reserr

The type or types of residual error (currently "addSd", "propSd", and "lnormSd" are accepted)

Value

The model with residual error modified

Details

For reserr, the parameter will be named with the dependent variable from the model as a prefix. For example, if the dependent variable in the model is cp, the parameter name for propSd will become cppropSd.

Examples

library(rxode2)
readModelDb("PK_1cmt") |> addResErr("addSd")
#>  
#>  
#> ! remove population parameter `propSd`
#>  add residual parameter `CcaddSd` and set estimate to 1
#>  change initial estimate of `CcaddSd` to `1`
#> function () 
#> {
#>     description <- "One compartment PK model with linear clearance"
#>     ini({
#>         lka <- 0.45
#>         label("Absorption rate (Ka)")
#>         lcl <- 1
#>         label("Clearance (CL)")
#>         lvc <- 3.45
#>         label("Central volume of distribution (V)")
#>         CcaddSd <- c(0, 1)
#>     })
#>     model({
#>         ka <- exp(lka)
#>         cl <- exp(lcl)
#>         vc <- exp(lvc)
#>         Cc <- linCmt()
#>         Cc ~ add(CcaddSd)
#>     })
#> }
#> <environment: 0x5604de798318>
readModelDb("PK_1cmt") |> addResErr("lnormSd")
#>  
#>  
#> ! remove population parameter `propSd`
#>  add residual parameter `CclnormSd` and set estimate to 1
#>  change initial estimate of `CclnormSd` to `0.5`
#> function () 
#> {
#>     description <- "One compartment PK model with linear clearance"
#>     ini({
#>         lka <- 0.45
#>         label("Absorption rate (Ka)")
#>         lcl <- 1
#>         label("Clearance (CL)")
#>         lvc <- 3.45
#>         label("Central volume of distribution (V)")
#>         CclnormSd <- c(0, 0.5)
#>     })
#>     model({
#>         ka <- exp(lka)
#>         cl <- exp(lcl)
#>         vc <- exp(lvc)
#>         Cc <- linCmt()
#>         Cc ~ lnorm(CclnormSd)
#>     })
#> }
#> <environment: 0x5604e0a6c9a8>
readModelDb("PK_1cmt") |> addResErr(c("addSd", "propSd"))
#>  
#>  
#> ! remove population parameter `propSd`
#>  add residual parameter `CcaddSd` and set estimate to 1
#>  add residual parameter `CcpropSd` and set estimate to 1
#>  change initial estimate of `CcaddSd` to `1`
#>  change initial estimate of `CcpropSd` to `0.5`
#> function () 
#> {
#>     description <- "One compartment PK model with linear clearance"
#>     ini({
#>         lka <- 0.45
#>         label("Absorption rate (Ka)")
#>         lcl <- 1
#>         label("Clearance (CL)")
#>         lvc <- 3.45
#>         label("Central volume of distribution (V)")
#>         CcaddSd <- c(0, 1)
#>         CcpropSd <- c(0, 0.5)
#>     })
#>     model({
#>         ka <- exp(lka)
#>         cl <- exp(lcl)
#>         vc <- exp(lvc)
#>         Cc <- linCmt()
#>         Cc ~ add(CcaddSd) + prop(CcpropSd)
#>     })
#> }
#> <environment: 0x5604de41fb48>