Skip to content

Commit d638baa

Browse files
authored
Merge pull request #1145 from alex-lauer/gt_clinical_tables
Gt clinical tables vignette
2 parents e263689 + 24804d4 commit d638baa

16 files changed

Lines changed: 555 additions & 2 deletions

‎.Rbuildignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
^README\.Rmd$
1313
^README\.md$
1414
^LICENSE\.md$
15+
^CITATION\.cff$
1516
vignettes
1617
man/figures/
1718
tests/gt-examples
@@ -61,4 +62,3 @@ tests/testthat/test-tab_spanner_delim.R
6162
tests/testthat/test-tab_stub_indent.R
6263
tests/testthat/test-table_parts.R
6364
tests/testthat/test-vec_fmt.R
64-
^CITATION\.cff$

‎DESCRIPTION‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ Authors@R: c(
1616
person("Barret", "Schloerke", , "[email protected]", "aut",
1717
comment = c(ORCID = "0000-0001-9986-114X")),
1818
person("Ellis", "Hughes", , "[email protected]", "aut",
19-
comment = c(ORCID = "0000-0003-0637-4436")),
19+
comment = c(ORCID = "0000-0003-0637-4436")),
20+
person("Alexandra", "Lauer", , "[email protected]", "aut",
21+
comment = c(ORCID = "0000-0002-4191-6301")),
2022
person("JooYoung", "Seo", , "[email protected]", "aut",
2123
comment = c(ORCID = "0000-0002-4064-6012")),
2224
person("Posit Software, PBC", role = c("cph", "fnd"))

‎R/datasets.R‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,64 @@
343343
#' 11-6
344344
#'
345345
"exibble"
346+
347+
#' An ADaM-flavored clinical trial toy dataset
348+
#'
349+
#' @description
350+
#' This tibble contains artificial data for 182 subjects of the `GT01` study.
351+
#' Each row corresponds to demographic characteristics of a single trial
352+
#' participant. Two out of 182 study participants were screen failures and
353+
#' thus not treated, the rest of the study population was randomized with a
354+
#' 1:1 ratio to receive either `Placebo` (as comparator) or `Drug 1`. The
355+
#' dataset entails subject level demographics such as age, age group, sex,
356+
#' ethnicity and body mass index (BMI) at baseline, as well as an event
357+
#' flag, indicating whether the subject experienced a specific event
358+
#' throughout the course of the study or not.
359+
#' Although the data was intentionally created to mimic a typical clinical
360+
#' trial dataset following the CDISC format, it might not strictly comply
361+
#' with CDISC ADaM rules. The intent is to showcase the workflow for clinical
362+
#' table creation rather than creating a fully CDISC-compliant ADaM dataset.
363+
#'
364+
#'
365+
#' @format A tibble with 182 rows and 14 variables:
366+
#' \describe{
367+
#' \item{STUDYID, STUDYIDN}{The unique study identifier and its numeric
368+
#' version.}
369+
#' \item{USUBJID}{The unique subject identifier.}
370+
#' \item{TRTA, TRTAN}{The study intervention and its numeric version, which
371+
#' is either `Placebo` (`1`), `Drug 1` (`2`) or `` (`3`, missing for screen
372+
#' failures).}
373+
#' \item{ITTFL}{Intent-to-Treat (ITT) population flag, where `Y` indicates
374+
#' a subject belongs to the ITT population and `N` indicates a subject
375+
#' is not in the ITT population.}
376+
#' \item{RANDFL}{Randomization flag, where `Y` indicates a subject was
377+
#' randomized to receive either `Placebo` or `Drug 1` and `N` indicates
378+
#' a subject was not randomized at all.}
379+
#' \item{SCRFREAS}{The reason for screen failure. This is either missing (``)
380+
#' for non-screen failure subjects or indicates the reason for screen failure}
381+
#' \item{AGE}{The age of a subject at baseline in years.}
382+
#' \item{AAGEGR1}{The analysis age group, indicating if a subject was strictly
383+
#' younger than 40 years at baseline or older.}
384+
#' \item{SEX}{Sex of a subject. Can be either `Male`, `Female` or
385+
#' `Undifferentiated`.}
386+
#' \item{ETHNIC}{Ethnicity of a subject. Can be either `Hispanic or Latino`,
387+
#' `Not Hispanic or Latino` or missing (``).}
388+
#' \item{BLBMI}{Body Mass Index (BMI) of a subject at baseline in kg/m2.}
389+
#' \item{EVNTFL}{Event Flag. Indicates whether the subject experienced a
390+
#' specific event during the course of the study or not. Can be either `Y`,
391+
#' if the subject had the event, or `N`}
392+
#' }
393+
#'
394+
#' @section Examples:
395+
#'
396+
#' Here is the `gt_adsl`.
397+
#'
398+
#' ```{r}
399+
#' gt_adsl
400+
#' ```
401+
#'
402+
#' @family datasets
403+
#' @section Function ID:
404+
#' 11-7
405+
#'
406+
"gt_adsl"

