Overview

This document contains exploratory plots for count PD data as well as the R code that generates these graphs. The plots presented here are based on simulated data (see: PKPD Datasets). Data specifications can be accessed on Datasets and Rmarkdown template to generate this page can be found on Rmarkdown-Template. You may also download the Multiple Ascending Dose PK/PD dataset for your reference (download dataset).

Setup

# remove reference to home directory in libPaths
.libPaths(grep("home", .libPaths(), value=TRUE, invert=TRUE))

# add localLib to libPaths for locally installed packages
.libPaths(c("localLib", .libPaths()))

# will load from first filepath first, then look in .libPaths for more packages not in first path
# version matches package in first filepath, in the case of multiple instances of a package

# library(rmarkdown)
library(gridExtra)
library(grid)
library(ggplot2)
library(dplyr)
library(RxODE)
library(caTools)

#flag for labeling figures as draft
  draft.flag      = TRUE

## ggplot settings
theme_set(theme_bw(base_size=12))

Define Useful Graphics Functions

# annotation of plots with status of code
AnnotateStatus <- function(draft.flag, log.y=FALSE, log.x=FALSE, fontsize=7, color="grey") {
  
  x.pos <- -Inf
  if (log.x)
    x.pos <- 0
  
  y.pos <- -Inf
  if (log.y)
    y.pos <- 0
  
  if(draft.flag) {
    annotateStatus <- annotate("text",
                               label="DRAFT",
                               x=x.pos, y=y.pos,
                               hjust=-0.1, vjust=-1.0,
                               cex=fontsize,
                               col=color, alpha=0.7, fontface="bold")
  } else {
    annotateStatus <- NULL
  }
  
  return(annotateStatus)
}

Load Dataset

my.data <- read.csv("../Data/Multiple_Ascending_Dose_Dataset2.csv")

# Define order for factors
my.data$TRTACT <- factor(my.data$TRTACT, levels = unique(my.data$TRTACT[order(my.data$DOSE)]))

Provide an overview of the data

Summarize the data in a way that is easy to visualize the general trend of PD over time and between doses. Using summary statistics can be helpful, e.g. Mean +/- SE, or median, 5th & 95th percentiles. Consider either coloring by dose or faceting by dose. Depending on the amount of data one graph may be better than the other.

PK and PD marker over time, colored by Dose, median, 5th, 95th percentiles by nominal time

Does the effect appear to increase and decrease quickly on a short time scale, or does is occur over a longer time scale? Do the PK and PD profiles appear to be on the same time scale, or does the PD seem delayed compared to the PK? Is there clear separation between the profiles for different doses? Does the effect appear to increase with increasing dose? Do you detect a saturation of the effect?

data_to_plot <- list()
data_to_plot[[1]] <- my.data[my.data$CMT==2,]
data_to_plot[[2]] <- my.data[my.data$CMT==4,]

ggs <- list()
for(iplot in 1:length(data_to_plot)){
  data_to_plot[[iplot]]$TRTACT <- factor(data_to_plot[[iplot]]$TRTACT, levels = rev(levels(data_to_plot[[iplot]]$TRTACT)))
  
  gg <- ggplot(data = data_to_plot[[iplot]], 
               aes(x=NOMTIME/24,y=LIDV, color = TRTACT, fill = TRTACT))+theme_bw()
  
    gg <- gg + stat_summary(geom="errorbar", 
                          fun.data=function(y){
                            data.frame(y=median(y),
                                       ymin=quantile(y,0.025),
                                       ymax=quantile(y,0.975))
                          }, size = 1, width = 0, alpha = 0.5)
  gg <- gg + stat_summary(geom="point", fun.y=median, size = 2, alpha = 0.5)
  gg <- gg + stat_summary(aes(group = TRTACT), geom="line", fun.y=median, alpha = 0.5)
  if(iplot == 1){
    gg <- gg + scale_y_log10()
    gg <- gg + ylab("Concentration (ng/mL)")
  }else{
    gg <- gg + ylab("Count")
  }
  gg <- gg + guides(color=guide_legend(""),fill=guide_legend(""))
  gg <- gg  + xlab("Time (days)") + scale_x_continuous(breaks = seq(-1,8,1))
  ggs[[iplot]] <- gg
}

grid.arrange(ggs[[1]], ggs[[2]], ncol = 1)

PK and PD marker over time, faceted by Dose, median, 5th, 95th percentiles by nominal time

data_to_plot <- list()
data_to_plot[[1]] <- my.data[my.data$CMT==2,]
data_to_plot[[2]] <- my.data[my.data$CMT==4&my.data$DOSE>0,]

ggs <- list()
for(iplot in 1:length(data_to_plot)){
  gg <- ggplot(data = data_to_plot[[iplot]], 
               aes(x=NOMTIME/24,y=LIDV, group = TRTACT))+theme_bw()
  gg <- gg + stat_summary(geom="errorbar", 
                          fun.data=function(y){
                            data.frame(y=median(y),
                                       ymin=quantile(y,0.025),
                                       ymax=quantile(y,0.975))
                          }, size = 1, width = 0.2, alpha = 0.5)
  gg <- gg + stat_summary(geom="point", fun.y=median, size = 2, alpha = 0.5)
  gg <- gg + stat_summary(aes(group = TRTACT), geom="line", fun.y=median, alpha = 0.5)
  if(iplot == 1){
    gg <- gg + scale_y_log10()
    gg <- gg + ylab("Concentration (ng/mL)")
  }else{
    gg <- gg + ylab("Count")
  }
  gg <- gg + guides(color=guide_legend(""),fill=guide_legend(""))
  gg <- gg  + xlab("Time (days)") + scale_x_continuous(breaks = seq(-1,8,1)) + facet_grid(.~TRTACT)
  ggs[[iplot]] <- gg
}

grid.arrange(ggs[[1]], ggs[[2]], ncol = 1)

Explore Variability

PK and PD marker over time, colored by Dose, dots & lines grouped by individuals

data_to_plot <- list()
data_to_plot[[1]] <- my.data[my.data$CMT==2,]
data_to_plot[[2]] <- my.data[my.data$CMT==4,]

ggs <- list()
for(iplot in 1:length(data_to_plot)){
  data_to_plot[[iplot]]$TRTACT <- factor(data_to_plot[[iplot]]$TRTACT, levels = rev(levels(data_to_plot[[iplot]]$TRTACT)))
  
  gg <- ggplot(data = data_to_plot[[iplot]], 
               aes(x=TIME/24,y=LIDV, color = TRTACT, group = ID))+theme_bw()
  gg <- gg + geom_point(alpha = 0.5)
  gg <- gg + geom_line(alpha = 0.5)
  if(iplot == 1){
    gg <- gg + scale_y_log10()
    gg <- gg + ylab("Concentration (ng/mL)")
  }else{
    gg <- gg + ylab("Count")
  }
  gg <- gg + guides(color=guide_legend(""),fill=guide_legend(""))
  gg <- gg  + xlab("Time (days)") + scale_x_continuous(breaks = seq(-1,8,1))
  ggs[[iplot]] <- gg
}

grid.arrange(ggs[[1]], ggs[[2]], ncol = 1)

PK and PD marker over time, faceted by Dose, dots & lines grouped by individuals

data_to_plot <- list()
data_to_plot[[1]] <- my.data[my.data$CMT==2,]
data_to_plot[[2]] <- my.data[my.data$CMT==4&my.data$DOSE>0,]

ggs <- list()
for(iplot in 1:length(data_to_plot)){
  gg <- ggplot(data = data_to_plot[[iplot]], 
               aes(x=TIME/24,y=LIDV, group = ID))+theme_bw()
  gg <- gg + geom_point(alpha = 0.5)
  gg <- gg + geom_line(alpha = 0.5)
  if(iplot == 1){
    gg <- gg + scale_y_log10()
    gg <- gg + ylab("Concentration (ng/mL)")
  }else{
    gg <- gg + ylab("Count")
  }
  gg <- gg + guides(color=guide_legend(""),fill=guide_legend(""))
  gg <- gg  + xlab("Time (days)") + scale_x_continuous(breaks = seq(-1,8,1)) + facet_grid(.~TRTACT)
  ggs[[iplot]] <- gg
}

