Skip to content

Commit

Permalink
update ectd R code
Browse files Browse the repository at this point in the history
  • Loading branch information
elong0527 committed Nov 14, 2021
1 parent 5378288 commit 3841701
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 96 deletions.
14 changes: 7 additions & 7 deletions vignettes/adrg-prepare.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 20 additions & 7 deletions vignettes/ectd/r0pkg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -758,6 +766,11 @@ Content:
\item Eli Miller
}

Other contributors:
\itemize{
\item Steven Haesendonckx [contributor]
}

}
\keyword{internal}

Expand Down Expand Up @@ -807,7 +820,7 @@ Content:
}

# Repository
message("Current oroject R package repository:")
message("Current project R package repository:")
message(paste0(" ", getOption("repos")))
message(" ")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)),
Expand All @@ -50,15 +53,16 @@ lyt <- basic_table(title = "Protocol: CDISCPILOT01",
} else {
stop("type not supproted")
}
})
},
var_labels = adsl_labels[vars])

# Table build
tbl <- build_table(lyt, adsl)

tbl


## ------------------------------------------------------------------------------------------------------------------
## -----------------------------------------------------------------------------------------------------------------------------------
# Output .out file
tbl %>%
toString() %>%
Expand Down
23 changes: 12 additions & 11 deletions vignettes/ectd/tlf-efficacy.txt → vignettes/ectd/tlf-efficacy.r
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -64,7 +61,7 @@ apr0ancova1 <- merge(t11, t12) %>%
apr0ancova1


## ------------------------------------------------------------------------------------------------------------------
## -----------------------------------------------------------------------------------------------------------------------------------
t2 <- data.frame(pairs(t12))

## Treatment Comparison
Expand All @@ -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 = ",
Expand All @@ -93,7 +90,7 @@ apr0ancova3 <- data.frame(rmse = paste0(
apr0ancova3


## ------------------------------------------------------------------------------------------------------------------
## -----------------------------------------------------------------------------------------------------------------------------------
tbl_1 <- apr0ancova1 %>%
rtf_title(
title = "ANCOVA of Change from Baseline at Week 20",
Expand Down Expand Up @@ -127,7 +124,7 @@ tbl_1 <- apr0ancova1 %>%
)


## ------------------------------------------------------------------------------------------------------------------
## -----------------------------------------------------------------------------------------------------------------------------------
tbl_2 <- apr0ancova2 %>%
rtf_colheader(
colheader = "Pairwise Comparison | Difference in LS Mean (95% CI){^a} | p-Value",
Expand All @@ -141,17 +138,21 @@ tbl_2 <- apr0ancova2 %>%
)


## ------------------------------------------------------------------------------------------------------------------
## -----------------------------------------------------------------------------------------------------------------------------------
tbl_3 <- apr0ancova3 %>%
rtf_body(
as_colheader = FALSE,
text_justification = "l"
)


## ------------------------------------------------------------------------------------------------------------------
## -----------------------------------------------------------------------------------------------------------------------------------
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")

91 changes: 91 additions & 0 deletions vignettes/ectd/tlf-kmplot.r
Original file line number Diff line number Diff line change
@@ -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")

Loading

0 comments on commit 3841701

Please sign in to comment.