Heller title: “PHAR7381 week8” output: html_document Oct 12 2024 #libraries

rm(list=ls())
library(dplyr)
library(ggplot2)

#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

pkdt<-read.csv("C:\\Heller\\PHAR7381\\week8\\pknmdt.csv",stringsAsFactors = F)
pkdtsum<-pkdt%>%group_by(DOSE,TIME)%>%summarise(cmean=mean(DV))
## `summarise()` has grouped output by 'DOSE'. You can override using the
## `.groups` argument.

#Exploratory data analysis

pkdtsum$DOSE<-factor(pkdtsum$DOSE,labels = c("5 mg","10 mg","25 mg","50 mg","100 mg"))
##linear plot mean versus dose
ggplot(data=pkdtsum,aes(TIME,cmean,color=DOSE))+
geom_line(size=0.5)+
geom_point(size=2)+
scale_x_continuous(limits = c(0,72),breaks = c(0,2,4,8,12,24,48,72))+
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 plots
pkdt$DOSE<-factor(pkdt$DOSE,labels = c("5 mg","10 mg","25 mg","50 mg","100 mg"))
##individual plots 5 mg
ggplot(data=pkdt%>%filter(DOSE=="5 mg"),aes(TIME,DV))+
geom_line(size=0.5)+
geom_point(size=1)+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 10 mg
ggplot(data=pkdt%>%filter(DOSE=="10 mg"),aes(TIME,DV))+
geom_line(size=0.5)+
geom_point(size=1)+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 25 mg
ggplot(data=pkdt%>%filter(DOSE=="25 mg"),aes(TIME,DV))+
geom_line(size=0.5)+
geom_point(size=1)+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 50 mg
ggplot(data=pkdt%>%filter(DOSE=="50 mg"),aes(TIME,DV))+
geom_line(size=0.5)+
geom_point(size=1)+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 100 mg
ggplot(data=pkdt%>%filter(DOSE=="100 mg"),aes(TIME,DV))+
geom_line(size=0.5)+
geom_point(size=1)+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

#Run1 Diagnostic plots

run1<-read.table("C:\\Heller\\PHAR7381\\week8\\RUN1.res",skip=1,header = T)
#observed and individual predictions
ggplot(data=run1%>%filter(TIME>0),aes(DV,IPRED))+
  geom_point(shape=19,colour="blue")+
  geom_abline(intercept =0, slope =1)+
  scale_x_continuous(limits = c(0,500))+
  scale_y_continuous(limits = c(0,500))+
  theme_bw()+
  my_theme()+
labs(x="Observations (ng/ml)",y="Individual Predictions (ng/ml)")

#observed and population predictions
ggplot(data=run1%>%filter(TIME>0),aes(DV,PRED))+
  geom_point(shape=19,colour="blue")+
  geom_abline(intercept =0, slope =1)+
  scale_x_continuous(limits = c(0,500))+
  scale_y_continuous(limits = c(0,500))+
  theme_bw()+
  my_theme()+
labs(x="Observations (ng/ml)",y="Population Predictions (ng/ml)")

#TIME versus CRES plot
ggplot(data=run1%>%filter(TIME>0),aes(TIME,CWRES))+
  geom_point(shape=19) +
  geom_hline(yintercept = 0, colour="black") +
  geom_hline(yintercept = c(-6,6),linetype = 2)+
  theme_bw()+
  my_theme()+
  labs(x="Time (hour)",y="Conditional Weighted residuals (CWRES)")

#Predictions versus CWRES plot
ggplot(data=run1%>%filter(TIME>0),aes(PRED,CWRES))+
  geom_point(shape=19) +
  geom_hline(yintercept = 0, colour="black") +
  geom_hline(yintercept = c(-6,6),linetype = 2)+
  theme_bw()+
  my_theme()+
  labs(x=" Population Predictions (ug/L)",y="Weighted residuals (CWRES)")

