nlmixr2 / rxode2

rxode2
https://nlmixr2.github.io/rxode2/
GNU General Public License v3.0
30 stars 7 forks source link

`rxode2` pipe out non-diagonal elements #781

Closed mattfidler closed 2 months ago

mattfidler commented 2 months ago

something like:

%>% ini(diag(a,b)) or %>% ini(diag(a+b))

billdenney commented 2 months ago

Is that to remove correlation between a and b without changing the estimates?

mattfidler commented 2 months ago

Is that to remove correlation between a and b without changing the estimates?

diag(a, b) will remove all correlations that include a or b. If needed it will re-order the matrix.

For example:

library(rxode2)
#> rxode2 3.0.0 using 8 threads (see ?getRxThreads)
#>   no cache: create with `rxCreateCache()`
mod2 <- function() {
ini({
    lka ~ 0.45
    lcl ~ c(0.01, 1)
    lvc ~ c(-0.01, 0.01, 3.45)
    lfun ~ c(-0.1, 0.1, 0.01, 4)
    })
model({
      ka <- exp(lka)
      cl <- exp(lcl)
      vc  <- exp(lvc)
      kel <- cl / vc
      d/dt(depot) <- -ka*depot
      d/dt(central) <- ka*depot-kel*central
      cp <- central / vc + lfun
      })
}

# Will reorder
  mod2 %>% ini(diag(lcl, lvc))
#> ℹ remove covariance `(lka,lcl)`
#> ℹ remove covariance `(lcl,lvc)`
#> ℹ remove covariance `(lcl,lfun)`
#> ℹ remove covariance `(lka,lvc)`
#> ℹ remove covariance `(lvc,lfun)`
#>  ── rxode2-based free-form 2-cmt ODE model ────────────────────────────────────── 
#>  ── Initalization: ──  
#> 
#> Omega ($omega): 
#>      lfun   lka  lvc lcl
#> lfun  4.0 -0.10 0.00   0
#> lka  -0.1  0.45 0.00   0
#> lvc   0.0  0.00 3.45   0
#> lcl   0.0  0.00 0.00   1
#> 
#> States ($state or $stateDf): 
#>   Compartment Number Compartment Name
#> 1                  1            depot
#> 2                  2          central
#>  ── Model (Normalized Syntax): ── 
#> function() {
#>     ini({
#>         lfun ~ 4
#>         lka ~ c(-0.1, 0.45)
#>         lvc ~ 3.45
#>         lcl ~ 1
#>     })
#>     model({
#>         ka <- exp(lka)
#>         cl <- exp(lcl)
#>         vc <- exp(lvc)
#>         kel <- cl/vc
#>         d/dt(depot) <- -ka * depot
#>         d/dt(central) <- ka * depot - kel * central
#>         cp <- central/vc + lfun
#>     })
#> }

Created on 2024-09-07 with reprex v2.1.1

mattfidler commented 2 months ago

You can also see the new lower triangular form here....