Heller title: “PHAR7383 Absorption modeling” output: html_document date: 01OCT2025 — # # Conduct exploratory data analysis and interpret PK profiles for their absorption kinetics (eg. Double peaks, #lag times etc.) # Develop a model by fitting following models # First order absorption # Zero order absorption # Mixed order absorption # Sequential first order absorption # Summarize results in a table for their objective function values # Interpret each model diagnostics # Conclude best model

#libraries

library(dplyr)
library(ggplot2)
library(xpose4)
library(tidyr)
library(knitr)

#theme

my_theme<-function(x){theme_bw()+
    theme(text = element_text(size=20))+
    theme(axis.line.y = element_line(size = 2.0))+
    theme(axis.line.x = element_line(size = 2.0))+
    theme(axis.ticks = element_line(size = 1.5,colour="black"))+
    theme(axis.ticks.length=  unit(0.45, "cm"))+
    theme(axis.title.y =element_text(vjust=1.2))+
    theme(axis.title.x =element_text(vjust=-0.2))+
    theme(axis.text=element_text(colour="black"))+
    theme(panel.background = element_rect(fill ="white"))}

#import data (this dataset not yet ready for nonmem runs. I provided modified datasets to implement variious models. Please understand the differences between this dataset and other additions made in the other datasets provided)

pkdt<-read.csv("C:\\Heller\\PHAR7383\\week11\\pkdt.csv",stringsAsFactors = F)

#Exploratory data analysis

#Population Plot
ggplot(data=pkdt,aes(TIME,DV,group=ID))+
geom_line(size=0.5)+
geom_point(size=1)+
scale_x_continuous(limits = c(0,24),breaks = c(0,1,2,4,6,8,12,24))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## i Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## i Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

#Individual Plot Reference
ggplot(data=pkdt,aes(TIME,DV))+
geom_line(size=0.5)+
geom_point(size=1)+
scale_x_continuous(limits = c(0,24),breaks = c(0,1,2,4,6,8,12,24))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

#Diagnostic plots (you need to run the nonmem runs by running mod file before running the code beow. Also, please review and understand each model file code and associated dataset preparation) #First order absorption model

fstabs<-xpose.data(1,dir="C:\\Heller\\PHAR7383\\week11")
## 
## Looking for NONMEM table files.
##     Reading C:\Heller\PHAR7383\week11/sdtab1 
##     Reading C:\Heller\PHAR7383\week11/patab1 
##     Reading C:\Heller\PHAR7383\week11/catab1 
##     Reading C:\Heller\PHAR7383\week11/cotab1 
## Table files read.
## 
## Looking for NONMEM simulation table files.
## No simulated table files read.
dv.vs.ipred(fstabs,type="p")

dv.vs.pred(fstabs,type="p")

cwres.vs.idv(fstabs,type="p")

cwres.vs.pred(fstabs,type="p")

ind.plots(fstabs)

ranpar.hist(fstabs)

#Zero order absorption model

zeroabs<-xpose.data(2,dir="C:\\Heller\\PHAR7383\\week11")
## 
## Looking for NONMEM table files.
##     Reading C:\Heller\PHAR7383\week11/sdtab2 
##     Reading C:\Heller\PHAR7383\week11/patab2 
##     Reading C:\Heller\PHAR7383\week11/catab2 
##     Reading C:\Heller\PHAR7383\week11/cotab2 
## Table files read.
## 
## Looking for NONMEM simulation table files.
## No simulated table files read.
dv.vs.ipred(zeroabs,type="p")

dv.vs.pred(zeroabs,type="p")

cwres.vs.idv(zeroabs,type="p")

cwres.vs.pred(zeroabs,type="p")

ind.plots(zeroabs)

ranpar.hist(zeroabs)

# Mixed order absorption model

mixedabs<-xpose.data(3,dir="C:\\Heller\\PHAR7383\\week11")
## 
## Looking for NONMEM table files.
##     Reading C:\Heller\PHAR7383\week11/sdtab3 
##     Reading C:\Heller\PHAR7383\week11/patab3 
##     Reading C:\Heller\PHAR7383\week11/catab3 
##     Reading C:\Heller\PHAR7383\week11/cotab3 
## Table files read.
## 
## Looking for NONMEM simulation table files.
## No simulated table files read.
dv.vs.ipred(mixedabs,type="p")

dv.vs.pred(mixedabs,type="p")

cwres.vs.idv(mixedabs,type="p")

cwres.vs.pred(mixedabs,type="p")

ind.plots(mixedabs)

ranpar.hist(mixedabs)

# Sequential first order absorption model (two different rate constants, second one starts a bit later after lag time ALAG2)

seqfst<-xpose.data(4,dir="C:\\Heller\\PHAR7383\\week11")
## 
## Looking for NONMEM table files.
##     Reading C:\Heller\PHAR7383\week11/sdtab4 
##     Reading C:\Heller\PHAR7383\week11/patab4 
##     Reading C:\Heller\PHAR7383\week11/catab4 
##     Reading C:\Heller\PHAR7383\week11/cotab4 
## Table files read.
## 
## Looking for NONMEM simulation table files.
## No simulated table files read.
dv.vs.ipred(seqfst,type="p")

dv.vs.pred(seqfst,type="p")

cwres.vs.idv(seqfst,type="p")

cwres.vs.pred(seqfst,type="p")

ind.plots(seqfst)

ranpar.hist(seqfst)