library(Rsmlx)
library(ggplot2)
theme_set(theme_bw())

Read and plot the data

Let us first read and plot the indomethacin data

indomethacin <- list(
  dataFile = "data/indomethacin.csv",
  headerTypes = c("id", "time", "amount", "observation"),
  administration = "iv")

indomethacin.data <- mlxR::readDatamlx(data=indomethacin)
print(names(indomethacin.data))
## [1] "treatment" "y"         "id"        "N"
ggplot(indomethacin.data$y, aes(x=time, y=y, color=id)) + geom_point(size=1.5) + geom_line(size=1) +
  theme(legend.position = "none") + scale_y_continuous(trans='log10')


Select the structural model

We use pkbuild to select a PK model for this data, using both clearances and rates as parameterization, comparing linear and nonlinear elimination models:

indomethacin.res <- pkbuild(data=indomethacin, param="both", MM=TRUE, new.dir="indomethacin")
## 
## [1] "indomethacin/pk_VCl.mlxtran"
## Estimation of the population parameters...
## Estimation of the log-likelihood... 
## 
## [1] "indomethacin/pk_V1V2QCl.mlxtran"
## Estimation of the population parameters...
## Estimation of the log-likelihood... 
## 
## [1] "indomethacin/pk_V1V2V3Q2Q3Cl.mlxtran"
## Estimation of the population parameters...
## Estimation of the log-likelihood... 
## 
## [1] "indomethacin/pk_V1V2QVmKm.mlxtran"
## Estimation of the population parameters...
## Estimation of the log-likelihood... 
## 
## [1] "indomethacin/pk_Vk.mlxtran"
## Estimation of the population parameters...
## Estimation of the log-likelihood... 
## 
## [1] "indomethacin/pk_Vk12k21k.mlxtran"
## Estimation of the population parameters...
## Estimation of the log-likelihood... 
## 
## [1] "indomethacin/pk_Vk12k21k13k31k.mlxtran"
## Estimation of the population parameters...
## Estimation of the log-likelihood... 
## 
## [1] "indomethacin/pk_Vk12k21VmKm.mlxtran"
## Estimation of the population parameters...
## Estimation of the log-likelihood...

According to (corrected) BIC, the best PK models for this data are the following ones

print(indomethacin.res$bic)
##                              model    bic.cor
## 1        infusion_2cpt_ClV1QV2.txt -135.34967
## 2       infusion_2cpt_Vkk12k21.txt -132.46955
## 3 infusion_3cpt_Vkk12k21k13k31.txt -127.80526
## 4   infusion_3cpt_ClV1Q2V2Q3V3.txt -126.62916
## 5      infusion_2cpt_V1QV2VmKm.txt -122.82267
## 6    infusion_2cpt_Vk12k21VmKm.txt -119.67118
## 7             infusion_1cpt_Vk.txt  -44.47631
## 8            infusion_1cpt_VCl.txt  -44.40552


Using Monolix to fit the data with the selected model

The following Monolix project was created by pkbuild

indomethacin.res$project
## [1] "indomethacin/pk_V1V2QCl.mlxtran"

We can load and run this project with Monolix (either using the MlxConnectors or the Monolix graphical user interface).

Very good initial values for a 2 compartments model are provided by pkbuild

Here are some individual fits obtained with Monolix: