Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rxode2 pipe out non-diagonal elements #781

Merged
merged 11 commits into from
Sep 8, 2024
Merged

rxode2 pipe out non-diagonal elements #781

merged 11 commits into from
Sep 8, 2024

Conversation

mattfidler
Copy link
Member

something like:

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

@billdenney
Copy link
Contributor

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

@mattfidler
Copy link
Member Author

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
Copy link
Member Author

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

@mattfidler mattfidler merged commit 37e7b47 into main Sep 8, 2024
5 of 7 checks passed
@mattfidler mattfidler deleted the 781-rm-diag branch September 8, 2024 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants