Heller title: “PHAR7381 Final project1” output: html_document — #libraries

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

#unt234<-read.table("/work/ac0837/PHAR7381/week8/UNT235/project/UNT234.res",header = T,skip=1)
unt234<-read.table("C:\\Heller\\PHAR7381\\project\\UNT234.res",skip=1,header=T)
#calculate means 5dose levels by 11 timepoints
unt234sum<-unt234%>%group_by(DOSE,TIME)%>%summarise(cmean=mean(DV))
## `summarise()` has grouped output by 'DOSE'. You can override using the
## `.groups` argument.

#Exploratory data analysis

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

#Onecomp Diagnostic plots

#onecomp<-read.table("/work/ac0837/PHAR7381/week8/UNT235/project/onecomp.res",skip=1,header = T)
onecomp<-read.table("C:\\Heller\\PHAR7381\\project\\onecomp.res",skip=1,header=T)
#observed and individual predictions
ggplot(data=onecomp%>%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=onecomp%>%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=onecomp%>%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=onecomp%>%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
onecomp$DOSE<-factor(onecomp$DOSE,labels = c("5 mg","10 mg","25 mg","50 mg","100 mg"))
##individual plots 5 mg
ggplot(data=onecomp%>%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,24),breaks = c(0,24))+
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=onecomp%>%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,24),breaks = c(0,24))+
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=onecomp%>%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,24),breaks = c(0,24))+
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=onecomp%>%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,24),breaks = c(0,24))+
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=onecomp%>%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,24),breaks = c(0,24))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))

#onecomp<-read.table("/work/ac0837/PHAR7381/week8/UNT235/project/onecomp.res",skip=1,header = T)
onecomp<-read.table("C:\\Heller\\PHAR7381\\project\\onecomp.res",skip=1,header=T)
#observed and individual predictions vs time by AHH


ggplot(data=onecomp%>%filter(TIME>0),aes(TIME,IPRED, group=DOSE))+
  geom_point(shape=19,colour="blue")+
  #geom_abline(intercept =0, slope =1)+
  scale_x_continuous(limits = c(0,24))+
  scale_y_continuous(limits = c(0,500))+
  theme_bw()+
  my_theme()+
labs(x="TIME (hours)",y="Indiv predictions (ng/ml)")

ggplot(data=onecomp%>%filter(TIME>0),aes(TIME,DV,group=DOSE))+
  geom_point(shape=19,colour="red")+
  #geom_abline(intercept =0, slope =1)+
  scale_x_continuous(limits = c(0,24))+
  scale_y_continuous(limits = c(0,500))+
  theme_bw()+
  my_theme()+
labs(x="TIME (hours)",y="observations (ng/ml)")
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).

#Twocomp Diagnostic plots

#twocomp<-read.table("/work/ac0837/PHAR7381/week8/UNT235/project/twocomp.res",skip=1,header = T)
twocomp<-read.table("C:\\Heller\\PHAR7381\\project\\twocomp.res",skip=1,header=T)
#observed and individual predictions
ggplot(data=twocomp%>%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=twocomp%>%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=twocomp%>%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=twocomp%>%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
twocomp$DOSE<-factor(twocomp$DOSE,labels = c("5 mg","10 mg","25 mg","50 mg","100 mg"))
##individual plots 5 mg
ggplot(data=twocomp%>%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,24),breaks = c(0,24))+
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=twocomp%>%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,24),breaks = c(0,24))+
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=twocomp%>%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,24),breaks = c(0,24))+
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=twocomp%>%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,24),breaks = c(0,24))+
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=twocomp%>%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,24),breaks = c(0,24))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(ID))