Skip to content

Commit 3841701

Browse files
committed
update ectd R code
1 parent 5378288 commit 3841701

7 files changed

+152
-96
lines changed

vignettes/adrg-prepare.Rmd

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,24 @@ knitr::include_graphics("pdf/tlf-efficacy.pdf")
5454
```
5555

5656
```{r, eval = FALSE}
57-
knitr::purl("tlf-demographic.Rmd", output = "ectd/tlf-demographic.txt")
58-
knitr::purl("tlf-efficacy.Rmd", output = "ectd/tlf-efficacy.txt")
59-
knitr::purl("tlf-kmplot.Rmd", output = "ectd/tlf-kmplot.txt")
60-
knitr::purl("tlf-primary.Rmd", output = "ectd/tlf-primary.txt")
57+
knitr::purl("tlf-demographic.Rmd", output = "ectd/tlf-demographic.r")
58+
knitr::purl("tlf-efficacy.Rmd", output = "ectd/tlf-efficacy.r")
59+
knitr::purl("tlf-kmplot.Rmd", output = "ectd/tlf-kmplot.r")
60+
knitr::purl("tlf-primary.Rmd", output = "ectd/tlf-primary.r")
6161
```
6262

6363
## List R package for analysis
6464

65-
CRAN package
66-
6765
```{r}
6866
pkg <- c("haven", "dplyr", "emmeans", "r2rtf","rtables",
67+
"ggplot2", "cowplot", "visR",
6968
"Tplyr", "pharmaRTF", "huxtable")
7069
7170
available.packages(contriburl = contrib.url(repos)) %>%
7271
data.frame() %>%
7372
subset(Package %in% pkg) %>%
74-
select(Package, Version, Repository)
73+
select(Package, Version, Repository) %>%
74+
arrange(Package)
7575
```
7676

7777
Proprietary Package

vignettes/ectd/r0pkg.txt

+20-7
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,28 @@ Content:
108108

109109
## Overview
110110

111-
The objective of the R Cconsortium R submission Pilot 1 Project is to
111+
The objective of the R Consortium R submission Pilot 1 Project is to
112112
test the concept that a R-language based submission package can meet
113113
the needs and the expectations of the FDA reviewers,
114114
including assessing code review and analyses reproducibility.
115-
All submission materials and communications from this pilot is publicly available,
115+
All submission materials and communications from this pilot are publicly available,
116116
with the aim of providing a working example for future R language based FDA submissions.
117117
This is a FDA-industry collaboration through the non-profit organization R consortium.
118118

119-
The [RConsortium/submissions-pilot1](https://github.com/RConsortium/submissions-pilot1) repo demonstrate an approach to organize internal developed R function and
119+
The [RConsortium/submissions-pilot1](https://github.com/RConsortium/submissions-pilot1) repo demonstrates an approach to organize internal developed R function and
120120
table, listing, figure generation program using an R package.
121121

122122
The [RConsortium/submissions-pilot1-to-fda](https://github.com/RConsortium/submissions-pilot1-to-fda)
123-
repo demonstrate the eCTD submission package based on the [RConsortium/submissions-pilot1](https://github.com/RConsortium/submissions-pilot1) repo.
123+
repo demonstrates the eCTD submission package based on the [RConsortium/submissions-pilot1](https://github.com/RConsortium/submissions-pilot1) repo.
124124

125+
## Running Environment
126+
127+
The project is developed and tested in the environment below:
128+
129+
- OS: Ubuntu 20.04
130+
- R version: R4.1.0
131+
- Snapshot date: 2021-08-31
132+
- Snapshot repository: https://mran.microsoft.com/snapshot/2021-08-31
125133

126134
## Folder Structure
127135

@@ -172,7 +180,7 @@ Content:
172180
#'
173181
#' This function handles the necessary data processing to handle the CDISC pilot
174182
#' primary endpoint analysis. The original source can be found
175-
#' \link[here]{https://github.com/atorus-research/CDISC_pilot_replication/blob/3c8e9e3798c02be8d93bd8e8944d1e0d3f6519e2/programs/funcs.R#L401}
183+
#' [here](https://github.com/atorus-research/CDISC_pilot_replication/blob/3c8e9e3798c02be8d93bd8e8944d1e0d3f6519e2/programs/funcs.R#L401)
176184
#'
177185
#' @importFrom tidyr pivot_longer
178186
#' @importFrom glue glue
@@ -527,7 +535,7 @@ Content:
527535
\description{
528536
This function handles the necessary data processing to handle the CDISC pilot
529537
primary endpoint analysis. The original source can be found
530-
\link[here]{https://github.com/atorus-research/CDISC_pilot_replication/blob/3c8e9e3798c02be8d93bd8e8944d1e0d3f6519e2/programs/funcs.R#L401}
538+
\href{https://github.com/atorus-research/CDISC_pilot_replication/blob/3c8e9e3798c02be8d93bd8e8944d1e0d3f6519e2/programs/funcs.R#L401}{here}
531539
}
532540

533541
Package: pilot1wrappers
@@ -758,6 +766,11 @@ Content:
758766
\item Eli Miller
759767
}
760768

769+
Other contributors:
770+
\itemize{
771+
\item Steven Haesendonckx [contributor]
772+
}
773+
761774
}
762775
\keyword{internal}
763776

@@ -807,7 +820,7 @@ Content:
807820
}
808821

809822
# Repository
810-
message("Current oroject R package repository:")
823+
message("Current project R package repository:")
811824
message(paste0(" ", getOption("repos")))
812825
message(" ")
813826

vignettes/ectd/tlf-demographic.txt vignettes/ectd/tlf-demographic.r

+12-8
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
# path = list(adam = "path/to/esub/analysis/adam/datasets") # Modify path to the actual location
77
# path$outtable = path$outgraph = "." # Output saved in current folder
88

9+
910
library(haven)
1011
library(dplyr)
1112
library(rtables)
1213
library(pilot1wrappers)
1314

1415

15-
## ------------------------------------------------------------------------------------------------------------------
16+
## -----------------------------------------------------------------------------------------------------------------------------------
1617
adsl <- read_xpt(file.path(path$adam, "adsl.xpt"))
18+
adsl_labels <- var_labels(adsl)
1719

1820

19-
## ------------------------------------------------------------------------------------------------------------------
21+
## -----------------------------------------------------------------------------------------------------------------------------------
2022
adsl <- adsl %>%
2123
dplyr::filter(
2224
STUDYID == "CDISCPILOT01",
@@ -26,18 +28,19 @@ adsl <- adsl %>%
2628
TRT01P = factor(TRT01P, levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose")),
2729
AGEGR1 = factor(AGEGR1, levels = c("<65", "65-80", ">80")),
2830
RACE = factor(RACE, levels = c("WHITE", "BLACK OR AFRICAN AMERICAN", "AMERICAN INDIAN OR ALASKA NATIVE"))
29-
)
31+
)
3032

3133

32-
## ------------------------------------------------------------------------------------------------------------------
34+
## -----------------------------------------------------------------------------------------------------------------------------------
3335
# Table layout
36+
vars <- c("AGE", "AGEGR1", "RACE", "HEIGHTBL", "WEIGHTBL", "BMIBL", "MMSETOT")
3437
lyt <- basic_table(title = "Protocol: CDISCPILOT01",
3538
subtitles = "Population: Intent-to-Treat",
36-
main_footer = "Program: tlf_demographic.Rmd"
39+
main_footer = paste0("Program: tlf_demographic.Rmd \n" , Sys.time())
3740
) %>%
3841
split_cols_by("TRT01P") %>%
3942
add_colcounts() %>%
40-
analyze(c("AGE", "AGEGR1", "RACE", "HEIGHTBL", "WEIGHTBL", "BMIBL", "MMSETOT"), function(x, ...) {
43+
analyze(vars, function(x, ...) {
4144
if (is.numeric(x)) {
4245
in_rows(
4346
"Mean (sd)" = c(mean(x), sd(x)),
@@ -50,15 +53,16 @@ lyt <- basic_table(title = "Protocol: CDISCPILOT01",
5053
} else {
5154
stop("type not supproted")
5255
}
53-
})
56+
},
57+
var_labels = adsl_labels[vars])
5458

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

5862
tbl
5963

6064

61-
## ------------------------------------------------------------------------------------------------------------------
65+
## -----------------------------------------------------------------------------------------------------------------------------------
6266
# Output .out file
6367
tbl %>%
6468
toString() %>%

vignettes/ectd/tlf-efficacy.txt vignettes/ectd/tlf-efficacy.r

+12-11
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,17 @@
77
# path$outtable = path$outgraph = "." # Output saved in current folder
88

99
library(dplyr)
10-
library(tibble)
11-
library(tidyr)
1210
library(haven)
1311
library(r2rtf)
1412
library(emmeans)
1513
library(pilot1wrappers)
1614

1715

18-
## ------------------------------------------------------------------------------------------------------------------
19-
adsl <- read_xpt(file.path(path$adam, "adsl.xpt"))
16+
## -----------------------------------------------------------------------------------------------------------------------------------
2017
adlb <- read_xpt(file.path(path$adam, "adlbc.xpt"))
2118

2219

23-
## ------------------------------------------------------------------------------------------------------------------
20+
## -----------------------------------------------------------------------------------------------------------------------------------
2421
adlb1 <- subset(adlb, TRTPN %in% c(0, 81) & PARAMCD == "GLUC" & !is.na(AVISITN)) %>%
2522
mutate(TRTPN = ifelse(TRTPN == 0, 99, TRTPN)) # change treatment order for pairwise comparison
2623

@@ -64,7 +61,7 @@ apr0ancova1 <- merge(t11, t12) %>%
6461
apr0ancova1
6562

6663

67-
## ------------------------------------------------------------------------------------------------------------------
64+
## -----------------------------------------------------------------------------------------------------------------------------------
6865
t2 <- data.frame(pairs(t12))
6966

7067
## Treatment Comparison
@@ -83,7 +80,7 @@ apr0ancova2 <- t2 %>%
8380
apr0ancova2
8481

8582

86-
## ------------------------------------------------------------------------------------------------------------------
83+
## -----------------------------------------------------------------------------------------------------------------------------------
8784
### Calculate root mean square and save data in output folder
8885
apr0ancova3 <- data.frame(rmse = paste0(
8986
"Root Mean Squared Error of Change = ",
@@ -93,7 +90,7 @@ apr0ancova3 <- data.frame(rmse = paste0(
9390
apr0ancova3
9491

9592

96-
## ------------------------------------------------------------------------------------------------------------------
93+
## -----------------------------------------------------------------------------------------------------------------------------------
9794
tbl_1 <- apr0ancova1 %>%
9895
rtf_title(
9996
title = "ANCOVA of Change from Baseline at Week 20",
@@ -127,7 +124,7 @@ tbl_1 <- apr0ancova1 %>%
127124
)
128125

129126

130-
## ------------------------------------------------------------------------------------------------------------------
127+
## -----------------------------------------------------------------------------------------------------------------------------------
131128
tbl_2 <- apr0ancova2 %>%
132129
rtf_colheader(
133130
colheader = "Pairwise Comparison | Difference in LS Mean (95% CI){^a} | p-Value",
@@ -141,17 +138,21 @@ tbl_2 <- apr0ancova2 %>%
141138
)
142139

143140

144-
## ------------------------------------------------------------------------------------------------------------------
141+
## -----------------------------------------------------------------------------------------------------------------------------------
145142
tbl_3 <- apr0ancova3 %>%
146143
rtf_body(
147144
as_colheader = FALSE,
148145
text_justification = "l"
149146
)
150147

151148

152-
## ------------------------------------------------------------------------------------------------------------------
149+
## -----------------------------------------------------------------------------------------------------------------------------------
153150
tbl <- list(tbl_1, tbl_2, tbl_3)
154151
tbl %>%
155152
rtf_encode() %>%
156153
write_rtf(file.path(path$output, "tlf-efficacy.rtf"))
157154

155+
156+
## ---- out.width = "100%", out.height = "400px", echo = FALSE, fig.align = "center"--------------------------------------------------
157+
knitr::include_graphics("pdf/tlf-efficacy.pdf")
158+

vignettes/ectd/tlf-kmplot.r

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Note to Reviewer
2+
# To rerun the code below, please refer ADRG appendix.
3+
# After required package are installed.
4+
# The path variable needs to be defined by using example code below
5+
#
6+
# path = list(adam = "path/to/esub/analysis/adam/datasets") # Modify path to the actual location
7+
# path$outtable = path$outgraph = "." # Output saved in current folder
8+
9+
library(haven)
10+
library(dplyr)
11+
library(pilot1wrappers)
12+
library(ggplot2)
13+
library(cowplot)
14+
library(visR)
15+
16+
17+
## -----------------------------------------------------------------------------------------------------------------------------------
18+
adsl <- read_xpt(file.path(path$adam, "adsl.xpt"))
19+
adtte <- read_xpt(file.path(path$adam, "adtte.xpt"))
20+
21+
22+
## -----------------------------------------------------------------------------------------------------------------------------------
23+
anl <- adsl %>%
24+
dplyr::filter(
25+
SAFFL == "Y",
26+
STUDYID == "CDISCPILOT01"
27+
) %>%
28+
dplyr::select(STUDYID, USUBJID, TRT01A) %>%
29+
dplyr::inner_join(
30+
filter(
31+
adtte, PARAMCD == "TTDE", STUDYID == "CDISCPILOT01"
32+
) %>% select(STUDYID, USUBJID, AVAL, CNSR, PARAM, PARAMCD),
33+
by = c("STUDYID", "USUBJID")
34+
) %>%
35+
dplyr::mutate(
36+
TRT01A = factor(TRT01A, levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"))
37+
)
38+
39+
40+
## -----------------------------------------------------------------------------------------------------------------------------------
41+
# estimate survival
42+
surv_mod <- visR::estimate_KM(data = anl, strata = "TRT01A")
43+
44+
# save plot
45+
ggplot2::theme_set(theme_bw())
46+
47+
pdf.options(reset = TRUE, onefile = FALSE)
48+
49+
pdf(file.path(path$output, "tlf-kmplot.pdf"))
50+
51+
KM <- visR::visr(surv_mod,
52+
y_label = "Probability of event\n",
53+
x_label = "Time to First Dermatologic Event (Days)",
54+
y_ticks = seq(0,1,0.10)) %>%
55+
add_CNSR() %>%
56+
add_CI()
57+
58+
KM <- KM +
59+
ggplot2::geom_hline(yintercept=0.5, linetype = "dashed")
60+
61+
KM <- KM %>%
62+
visR::add_risktable(group = "statlist")
63+
64+
title <- cowplot::ggdraw() +
65+
cowplot::draw_label(
66+
"KM plot for Time to First Dermatologic Event: Safety population\n",
67+
fontfamily = "sans",
68+
fontface = "bold",
69+
size=10
70+
)
71+
72+
caption <- cowplot::ggdraw() +
73+
cowplot::draw_label(
74+
paste0("\nProgram: tlf_kmplot.Rmd [", Sys.time(), "]"),
75+
fontfamily = "sans",
76+
size=10
77+
)
78+
79+
KM <- cowplot::plot_grid(
80+
title, KM, caption,
81+
ncol = 1,
82+
rel_heights = c(0.1,0.8,0.1)
83+
)
84+
85+
print(KM)
86+
dev.off()
87+
88+
89+
## ---- out.width = "100%", out.height = "400px", echo = FALSE, fig.align = "center"--------------------------------------------------
90+
knitr::include_graphics("pdf/tlf-kmplot.pdf")
91+

0 commit comments

Comments
 (0)