How to access "states" or "compartments" of solved systems #658
-
In the example below I'm using a solved system dosing into the depot compartment. I want to take the output and access the values of the "states" or "compartments" in the solved system. For example I want to access the depot and central compartment. I realize that Cc is the central compartment but I want to access these values based on the names in library(rxode2)
#> Warning: package 'rxode2' was built under R version 4.2.3
#> rxode2 2.1.2 using 1 threads (see ?getRxThreads)
#> no cache: create with `rxCreateCache()`
#> ========================================
#> rxode2 has not detected OpenMP support and will run in single-threaded mode
#> This is a Mac. Please read https://mac.r-project.org/openmp/
#> ========================================
my_model = 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)
etalka ~ 0.1
etalvc ~ 0.1
})
model({
ka <- exp(lka + etalka)
cl <- exp(lcl)*(WT/70)^.75
vc <- exp(lvc + etalvc)*(WT/70)
Cc <- linCmt()
Cc ~ add(CcaddSd)
})
}
# This creates an rxode2 object
object = rxode(my_model)
nsub=5
iCov = data.frame(
id = c(1:5),
WT = c(65, 67, 70, 72, 80))
ot = seq(0, 5, .1)
ev <-rxode2et::et(amt=1, cmt=depot, id=c(1:nsub)) |>
rxode2et::et(time=ot, cmt=Cc) |>
rxode2et::et(time=ot, cmt=Cp)
sim <- rxode2::rxSolve(object, ev, nSub=nsub, iCov = iCov)
head(as.data.frame(sim))
#> id time ka cl vc Cc ipredSim sim WT
#> 1 1 0.0 1.32875 2.571319 41.44283 0.000000000 0.000000000 1.0442213 65
#> 2 1 0.0 1.32875 2.571319 41.44283 0.000000000 0.000000000 1.2972223 65
#> 3 1 0.1 1.32875 2.571319 41.44283 0.002992840 0.002992840 -0.6820884 65
#> 4 1 0.1 1.32875 2.571319 41.44283 0.002992840 0.002992840 1.2843680 65
#> 5 1 0.2 1.32875 2.571319 41.44283 0.005594782 0.005594782 1.2141784 65
#> 6 1 0.2 1.32875 2.571319 41.44283 0.005594782 0.005594782 -0.6169079 65 Created on 2024-02-22 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The compartments are not output, so there is no way to access them programmatically.
You cannot access either You can file a feature request in |
Beta Was this translation helpful? Give feedback.
The compartments are not output, so there is no way to access them programmatically.
Right now I believe you could usecentral
ordepot
in your model to output to some variable, but the peripheral compartment(s) cannot be accessedYou cannot access either
depot
orcentral
directly. As you said you could accesscentral
throughCc*V
though that really is not what you are looking for.You can file a feature request in
rxode2
if you are passionate about adding it, though it would have to also have components inrxode2parse