‎data-raw/07-gt_clinical.R‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
library(tidyverse)
2+
3+
gt_subjects <- paste0("GT", 1001:1180)
4+
gt_treatments <- c("Placebo", "Drug 1")
5+
6+
set.seed(3141592)
7+
8+
gt_adsl <- dplyr::tribble(
9+
~STUDYID, ~STUDYIDN, ~USUBJID, ~TRTA, ~TRTAN, ~ITTFL, ~RANDFL, ~SCRFREAS,
10+
"GT01", "4001", "GT1000", "Screen Failure", 3, "N", "N", "WITHDRAWAL BY SUBJECT",
11+
"GT01", "4001", "GT1181", "Screen Failure", 3, "N", "N", "OTHER",
12+
) |>
13+
dplyr::bind_rows(
14+
data.frame(STUDYID = "GT01",
15+
STUDYIDN = "4001",
16+
USUBJID = gt_subjects,
17+
TRTA = rep(gt_treatments, each = length(gt_subjects)/length(gt_treatments)),
18+
TRTAN = rep(seq_along(gt_treatments), each = length(gt_subjects)/length(gt_treatments)),
19+
ITTFL = "Y",
20+
RANDFL = "Y",
21+
SCRFREAS = ""
22+
)
23+
) |>
24+
dplyr::mutate(TRTA = factor(TRTA, levels = gt_treatments)) |>
25+
dplyr::arrange(USUBJID) |>
26+
dplyr::group_by(TRTA) |>
27+
dplyr::mutate(AGE = rpois(n = dplyr::n(), lambda = 40),
28+
AAGEGR1 = factor(
29+
ifelse(AGE >= 40, ">=40", "<40"),
30+
levels = c("<40", ">=40")
31+
),
32+
SEX = factor(
33+
sample(c("M", "F", "U"), dplyr::n(), replace = TRUE, prob = c(.6, .35, 0.05)),
34+
levels = c("M", "F", "U"),
35+
labels = c("Male", "Female", "Undifferentiated")
36+
),
37+
ETHNIC = factor(
38+
sample(c("HISPANIC OR LATINO", "NOT HISPANIC OR LATINO", ""), dplyr::n(), replace = TRUE, prob = c(.4, .5, .1)),
39+
levels = c("HISPANIC OR LATINO", "NOT HISPANIC OR LATINO", ""),
40+
labels = c("Hispanic or Latino", "Not Hispanic or Latino", "Missing")
41+
),
42+
BLBMI = runif(n = dplyr::n(), min = 18, max = 35),
43+
EVNTFL = dplyr::case_when(
44+
TRTAN == 3 ~ "",
45+
TRTAN == 2 ~ sample(c("Y", "N"), dplyr::n(), replace = TRUE, prob = c(.7, .3)),
46+
TRTAN == 1 ~ sample(c("Y", "N"), dplyr::n(), replace = TRUE, prob = c(.4, .6))
47+
)
48+
) |>
49+
dplyr::ungroup()
50+
51+
attr(gt_adsl$STUDYID, "label") <- "Unique Study Identifier"
52+
attr(gt_adsl$STUDYIDN, "label") <- "Unique Study Identifier (N)"
53+
attr(gt_adsl$USUBJID, "label") <- "Unique Subject Identifier"
54+
attr(gt_adsl$TRTA, "label") <- "Actual Treatment"
55+
attr(gt_adsl$TRTAN, "label") <- "Actual Treatment (N)"
56+
attr(gt_adsl$ITTFL, "label") <- "ITT Population Flag"
57+
attr(gt_adsl$RANDFL, "label") <- "Randomization Flag"
58+
attr(gt_adsl$SCRFREAS, "label") <- "Reason for Screen Failure"
59+
attr(gt_adsl$AGE, "label") <- "Age"
60+
attr(gt_adsl$AGE, "units") <- "Years"
61+
attr(gt_adsl$AAGEGR1, "label") <- "Age Group"
62+
attr(gt_adsl$SEX, "label") <- "Sex"
63+
attr(gt_adsl$ETHNIC, "label") <- "Ethnicity"
64+
attr(gt_adsl$BLBMI, "label") <- "Body Mass Index"
65+
attr(gt_adsl$BLBMI, "units") <- "kg/m2"
66+
attr(gt_adsl$EVNTFL, "label") <- "Event Flag"
67+
68+

‎data/gt.rda‎

13.1 KB
Binary file not shown.

‎data/gt_adsl.rda‎

2.72 KB
Binary file not shown.

‎man/countrypops.Rd‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/exibble.Rd‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/gt-package.Rd‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎man/gt_adsl.Rd‎

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)