grid.arrange(ggs[[1]], ggs[[2]], ncol = 1)

Explore Exposure-Response Relationship

data_to_plot <- list()
data_to_plot[[1]] <- my.data[my.data$CMT==2&my.data$TRTACT!="Placebo",c("TIME","LIDV","ID","TRTACT")]
data_to_plot[[1]]$Concentration <- data_to_plot[[1]]$LIDV
data_to_plot[[1]]$LIDV <- NULL

data_to_plot[[2]] <- my.data[my.data$CMT==4,c("TIME","LIDV","ID","TRTACT")]
data_to_plot[[2]]$Response <- data_to_plot[[2]]$LIDV
data_to_plot[[2]]$LIDV <- NULL

data_to_plot2 <- merge(data_to_plot[[1]],data_to_plot[[2]],by=c("TIME","ID","TRTACT"))

data_to_plot2$TRTACT <- factor(data_to_plot2$TRTACT, levels = rev(levels(data_to_plot2$TRTACT)))

gg <- ggplot(data = data_to_plot2, aes(x=Concentration,y=Response))+theme_bw()
gg <- gg + geom_jitter(aes(color = TRTACT), width = 0, height = 0.1, alpha = 0.5)
gg <- gg + ylab("Count") + xlab("Concentration (ng/mL)")
# gg <- gg + scale_x_log10() + annotation_logticks(base = 10, sides = "b", color = rgb(0.5,0.5,0.5))
gg <- gg + guides(color = guide_legend("")) 
gg <- gg + geom_smooth( method = "glm",method.args=list(family=poisson), color = "black")
gg

data_to_plot <- list()
data_to_plot[[1]] <- my.data[my.data$CMT==2&my.data$PROFDAY%in%c(1,3,5),c("TIME","LIDV","ID","TRTACT","PROFDAY")]
data_to_plot[[1]]$Concentration <- data_to_plot[[1]]$LIDV
data_to_plot[[1]]$LIDV <- NULL

data_to_plot[[2]] <- my.data[my.data$CMT==4&my.data$PROFDAY%in%c(1,3,5),c("TIME","LIDV","ID","TRTACT","PROFDAY")]
data_to_plot[[2]]$Response <- data_to_plot[[2]]$LIDV
data_to_plot[[2]]$LIDV <- NULL

data_to_plot2 <- merge(data_to_plot[[1]],data_to_plot[[2]],by=c("TIME","ID","TRTACT","PROFDAY"))
data_to_plot2$DAY_label <- paste("Day", data_to_plot2$PROFDAY)
data_to_plot2$TRTACT <- factor(data_to_plot2$TRTACT, 
                                   levels = rev(levels(data_to_plot2$TRTACT)))

gg <- ggplot(data = data_to_plot2, aes(y=Concentration,x=Response))+theme_bw()
# gg <- gg + geom_path(aes(group = ID))
gg <- gg + geom_boxplot(aes(group = Response)) + coord_flip()
gg <- gg + geom_jitter(aes(color = TRTACT), width = 0.1, height = 0, alpha = 0.5) 
gg <- gg + guides(color=guide_legend(""),fill=guide_legend(""))
gg <- gg + xlab("Count") + ylab("Concentration (ng/mL)")
gg <- gg + scale_y_log10() #+ annotation_logticks(base = 10, sides = "l", color = rgb(0.5,0.5,0.5))
gg + facet_grid(~DAY_label)

Explore covariate effects on Exposure-Response Relationship

Stratify exposure-response plots by covariates of interest to explore whether any key covariates impact response independent of exposure. For examples of plots and code startifying by covariate, see Continuous PKPD Covariate Section

Individual response vs exposure hysteresis plots

Using geom_path you can create hysteresis plots of response vs exposure. Including details like arrows or colors can be helpful to indicate the direction of time.

If most of the arrows point up and to the right or down and to the left, this indicates a positive relationship between exposure and response (i.e. increasing exposure -> increasing response). Arrows pointing down and to the right or up and to the left indicate a negative relationship.

