Rmarkdown template to generate this page can be found on Rmarkdown-Template.

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)

theme_set(theme_bw(base_size=12))

Single Time-to-event (e.g. survival)

Single time-to-event plots should be summarized by Kaplan-Meier plots and stratified by dose to give an overview of the dose-response

library(survival)
km_data <- lung %>%
  dplyr::rename(dose = ph.ecog)
km_fit <- survfit(Surv(time) ~ dose, data = km_data)
# summary(km_fit)
km_fit2 <- summary(km_fit, times = c(1,30,60,90*(1:10)))
data = data.frame(time =km_fit2$time, 
                  surv= km_fit2$surv, 
                  dose = km_fit2$strata) %>%
  mutate(dose = stringr::str_replace(dose,"dose=","")) %>%
  filter(dose!="3")

gg <- ggplot(data, aes(x=time, y=surv, color = factor(dose)))
gg <- gg + geom_line(size = 1)
gg <- gg + scale_y_continuous(labels=scales::percent_format())
gg <- gg + ylab("Survival") + xlab("Time") + labs(color="Dose (mg)")
#gg <- gg + guides(color=guide_legend("")) 
gg

pp3 <- gg + theme(legend.position = "none")

Repeated Time-to-event

Provide an overview of the data

Mean Event Rate over time

For repeated time to event data, the rate of occurance of the events can be plotted. The observed average rate of occurance would be related to the Hazard rate in a time-to-event model.

Calculate the rate of occurance of an event as the number of events occuring within specific time intervals, average over the number of subjects being observed.

Observe the mean event rate, do you see any patterns? Does the event rate increase or decrease over time, or at specific time points (e.g. dosing intervals, circadian rhythms)?

# (coming soon)

Mean Cumulative Function

The mean cumulative function is another way of looking at repeated time-to-event data. The mean cumulative function is the population average of the cumulative number of events over time, and would be related to the Cumulative Hazard in a time-to-event model.

Calculate the mean cumulative function by ordering all of the events by increasing time, calculate the cumulative number of occurances up to each time point, and take the average over the number of subjects being observed. For repeated time-to-event data, the mean cumulative function can achieve values greater than 1.

# (coming soon)

Explore Dose-Response Relationship

(coming soon)

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] survival_2.41-3 DT_0.2          RxODE_0.6-1     bindrcpp_0.2   
##  [5] haven_1.1.0     readr_1.1.1     readxl_1.0.0    xtable_1.8-2   
##  [9] tidyr_0.7.2     caTools_1.17.1  zoo_1.8-0       dplyr_0.7.4    
## [13] 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