Calvagone / campsis

A generic PK/PD simulation platform based on rxode2 and mrgsolve engines.
https://calvagone.github.io/
GNU General Public License v3.0
8 stars 3 forks source link

wrapper function for quick parallel design datasets #38

Closed AndreasCalvagone closed 3 years ago

AndreasCalvagone commented 3 years ago

Would be nice to have a wraper function to quickly generate parallel design datasets with different arms based on the amount input; something like: createDatasetparallel(subjects=100, amt=c(100,200,400,600), interval=24, model=model, obs=seq(0,100,1))

this would create a dataset with 4 arms and 100 subjects each; may also be an option to provide the dosing schedule as a list if the interval varies: amt=list(c(100,24),c(200,12),c(200,24),c(600,48))

luyckxn commented 3 years ago

I'm hesitant to implement such a wrapper function. For me, this function will never suit everyone needs. In particular, it will not be usable if you have, in your dataset :

luyckxn commented 3 years ago

Can you have a look at the 3 below alternatives, which I find more flexible:


model <- model_library$advan4_trans4

# Solution 1 (create arm method)
createArm <- function(amt) {
  arm <- Arm(subjects=100)
  arm <- arm %>% add(Observations(seq(0,7*24)))
  arm <- arm %>% add(Bolus((0:6)*24, amount=amt))
  return(arm)
}
arms <- c(100, 200, 300, 400) %>% purrr::map(~ createArm(.x))
dataset <- Dataset() %>% add(arms)

# Solution 2 (create complete dataset & adapt using dose adaptation, available in next release)
arm <- Arm(subjects=100)
arm <- arm %>% add(Observations(seq(0,7*24)))
arm <- arm %>% add(Bolus((0:6)*24, amount=100))

arms <- c(1, 2, 3, 4) %>% purrr::map(~ arm %>% add(DoseAdaptation(paste0("AMT*", .x))))
dataset <- Dataset() %>% add(arms)

# Solution 3 (create almost complete dataset & add arm-specific boluses)
arm <- Arm(subjects=100)
arm <- arm %>% add(Observations(seq(0,7*24)))

arms <- c(100, 200, 300, 400) %>% purrr::map(~ arm %>% add(Bolus((0:6)*24, amount=.x)))
dataset <- Dataset() %>% add(arms)

# All these 3 datasets give the same results
results <- model %>% simulate(dataset=dataset)
shadedPlot(results, "CP", "ARM")
luyckxn commented 3 years ago

By the way, in the next release, replace & delete methods can be used to adapt an existing dataset or arm. For instance, to replace the amount of the first bolus, you'll write: arm %>% replace(Bolus(0, amount= X)) This will be nice I think for writing scenarios. However, there is no 1-line code to replace the amount of all boluses in your arm (other than using the new dose adaptation element).

AndreasCalvagone commented 3 years ago

I see the point of avoiding to have a too complex function. However, I'm not sure if the current approach is very user-friendly; this is certainly something that the normal user will have too look-up every time he/she is doing a simulation since it is not intuitive. Of course, we can have an example in the vignette or a cheat-sheet; but I think the way they handle the dosing instructions in mrgsolve for example is quite elegant: https://mrgsolve.github.io/vignettes/events.html#31_Combine_to_create_a_data_set

Maybe we can do something similar: creating different arm objects and then combine then with a function.

luyckxn commented 3 years ago

I see. What about a quick arm constructor like QuickArm(amount=250, ii=24, addl=4, time=24, label=X) ?

luyckxn commented 3 years ago

It would return an arm object that you can still work on if needed (to add covariates, etc.)

luyckxn commented 3 years ago

After discussion, we decided to not implement any wrapper, but to add optional 'ii' and 'addl' arguments to constructors Bolus() and Infusion().

To quickly simulate 4 treatments arms without using the purrr package, you can do as follows:

model <- model_library$advan4_trans4

arm_tmp <- Arm(subjects=100) %>% add(Observations(seq(0,7*24)))

arm1 <- arm_tmp %>% add(Bolus(time=0, amount=100, ii=24, addl=6))
arm2 <- arm_tmp %>% add(Bolus(time=0, amount=200, ii=24, addl=6))
arm3 <- arm_tmp %>% add(Bolus(time=0, amount=300, ii=24, addl=6))
arm4 <- arm_tmp %>% add(Bolus(time=0, amount=400, ii=24, addl=6))

dataset <- Dataset() %>% add(c(arm1, arm2, arm3, arm4))

# Plot
results <- model %>% simulate(dataset=dataset)
shadedPlot(results, "CP", "ARM")