In a hysteresis plot, you want to determine whether the path is curving, and if so in what direction. If you detect a curve in the hysteresis plot, this indicates there is a delay between the exposure and the response. Normally, a clockwise turn indicates that increasing exposure is associated with (a delayed) increasing response, while a counter clockwise turn indicates increasing concentration gives (a delayed) decreasing response.

In the plots below, most of the hysteresis paths follow a counter clockwise turn, with most arrows pointing up and to the right or down and to the left, indicating the effect increases in a delayed manner with increasing concentration.

data_to_plot <- list()
data_to_plot[[1]] <- my.data[my.data$CMT==2&my.data$TRTACT!="Placebo",c("TIME","LIDV","ID","TRTACT")]
data_to_plot[[1]]$Concentration <- data_to_plot[[1]]$LIDV
data_to_plot[[1]]$LIDV <- NULL

data_to_plot[[2]] <- my.data[my.data$CMT==4,c("TIME","LIDV","ID","TRTACT")]
data_to_plot[[2]]$Response <- data_to_plot[[2]]$LIDV
data_to_plot[[2]]$LIDV <- NULL

data_to_plot2 <- merge(data_to_plot[[1]],data_to_plot[[2]],by=c("TIME","ID","TRTACT"))

data_to_plot2$TRTACT <- factor(data_to_plot2$TRTACT, 
                                   levels = rev(levels(data_to_plot2$TRTACT)))

gg <- ggplot(data = data_to_plot2, aes(x=Concentration,y=Response, color=TIME))+theme_bw()
gg <- gg + geom_path(arrow=arrow(length=unit(0.15,"cm")))
gg <- gg + ylab("Count") + xlab("Concentration (ng/mL)")
gg <- gg + scale_x_log10() + scale_y_log10() + annotation_logticks(base = 10, sides = "lb", color = rgb(0.5,0.5,0.5))
gg+facet_wrap(~ID+TRTACT, ncol = 5)

R Session Info

sessionInfo()
## R version 3.4.3 (2017-11-30)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Red Hat Enterprise Linux Server 7.4 (Maipo)
## 
## Matrix products: default
## BLAS/LAPACK: /CHBS/apps/intel/17.4.196/compilers_and_libraries_2017.4.196/linux/mkl/lib/intel64_lin/libmkl_gf_lp64.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] grid      stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] reshape_0.8.7   lubridate_1.7.1 survival_2.41-3 DT_0.2         
##  [5] RxODE_0.6-1     bindrcpp_0.2    haven_1.1.0     readr_1.1.1    
##  [9] readxl_1.0.0    xtable_1.8-2    tidyr_0.7.2     caTools_1.17.1 
## [13] zoo_1.8-0       dplyr_0.7.4     ggplot2_2.2.1   gridExtra_2.3  
## 
## loaded via a namespace (and not attached):
##  [1] purrr_0.2.4        reshape2_1.4.3     splines_3.4.3     
##  [4] lattice_0.20-35    colorspace_1.3-2   htmltools_0.3.6   
##  [7] yaml_2.1.16        rlang_0.1.6        pillar_1.0.1      
## [10] glue_1.2.0         RColorBrewer_1.1-2 binom_1.1-1       
## [13] bindr_0.1          plyr_1.8.4         stringr_1.2.0     
## [16] munsell_0.4.3      gtable_0.2.0       cellranger_1.1.0  
## [19] htmlwidgets_0.9    codetools_0.2-15   evaluate_0.10.1   
## [22] memoise_1.1.0      labeling_0.3       knitr_1.18        
## [25] forcats_0.2.0      rex_1.1.2          markdown_0.8      
## [28] Rcpp_0.12.14       scales_0.5.0       backports_1.1.2   
## [31] jsonlite_1.5       hms_0.4.0          digest_0.6.13     
## [34] stringi_1.1.3      rprojroot_1.3-1    tools_3.4.3       
## [37] bitops_1.0-6       magrittr_1.5       lazyeval_0.2.1    
## [40] tibble_1.4.1       pkgconfig_2.0.1    Matrix_1.2-12     
## [43] rsconnect_0.8.5    assertthat_0.2.0   rmarkdown_1.8     
## [46] R6_2.2.2           compiler_3.4.3