#Individual plots
run1$DOSE<-factor(run1$DOSE,labels = c("5 mg","10 mg","25 mg","50 mg","100 mg"))
##individual plots 5 mg
ggplot(data=run1%>%filter(DOSE=="5 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 10 mg
ggplot(data=run1%>%filter(DOSE=="10 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 25 mg
ggplot(data=run1%>%filter(DOSE=="25 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 50 mg
ggplot(data=run1%>%filter(DOSE=="50 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 100 mg
ggplot(data=run1%>%filter(DOSE=="100 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

#Run2 Diagnostic plots

run2<-read.table("C:\\Heller\\PHAR7381\\week8\\RUN2.res",skip=1,header = T)
#observed and individual predictions
ggplot(data=run2%>%filter(TIME>0),aes(DV,IPRED))+
  geom_point(shape=19,colour="blue")+
  geom_abline(intercept =0, slope =1)+
  scale_x_continuous(limits = c(0,500))+
  scale_y_continuous(limits = c(0,500))+
  theme_bw()+
  my_theme()+
labs(x="Observations (ng/ml)",y="Individual Predictions (ng/ml)")

#observed and population predictions
ggplot(data=run2%>%filter(TIME>0),aes(DV,PRED))+
  geom_point(shape=19,colour="blue")+
  geom_abline(intercept =0, slope =1)+
  scale_x_continuous(limits = c(0,500))+
  scale_y_continuous(limits = c(0,500))+
  theme_bw()+
  my_theme()+
labs(x="Observations (ng/ml)",y="Population Predictions (ng/ml)")

#TIME versus CRES plot
ggplot(data=run2%>%filter(TIME>0),aes(TIME,CWRES))+
  geom_point(shape=19) +
  geom_hline(yintercept = 0, colour="black") +
  geom_hline(yintercept = c(-6,6),linetype = 2)+
  theme_bw()+
  my_theme()+
  labs(x="Time (hour)",y="Conditional Weighted residuals (CWRES)")

#Predictions versus CWRES plot
ggplot(data=run2%>%filter(TIME>0),aes(PRED,CWRES))+
  geom_point(shape=19) +
  geom_hline(yintercept = 0, colour="black") +
  geom_hline(yintercept = c(-6,6),linetype = 2)+
  theme_bw()+
  my_theme()+
  labs(x=" Population Predictions (ug/L)",y="Weighted residuals (CWRES)")

#Individual plots
run2$DOSE<-factor(run2$DOSE,labels = c("5 mg","10 mg","25 mg","50 mg","100 mg"))
##individual plots 5 mg
ggplot(data=run2%>%filter(DOSE=="5 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 10 mg
ggplot(data=run2%>%filter(DOSE=="10 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 25 mg
ggplot(data=run2%>%filter(DOSE=="25 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 50 mg
ggplot(data=run2%>%filter(DOSE=="50 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 100 mg
ggplot(data=run2%>%filter(DOSE=="100 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

#Run3 Diagnostic plots

run3<-read.table("C:\\Heller\\PHAR7381\\week8\\RUN3.res",skip=1,header = T)
#observed and individual predictions
ggplot(data=run3%>%filter(TIME>0),aes(DV,IPRED))+
  geom_point(shape=19,colour="blue")+
  geom_abline(intercept =0, slope =1)+
  scale_x_continuous(limits = c(0,500))+
  scale_y_continuous(limits = c(0,500))+
  theme_bw()+
  my_theme()+
labs(x="Observations (ng/ml)",y="Individual Predictions (ng/ml)")

#observed and population predictions
ggplot(data=run3%>%filter(TIME>0),aes(DV,PRED))+
  geom_point(shape=19,colour="blue")+
  geom_abline(intercept =0, slope =1)+
  scale_x_continuous(limits = c(0,500))+
  scale_y_continuous(limits = c(0,500))+
  theme_bw()+
  my_theme()+
labs(x="Observations (ng/ml)",y="Population Predictions (ng/ml)")

#TIME versus CRES plot
ggplot(data=run3%>%filter(TIME>0),aes(TIME,CWRES))+
  geom_point(shape=19) +
  geom_hline(yintercept = 0, colour="black") +
  geom_hline(yintercept = c(-6,6),linetype = 2)+
  theme_bw()+
  my_theme()+
  labs(x="Time (hour)",y="Conditional Weighted residuals (CWRES)")

#Predictions versus CWRES plot
ggplot(data=run3%>%filter(TIME>0),aes(PRED,CWRES))+
  geom_point(shape=19) +
  geom_hline(yintercept = 0, colour="black") +
  geom_hline(yintercept = c(-6,6),linetype = 2)+
  theme_bw()+
  my_theme()+
  labs(x=" Population Predictions (ug/L)",y="Weighted residuals (CWRES)")

#Individual plots
run3$DOSE<-factor(run3$DOSE,labels = c("5 mg","10 mg","25 mg","50 mg","100 mg"))
##individual plots 5 mg
ggplot(data=run3%>%filter(DOSE=="5 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 10 mg
ggplot(data=run3%>%filter(DOSE=="10 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 25 mg
ggplot(data=run3%>%filter(DOSE=="25 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 50 mg
ggplot(data=run3%>%filter(DOSE=="50 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

##individual plots 100 mg
ggplot(data=run3%>%filter(DOSE=="100 mg"),aes(TIME,DV))+
geom_point(size=1)+
geom_line(aes(TIME,IPRED),size=0.5,linetype = "dashed")+
scale_x_continuous(limits = c(0,72),breaks = c(0,24,48,72))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))