Play with compartment properties"

EXPORT_PNG <- FALSE

Prerequisite

For this vignette, please load the campsismod package and load the minimalist model that we have created in the first vignette.

library(campsismod)
model <- read.campsis("resources/minimalist_model/")

Create new compartment properties

Let's invent a very basic scenario: we would like to infuse 1000 into the central compartment with a fixed rate of 100 and a fixed lag time of 2.
First, we're going to delete the initial condition that we had in the minimalist model. This is done as follows:

model_ <- model %>% delete(InitialCondition(compartment=1))
model_

This is strictly equal as doing (if you prefer working with compartment names):

model <- model %>% delete(InitialCondition(compartment= model %>% getCompartmentIndex("CENTRAL")))

We can now add a fixed rate for all infusions that go into the central compartment:

model <- model %>% add(InfusionRate(compartment=1, "100"))

Finally, let's now add a constant lag time:

model <- model %>% add(LagTime(compartment=1, "2"))

OK, this is how our model looks like now:

model

Simulate our model

Let's now simulate a few individuals and show A_CENTRAL, i.e., the amount of drug in the central compartment.

First, we need to define an infusion of 1000 in a CAMPSIS dataset, as well as the observations times.

library(campsis)
dataset <- Dataset(5) %>% 
  add(Infusion(time=0, amount=1000)) %>%
  add(Observations(seq(0,36,by=0.5)))

Then, we can run the simulation.

results <- model %>% simulate(dataset=dataset, seed=1)
spaghettiPlot(results, "A_CENTRAL")
ggplot2::ggsave(filename="resources/minimalist_example_cmt_properties.png", width=7, height=3, dpi=100)

A couple of useful functions in action

As previously, let's demonstrate the use of a couple of interesting functions:

Check the existence of a compartment:

model %>% contains(Compartment(1)) 
# Or equivalenty:
model %>% contains(Compartment(model %>% getCompartmentIndex("CENTRAL")))

Check the existence of a property:

model %>% contains(InfusionRate(1))
model %>% contains(InfusionDuration(1)) 

Find a compartment:

model %>% find(Compartment(1)) 

Find a compartment property:

model %>% find(InfusionRate(1)) 

Replace a compartment property:

model %>% replace(InfusionRate(1, "200")) # Previous value of 100 is overridden

Interestingly, the name of a compartment can be replaced as follows:

model %>% replace(Compartment(1, name="CENT")) %>%
  delete(Ode("A_CENTRAL")) %>%
  add(Ode("A_CENT", "-K*A_CENT"))


Try the campsismod package in your browser

Any scripts or data that you put into this service are public.

campsismod documentation built on Oct. 12, 2023, 5:13 p.m.