diff --git a/vignettes/adrg-prepare.Rmd b/vignettes/adrg-prepare.Rmd index fb76265..5523e54 100644 --- a/vignettes/adrg-prepare.Rmd +++ b/vignettes/adrg-prepare.Rmd @@ -54,24 +54,24 @@ knitr::include_graphics("pdf/tlf-efficacy.pdf") ``` ```{r, eval = FALSE} -knitr::purl("tlf-demographic.Rmd", output = "ectd/tlf-demographic.txt") -knitr::purl("tlf-efficacy.Rmd", output = "ectd/tlf-efficacy.txt") -knitr::purl("tlf-kmplot.Rmd", output = "ectd/tlf-kmplot.txt") -knitr::purl("tlf-primary.Rmd", output = "ectd/tlf-primary.txt") +knitr::purl("tlf-demographic.Rmd", output = "ectd/tlf-demographic.r") +knitr::purl("tlf-efficacy.Rmd", output = "ectd/tlf-efficacy.r") +knitr::purl("tlf-kmplot.Rmd", output = "ectd/tlf-kmplot.r") +knitr::purl("tlf-primary.Rmd", output = "ectd/tlf-primary.r") ``` ## List R package for analysis -CRAN package - ```{r} pkg <- c("haven", "dplyr", "emmeans", "r2rtf","rtables", + "ggplot2", "cowplot", "visR", "Tplyr", "pharmaRTF", "huxtable") available.packages(contriburl = contrib.url(repos)) %>% data.frame() %>% subset(Package %in% pkg) %>% - select(Package, Version, Repository) + select(Package, Version, Repository) %>% + arrange(Package) ``` Proprietary Package diff --git a/vignettes/ectd/r0pkg.txt b/vignettes/ectd/r0pkg.txt index 5ec977e..99823df 100644 --- a/vignettes/ectd/r0pkg.txt +++ b/vignettes/ectd/r0pkg.txt @@ -108,20 +108,28 @@ Content: ## Overview - The objective of the R Cconsortium R submission Pilot 1 Project is to + The objective of the R Consortium R submission Pilot 1 Project is to test the concept that a R-language based submission package can meet the needs and the expectations of the FDA reviewers, including assessing code review and analyses reproducibility. - All submission materials and communications from this pilot is publicly available, + All submission materials and communications from this pilot are publicly available, with the aim of providing a working example for future R language based FDA submissions. This is a FDA-industry collaboration through the non-profit organization R consortium. - The [RConsortium/submissions-pilot1](https://github.com/RConsortium/submissions-pilot1) repo demonstrate an approach to organize internal developed R function and + The [RConsortium/submissions-pilot1](https://github.com/RConsortium/submissions-pilot1) repo demonstrates an approach to organize internal developed R function and table, listing, figure generation program using an R package. The [RConsortium/submissions-pilot1-to-fda](https://github.com/RConsortium/submissions-pilot1-to-fda) - repo demonstrate the eCTD submission package based on the [RConsortium/submissions-pilot1](https://github.com/RConsortium/submissions-pilot1) repo. + repo demonstrates the eCTD submission package based on the [RConsortium/submissions-pilot1](https://github.com/RConsortium/submissions-pilot1) repo. + ## Running Environment + + The project is developed and tested in the environment below: + + - OS: Ubuntu 20.04 + - R version: R4.1.0 + - Snapshot date: 2021-08-31 + - Snapshot repository: https://mran.microsoft.com/snapshot/2021-08-31 ## Folder Structure @@ -172,7 +180,7 @@ Content: #' #' This function handles the necessary data processing to handle the CDISC pilot #' primary endpoint analysis. The original source can be found - #' \link[here]{https://github.com/atorus-research/CDISC_pilot_replication/blob/3c8e9e3798c02be8d93bd8e8944d1e0d3f6519e2/programs/funcs.R#L401} + #' [here](https://github.com/atorus-research/CDISC_pilot_replication/blob/3c8e9e3798c02be8d93bd8e8944d1e0d3f6519e2/programs/funcs.R#L401) #' #' @importFrom tidyr pivot_longer #' @importFrom glue glue @@ -527,7 +535,7 @@ Content: \description{ This function handles the necessary data processing to handle the CDISC pilot primary endpoint analysis. The original source can be found - \link[here]{https://github.com/atorus-research/CDISC_pilot_replication/blob/3c8e9e3798c02be8d93bd8e8944d1e0d3f6519e2/programs/funcs.R#L401} + \href{https://github.com/atorus-research/CDISC_pilot_replication/blob/3c8e9e3798c02be8d93bd8e8944d1e0d3f6519e2/programs/funcs.R#L401}{here} } Package: pilot1wrappers @@ -758,6 +766,11 @@ Content: \item Eli Miller } + Other contributors: + \itemize{ + \item Steven Haesendonckx [contributor] + } + } \keyword{internal} @@ -807,7 +820,7 @@ Content: } # Repository - message("Current oroject R package repository:") + message("Current project R package repository:") message(paste0(" ", getOption("repos"))) message(" ") diff --git a/vignettes/ectd/tlf-demographic.txt b/vignettes/ectd/tlf-demographic.r similarity index 76% rename from vignettes/ectd/tlf-demographic.txt rename to vignettes/ectd/tlf-demographic.r index 5e51477..f14d0c8 100644 --- a/vignettes/ectd/tlf-demographic.txt +++ b/vignettes/ectd/tlf-demographic.r @@ -6,17 +6,19 @@ # path = list(adam = "path/to/esub/analysis/adam/datasets") # Modify path to the actual location # path$outtable = path$outgraph = "." # Output saved in current folder + library(haven) library(dplyr) library(rtables) library(pilot1wrappers) -## ------------------------------------------------------------------------------------------------------------------ +## ----------------------------------------------------------------------------------------------------------------------------------- adsl <- read_xpt(file.path(path$adam, "adsl.xpt")) +adsl_labels <- var_labels(adsl) -## ------------------------------------------------------------------------------------------------------------------ +## ----------------------------------------------------------------------------------------------------------------------------------- adsl <- adsl %>% dplyr::filter( STUDYID == "CDISCPILOT01", @@ -26,18 +28,19 @@ adsl <- adsl %>% TRT01P = factor(TRT01P, levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose")), AGEGR1 = factor(AGEGR1, levels = c("<65", "65-80", ">80")), RACE = factor(RACE, levels = c("WHITE", "BLACK OR AFRICAN AMERICAN", "AMERICAN INDIAN OR ALASKA NATIVE")) - ) + ) -## ------------------------------------------------------------------------------------------------------------------ +## ----------------------------------------------------------------------------------------------------------------------------------- # Table layout +vars <- c("AGE", "AGEGR1", "RACE", "HEIGHTBL", "WEIGHTBL", "BMIBL", "MMSETOT") lyt <- basic_table(title = "Protocol: CDISCPILOT01", subtitles = "Population: Intent-to-Treat", - main_footer = "Program: tlf_demographic.Rmd" + main_footer = paste0("Program: tlf_demographic.Rmd \n" , Sys.time()) ) %>% split_cols_by("TRT01P") %>% add_colcounts() %>% - analyze(c("AGE", "AGEGR1", "RACE", "HEIGHTBL", "WEIGHTBL", "BMIBL", "MMSETOT"), function(x, ...) { + analyze(vars, function(x, ...) { if (is.numeric(x)) { in_rows( "Mean (sd)" = c(mean(x), sd(x)), @@ -50,7 +53,8 @@ lyt <- basic_table(title = "Protocol: CDISCPILOT01", } else { stop("type not supproted") } - }) + }, + var_labels = adsl_labels[vars]) # Table build tbl <- build_table(lyt, adsl) @@ -58,7 +62,7 @@ tbl <- build_table(lyt, adsl) tbl -## ------------------------------------------------------------------------------------------------------------------ +## ----------------------------------------------------------------------------------------------------------------------------------- # Output .out file tbl %>% toString() %>% diff --git a/vignettes/ectd/tlf-efficacy.txt b/vignettes/ectd/tlf-efficacy.r similarity index 84% rename from vignettes/ectd/tlf-efficacy.txt rename to vignettes/ectd/tlf-efficacy.r index 3be20e9..b661707 100644 --- a/vignettes/ectd/tlf-efficacy.txt +++ b/vignettes/ectd/tlf-efficacy.r @@ -7,20 +7,17 @@ # path$outtable = path$outgraph = "." # Output saved in current folder library(dplyr) -library(tibble) -library(tidyr) library(haven) library(r2rtf) library(emmeans) library(pilot1wrappers) -## ------------------------------------------------------------------------------------------------------------------ -adsl <- read_xpt(file.path(path$adam, "adsl.xpt")) +## ----------------------------------------------------------------------------------------------------------------------------------- adlb <- read_xpt(file.path(path$adam, "adlbc.xpt")) -## ------------------------------------------------------------------------------------------------------------------ +## ----------------------------------------------------------------------------------------------------------------------------------- adlb1 <- subset(adlb, TRTPN %in% c(0, 81) & PARAMCD == "GLUC" & !is.na(AVISITN)) %>% mutate(TRTPN = ifelse(TRTPN == 0, 99, TRTPN)) # change treatment order for pairwise comparison @@ -64,7 +61,7 @@ apr0ancova1 <- merge(t11, t12) %>% apr0ancova1 -## ------------------------------------------------------------------------------------------------------------------ +## ----------------------------------------------------------------------------------------------------------------------------------- t2 <- data.frame(pairs(t12)) ## Treatment Comparison @@ -83,7 +80,7 @@ apr0ancova2 <- t2 %>% apr0ancova2 -## ------------------------------------------------------------------------------------------------------------------ +## ----------------------------------------------------------------------------------------------------------------------------------- ### Calculate root mean square and save data in output folder apr0ancova3 <- data.frame(rmse = paste0( "Root Mean Squared Error of Change = ", @@ -93,7 +90,7 @@ apr0ancova3 <- data.frame(rmse = paste0( apr0ancova3 -## ------------------------------------------------------------------------------------------------------------------ +## ----------------------------------------------------------------------------------------------------------------------------------- tbl_1 <- apr0ancova1 %>% rtf_title( title = "ANCOVA of Change from Baseline at Week 20", @@ -127,7 +124,7 @@ tbl_1 <- apr0ancova1 %>% ) -## ------------------------------------------------------------------------------------------------------------------ +## ----------------------------------------------------------------------------------------------------------------------------------- tbl_2 <- apr0ancova2 %>% rtf_colheader( colheader = "Pairwise Comparison | Difference in LS Mean (95% CI){^a} | p-Value", @@ -141,7 +138,7 @@ tbl_2 <- apr0ancova2 %>% ) -## ------------------------------------------------------------------------------------------------------------------ +## ----------------------------------------------------------------------------------------------------------------------------------- tbl_3 <- apr0ancova3 %>% rtf_body( as_colheader = FALSE, @@ -149,9 +146,13 @@ tbl_3 <- apr0ancova3 %>% ) -## ------------------------------------------------------------------------------------------------------------------ +## ----------------------------------------------------------------------------------------------------------------------------------- tbl <- list(tbl_1, tbl_2, tbl_3) tbl %>% rtf_encode() %>% write_rtf(file.path(path$output, "tlf-efficacy.rtf")) + +## ---- out.width = "100%", out.height = "400px", echo = FALSE, fig.align = "center"-------------------------------------------------- +knitr::include_graphics("pdf/tlf-efficacy.pdf") + diff --git a/vignettes/ectd/tlf-kmplot.r b/vignettes/ectd/tlf-kmplot.r new file mode 100644 index 0000000..99d02fb --- /dev/null +++ b/vignettes/ectd/tlf-kmplot.r @@ -0,0 +1,91 @@ +# Note to Reviewer +# To rerun the code below, please refer ADRG appendix. +# After required package are installed. +# The path variable needs to be defined by using example code below +# +# path = list(adam = "path/to/esub/analysis/adam/datasets") # Modify path to the actual location +# path$outtable = path$outgraph = "." # Output saved in current folder + +library(haven) +library(dplyr) +library(pilot1wrappers) +library(ggplot2) +library(cowplot) +library(visR) + + +## ----------------------------------------------------------------------------------------------------------------------------------- +adsl <- read_xpt(file.path(path$adam, "adsl.xpt")) +adtte <- read_xpt(file.path(path$adam, "adtte.xpt")) + + +## ----------------------------------------------------------------------------------------------------------------------------------- +anl <- adsl %>% + dplyr::filter( + SAFFL == "Y", + STUDYID == "CDISCPILOT01" + ) %>% + dplyr::select(STUDYID, USUBJID, TRT01A) %>% + dplyr::inner_join( + filter( + adtte, PARAMCD == "TTDE", STUDYID == "CDISCPILOT01" + ) %>% select(STUDYID, USUBJID, AVAL, CNSR, PARAM, PARAMCD), + by = c("STUDYID", "USUBJID") + ) %>% + dplyr::mutate( + TRT01A = factor(TRT01A, levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose")) + ) + + +## ----------------------------------------------------------------------------------------------------------------------------------- +# estimate survival +surv_mod <- visR::estimate_KM(data = anl, strata = "TRT01A") + +# save plot +ggplot2::theme_set(theme_bw()) + +pdf.options(reset = TRUE, onefile = FALSE) + +pdf(file.path(path$output, "tlf-kmplot.pdf")) + +KM <- visR::visr(surv_mod, + y_label = "Probability of event\n", + x_label = "Time to First Dermatologic Event (Days)", + y_ticks = seq(0,1,0.10)) %>% + add_CNSR() %>% + add_CI() + +KM <- KM + + ggplot2::geom_hline(yintercept=0.5, linetype = "dashed") + +KM <- KM %>% + visR::add_risktable(group = "statlist") + +title <- cowplot::ggdraw() + + cowplot::draw_label( + "KM plot for Time to First Dermatologic Event: Safety population\n", + fontfamily = "sans", + fontface = "bold", + size=10 + ) + +caption <- cowplot::ggdraw() + + cowplot::draw_label( + paste0("\nProgram: tlf_kmplot.Rmd [", Sys.time(), "]"), + fontfamily = "sans", + size=10 + ) + +KM <- cowplot::plot_grid( + title, KM, caption, + ncol = 1, + rel_heights = c(0.1,0.8,0.1) +) + +print(KM) +dev.off() + + +## ---- out.width = "100%", out.height = "400px", echo = FALSE, fig.align = "center"-------------------------------------------------- +knitr::include_graphics("pdf/tlf-kmplot.pdf") + diff --git a/vignettes/ectd/tlf-kmplot.txt b/vignettes/ectd/tlf-kmplot.txt deleted file mode 100644 index 1f1b3f3..0000000 --- a/vignettes/ectd/tlf-kmplot.txt +++ /dev/null @@ -1,56 +0,0 @@ -# Note to Reviewer -# To rerun the code below, please refer ADRG appendix. -# After required package are installed. -# The path variable needs to be defined by using example code below -# -# path = list(adam = "path/to/esub/analysis/adam/datasets") # Modify path to the actual location -# path$outtable = path$outgraph = "." # Output saved in current folder - -library(haven) -library(dplyr) -library(pilot1wrappers) - - -## ------------------------------------------------------------------------------------------------------------------ -adsl <- read_xpt(file.path(path$adam, "adsl.xpt")) -adtte <- read_xpt(file.path(path$adam, "adtte.xpt")) - - -## ------------------------------------------------------------------------------------------------------------------ -anl <- adsl %>% - dplyr::filter( - SAFFL == "Y", - STUDYID == "CDISCPILOT01" - ) %>% - dplyr::select(STUDYID, USUBJID, TRT01A) %>% - dplyr::inner_join( - filter( - adtte, PARAMCD == "TTDE", STUDYID == "CDISCPILOT01" - ) %>% select(STUDYID, USUBJID, AVAL, CNSR), - by = c("STUDYID", "USUBJID") - ) %>% - dplyr::mutate( - TRT01A = factor(TRT01A, levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose")) - ) - - -## ------------------------------------------------------------------------------------------------------------------ -surv_mod <- survival::Surv(anl$AVAL, anl$CNSR == 0) -surv_fit <- survival::survfit(surv_mod ~ anl$TRT01A) -ngr <- table(anl$TRT01A) -col <- 1:length(ngr) - -# save plot -pdf(file.path(path$output, "tlf-kmplot.pdf")) -plot(surv_fit, col = col, oma=c(2, 3, 5, 2)) -abline(h = 0.5, lty = 2) -legend( - "bottomleft", legend = paste0(names(ngr), " (n=", ngr, ")"), - col = col, pch = 19, cex = 0.7 -) -title = "KM plot for Time to First Dermatologic Event: Safety population" -footnote = "Program: tlf_kmplot.Rmd" -mtext(side = 3, line = 3, at = -0.07, adj = 0, cex = 1, title) -mtext(side = 1, line = 2, at = -0.07, adj = 0, cex = 0.7, footnote) -dev.off() - diff --git a/vignettes/ectd/tlf-primary.txt b/vignettes/ectd/tlf-primary.r similarity index 85% rename from vignettes/ectd/tlf-primary.txt rename to vignettes/ectd/tlf-primary.r index 6c3c624..dbbf20c 100644 --- a/vignettes/ectd/tlf-primary.txt +++ b/vignettes/ectd/tlf-primary.r @@ -6,7 +6,7 @@ # path = list(adam = "path/to/esub/analysis/adam/datasets") # Modify path to the actual location # path$outtable = path$outgraph = "." # Output saved in current folder -## ----setup, message=FALSE----------------------------------------------------------------------------------------- +## ----setup, message=FALSE----------------------------------------------------------------------------------------------------------- library(dplyr) library(Tplyr) library(pharmaRTF) @@ -14,12 +14,12 @@ library(pilot1wrappers) options(huxtable.add_colnames = FALSE) -## ----------------------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------------------------------------------------------------------- adas <- haven::read_xpt(file.path(path$adam, "adadas.xpt")) adsl <- haven::read_xpt(file.path(path$adam, "adsl.xpt")) -## ----------------------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------------------------------------------------------------------- adas <- adas %>% filter( EFFFL == "Y", @@ -29,7 +29,7 @@ adas <- adas %>% ) -## ----------------------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------------------------------------------------------------------- t <- tplyr_table(adas, TRTP) %>% set_pop_data(adsl) %>% set_pop_treat_var(TRT01P) %>% @@ -61,11 +61,11 @@ sum_data <- t %>% ) -## ----------------------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------------------------------------------------------------------- model_portion <- efficacy_models(adas, 'CHG', 24) -## ----------------------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------------------------------------------------------------------- final <- bind_rows(sum_data, model_portion) ht <- huxtable::as_hux(final, add_colnames = FALSE) %>% @@ -79,7 +79,7 @@ ht <- huxtable::as_hux(final, add_colnames = FALSE) %>% ht -## ----------------------------------------------------------------------------------------------------------------- +## ----------------------------------------------------------------------------------------------------------------------------------- doc <- rtf_doc(ht) %>% set_font_size(10) %>% set_ignore_cell_padding(TRUE) %>% @@ -137,3 +137,6 @@ doc <- rtf_doc(ht) %>% write_rtf(doc, file=file.path(path$output, 'tlf-primary.rtf')) +## ---- out.width = "100%", out.height = "400px", echo = FALSE, fig.align = "center"-------------------------------------------------- +knitr::include_graphics("pdf/tlf-primary.pdf") +