28  Clinical Data Standards: CDISC, SDTM, and ADaM

Alumni of this program who now work for pharmaceutical sponsors and contract research organizations (CROs) report the same first week: data structures, variable names, and regulatory conventions that their statistics courses never mentioned. One of those conventions produces a wrong answer without an error. The time-to-event datasets they are handed code an event as CNSR = 0 and censoring as a positive number. This is the reverse of what survival::Surv() expects. As a result Surv(AVAL, CNSR) runs, draws a plausible curve, and estimates the curve of censoring instead of the curve of events. This chapter builds the standard datasets for the running HF-HOME trial. We begin with the tabulation layer a sponsor submits and end with the analysis datasets you will specify and check. Along the way we show where each convention can go wrong without warning.

The nice thing about standards is that you have so many to choose from.

Andrew S. Tanenbaum, Computer Networks (attributed; wording and page vary by edition)

Diagram of the analysis pipeline: six stages in order (Plan, Acquire, Wrangle, Analyze, Report, Share) above two bands that run under every stage (Version control and Environment). Highlighted for this chapter: Wrangle.
Figure 28.1: Where this chapter sits: deriving analysis datasets from the submitted tabulations is part of the Wrangle stage, which turns raw tables into the derived analytic datasets.
NoteIn this chapter

Reading time. About 45 minutes.

You’ll need. Chapter 18 for declared join relationships, Section 26.2 for the HF-HOME estimand, and Chapter 16 for dates. The code uses:

It also sources the HF-HOME generator, R/hfhome.R, which needs no packages beyond base R.

You’ll be able to.

  • Trace a trial’s data from the case report form through SDTM and ADaM to the tables of a clinical study report, and name who builds each layer.
  • Derive a subject-level dataset (ADSL) and a time-to-event dataset (ADTTE) from SDTM domains, with randomization dates and population flags drawn from the right source.
  • Convert the CDISC censoring code correctly at the boundary with survival::Surv(), and verify the event count against an independent derivation.
  • Name the R tools a sponsor uses for tables, package validation, and double programming, and what each checks.
  • Explain what distinguishes a pre-specified TLF shell from an exploratory table, and name the obligations 21 CFR Part 11 and ICH E6(R3) place on a regulated computing environment.

Outline.

If these answers come quickly, skip to the next chapter. The answers are in Section 28.11.

  1. What is the difference between SDTM and ADaM, and who typically specifies and builds ADaM?
  2. In the CDISC convention, does CNSR = 1 indicate a censored observation or an event?
  3. What is the role of ADSL relative to other ADaM datasets such as ADLB or ADTTE?

28.1 From protocol to submission

The Clinical Data Interchange Standards Consortium (CDISC) is a non-profit that publishes data standards for clinical research. Since December 2016, the United States Food and Drug Administration (FDA) has required study data in CDISC formats for new drug applications (NDAs) and biologics license applications (BLAs) (US Food and Drug Administration, 2024). Two of the CDISC standards are the statistician’s daily material. The Study Data Tabulation Model (SDTM) is the submitted record of what was collected. The Analysis Data Model (ADaM) holds the datasets the analyses run on.1

1 Two other CDISC standards sit on either side of these. CDASH (Clinical Data Acquisition Standards Harmonization) standardizes the case report form, so that collected fields map cleanly to SDTM; SEND (Standard for Exchange of Nonclinical Data) is SDTM’s counterpart for animal studies.

28.1.1 The pipeline and who builds each layer

Figure 28.2 shows the flow and the row granularity at each stage, which is the quantity to track across every join.

flowchart TD
  P["Protocol and SAP<br/><i>design, endpoints, estimands</i>"] --> C["CRF<br/><i>site data entry</i>"]
  C --> S["SDTM domains<br/>DM · EX · AE · LB · VS · DS<br/><i>one row per observation</i>"]
  S --> A["ADaM datasets<br/>ADSL · ADTTE · ADAE<br/><i>analysis-ready</i>"]
  A --> T["TLFs<br/><i>tables, listings, figures</i>"]
  T --> R["CSR and FDA submission<br/><i>Define-XML, aCRF, SDRG, ADRG</i>"]
  S -.->|"immutable once locked"| S
  A -.->|"traceable to SDTM"| S
Figure 28.2: The regulatory data pipeline from protocol to FDA submission. SDTM is the immutable source the analysis reads; ADaM is the analysis-ready layer derived from it.

The protocol and statistical analysis plan (SAP) define the trial. Sites record observations on case report forms (CRFs), and data management builds the SDTM domains from the collected data. ADaM datasets are derived from SDTM. The tables, listings, and figures (TLFs) of the clinical study report (CSR) are then produced from ADaM. In most sponsors and CROs the work on ADaM is divided. The biostatistician writes the SAP and, often, the ADaM specifications. Statistical programmers implement the datasets and the TLFs against those specifications, usually with independent double programming as validation (Section 28.5). Whichever role you take, your deliverables will be ADaM specifications, ADaM datasets, or the tables built from them.

Two rules organize the pipeline. Immutability: once SDTM is locked it is not edited to suit a new analysis. A new analytic need produces a new ADaM variable instead. Traceability: every ADaM variable points back to its SDTM source and its derivation. Both are recorded in the ADaM specification and in Define-XML. The order of work follows from the second rule. We write the specification, review it, and then implement it. Building the dataset first and writing the specification from the result is a common antipattern. The specification is the contract that gets reviewed, so it has to come first.

28.1.2 The submission package

A submission carries more than datasets. Table 28.1 lists the supporting documents a statistician meets. You will rarely write Define-XML by hand, because tools generate it from the specification.

Table 28.1: The documents that accompany SDTM and ADaM in a submission.
Document What it is Typically produced by
Define-XML Machine-readable metadata for every variable: type, controlled terminology, derivation, source Generated from the specifications
Annotated CRF (aCRF) The blank CRF with SDTM variable names on each field Data management
Study Data Reviewer’s Guide (SDRG) Narrative on SDTM conformance and known issues Data management
Analysis Data Reviewer’s Guide (ADRG) Narrative on ADaM datasets and analysis choices Statistics and programming
SAP Pre-specified analyses, analysis sets, estimands, sensitivity analyses Biostatistician

Question. SDTM already holds every collected value in a one-row-per-observation layout, and ADaM adds no new data. Why build a second layer rather than fit the model on SDTM?

Answer. ADaM is where the analysis decisions become explicit, traceable, and reviewable one at a time. These include which subjects are in each analysis set, which date starts the clock, how censoring was assigned, and which visit is baseline. If we fit the model on SDTM, those decisions are still made. However, they are made inside the modeling script, mixed together, and visible only to whoever reads the code. The separation is the book’s raw and derived data rule (Chapter 13): SDTM is data/raw/, ADaM is data/derived/.

28.2 SDTM: the data as collected

SDTM organizes a trial’s observations into domains, each a dataset on one topic. The ones you will meet first are DM (demographics, one row per subject), EX (exposure, one row per dose or dosing interval), DS (disposition, one row per milestone or event), AE (adverse events), LB (laboratory results), and VS (vital signs). Within a domain each row is a single observation, and the same variable names (USUBJID, VISIT, --TESTCD, --ORRES, --STRESN) recur across domains. Dates are ISO 8601 character strings such as '2024-03-15' or '2024-03-15T08:30', not Date values. The reason is that a collected date can be partial ('2024-03'), and a character field holds it as collected.

28.2.1 The HF-HOME domains

The HF-HOME generator includes hfhome_sdtm(), which builds minimal DM, EX, and DS domains from the trial. EX has one row per home-health visit, the intervention in this trial. DS has a RANDOMIZED protocol milestone for every subject and one disposition event (COMPLETED at day 30, DEATH, or LOST TO FOLLOW-UP for an unascertained outcome). Readmissions belong in the healthcare-encounters domain, HO, which the chunk builds from the outcome file. Real SDTM has many more variables per domain; these keep only what the ADaM derivations need.

library(dplyr)
library(survival)

source(file.path('..', '..', 'R', 'hfhome.R'))
sdtm <- hfhome_sdtm()
dm <- sdtm$dm
ex <- sdtm$ex
ds <- sdtm$ds

hf_dir <- file.path('..', 'data', 'raw_data', 'hfhome')
read_hf <- function(file) {
  readr::read_csv(file.path(hf_dir, file),
                  col_types = readr::cols(patient_id = 'c',
                                          .default = '?'))
}

ho <- read_hf('outcomes.csv') |>
  filter(!is.na(readmit_date)) |>
  transmute(STUDYID = 'HFHOME', DOMAIN = 'HO',
            USUBJID = paste('HFHOME', patient_id, sep = '-'),
            HOTERM  = 'HOSPITAL READMISSION',
            HOSTDTC = format(readmit_date, '%Y-%m-%d'))

c(DM = nrow(dm), EX = nrow(ex), DS = nrow(ds), HO = nrow(ho))
#>   DM   EX   DS   HO 
#> 2432 2237 4864  429
head(select(dm, USUBJID, SITEID, RFSTDTC, AGE, SEX, ARM, ACTARM), 3)
#>       USUBJID SITEID    RFSTDTC AGE SEX         ARM      ACTARM
#> 1 HFHOME-0001     02 2024-02-01  77   F Home health Home health
#> 2 HFHOME-0002     05 2024-02-01  77   F Home health Home health
#> 3 HFHOME-0003     05 2024-02-01  62   F  Usual care Home health
head(select(ds, USUBJID, DSDECOD, DSCAT, DSSTDTC), 4)
#>       USUBJID    DSDECOD              DSCAT    DSSTDTC
#> 1 HFHOME-0001 RANDOMIZED PROTOCOL MILESTONE 2024-02-01
#> 2 HFHOME-0001  COMPLETED  DISPOSITION EVENT 2024-03-02
#> 3 HFHOME-0002 RANDOMIZED PROTOCOL MILESTONE 2024-02-01
#> 4 HFHOME-0002  COMPLETED  DISPOSITION EVENT 2024-03-02

ARM is the planned arm, as randomized. ACTARM is the arm the subject actually received. Here that means home health if a visit occurred within 7 days of discharge. The two differ for the nonadherent patients in both arms.

TipVerification

Confirm the structural promises of each domain before deriving anything from it: one DM row per subject, character dates, two DS rows per subject, and no EX or HO subject missing from DM.

stopifnot(
  !anyDuplicated(dm$USUBJID),
  is.character(dm$RFSTDTC), is.character(ex$EXSTDTC),
  is.character(ds$DSSTDTC), is.character(ho$HOSTDTC),
  all(table(ds$USUBJID) == 2),
  all(ex$USUBJID %in% dm$USUBJID),
  all(ho$USUBJID %in% dm$USUBJID)
)

These are structural checks: they confirm the shape the derivations assume, not that any value is right.

28.2.2 Controlled terminology

CDISC publishes codelists that enumerate the valid values of categorical variables. SEX, for instance, takes values such as 'M', 'F', and 'U', not 'Male', 'male', or '1'. The ADaM specification cites the codelist version for each controlled variable, and conformance tools reject values outside it.

28.2.3 Exercises

  1. Count the HF-HOME subjects by ARM and ACTARM, and compute, from DS, the number of disposition events of each kind by planned arm. Which counts would differ if you had grouped by ACTARM?
count(dm, ARM, ACTARM)
#>           ARM      ACTARM    n
#> 1 Home health Home health 1019
#> 2 Home health  Usual care  197
#> 3  Usual care Home health   64
#> 4  Usual care  Usual care 1152

ds |>
  filter(DSCAT == 'DISPOSITION EVENT') |>
  left_join(select(dm, USUBJID, ARM), by = 'USUBJID',
            relationship = 'one-to-one') |>
  count(ARM, DSDECOD)
#>           ARM           DSDECOD    n
#> 1 Home health         COMPLETED 1087
#> 2 Home health             DEATH   49
#> 3 Home health LOST TO FOLLOW-UP   80
#> 4  Usual care         COMPLETED 1071
#> 5  Usual care             DEATH   62
#> 6  Usual care LOST TO FOLLOW-UP   83

Every off-diagonal cell of the first table is a subject whose received care differs from the assignment. Grouping disposition by ACTARM would move those subjects between arms, so every count in the second table would change. Analyses as randomized use ARM (in ADaM, TRT01P). The treatment actually received belongs to ACTARM (TRT01A), which has its own, different uses.

Question. A colleague converts every --DTC variable to Date as soon as SDTM is read, ‘to save time later’. What is lost?

Answer. Partial dates. In a column whose first value is a complete date, as.Date() turns '2024-03' into NA without an error. A collected month and year therefore becomes missing. The imputation rule the SAP states for partial dates can then no longer be applied. Keep --DTC as character in SDTM and convert in ADaM, where the conversion and any imputation are part of a documented derivation (Chapter 16).

28.3 ADaM: the data as analyzed

ADaM datasets take SDTM as input and produce rows and columns shaped for direct use by statistical procedures. There are three principal structures, listed in Table 28.2. The variables they share are collected in the ADaM variable card at the end of the chapter (Table 28.3).

Table 28.2: The three ADaM structures. Every other dataset joins back to ADSL by USUBJID.
Structure Rows Examples Key variables
ADSL (subject-level) Exactly one per subject ADSL USUBJID, TRT01P, TRT01A, RANDDT, population flags
BDS (basic data structure) One per subject, parameter, and analysis timepoint ADLB, ADVS, ADTTE PARAMCD, AVAL, AVISIT, ABLFL, BASE, CHG, CNSR
OCCDS (occurrence data structure) One per occurrence ADAE, ADCM AEDECOD, ASTDT, TRTEMFL

28.3.1 The censoring convention

In an ADTTE dataset, AVAL is the time and CNSR is the censoring indicator. HF-HOME will use 1 for a subject followed to day 30 without an event and 2 for a subject lost to follow-up.

WarningPitfall

Surv(AVAL, CNSR) runs and estimates the wrong curve. CDISC codes the event as CNSR = 0 and censoring as a positive integer, usually 1, though a sponsor may use 2, 3, and so on for different censoring reasons. survival::Surv() expects the opposite: its second argument is 1 (or TRUE) for an event. Passed unconverted, every censored subject is treated as an event and every event as censored. The fitted curve then describes censoring, and the arm with longer follow-up looks worse. The arithmetic shortcut Surv(AVAL, 1 - CNSR) is right only while every censored row has CNSR = 1. A CNSR = 2 becomes -1, which Surv() turns into NA with only a warning, and those subjects leave the analysis without notice. Convert once, at the boundary, with Surv(AVAL, CNSR == 0). This is true for the event whatever the censoring codes are.

28.3.2 Analysis sets and the estimand

The SAP pre-specifies which analysis set each analysis uses, and ADSL implements the choice as flags. The intention-to-treat (ITT) set, or full analysis set (FAS), includes every randomized subject, analyzed as randomized (ITTFL, FASFL). A modified ITT set excludes a few randomized subjects by a rule the protocol states in advance (for example, no post-baseline assessment). Its definition varies by sponsor and must be read, not assumed. The safety set includes every subject who received at least one dose, analyzed as treated (SAFFL). A per-protocol set excludes subjects with important protocol deviations (PPROTFL).

An analysis set is not the estimand’s population. ICH E9(R1) (International Council for Harmonisation, 2019) defines the population at the level of the scientific question. The analysis set is then chosen so that the analysis estimates that estimand. For HF-HOME the SAP’s estimand uses a treatment-policy strategy for nonadherence (Section 26.2). That is, we analyze every randomized subject as randomized, from randomization. Filtering on the wrong flag analyzes a different group of patients than the SAP promised. The analysis may then no longer target the stated estimand.

Question. The HF-HOME SAP’s primary analysis is ‘all randomized patients, as randomized’. Which ADSL variables implement that, and what changes if a programmer groups by TRT01A instead?

Answer. Filter on ITTFL == 'Y' and group by TRT01P, the planned (randomized) arm. Grouping by TRT01A moves every nonadherent subject into the arm of the care they received. The groups are then no longer the randomized groups, and the comparison is no longer protected by randomization. The treatment-policy estimand is not what it estimates. The code runs either way, which is why the specification names the variable.

28.4 Worked example: ADSL and ADTTE for HF-HOME

The derivation below builds ADSL and an ADTTE for time to readmission or death within 30 days of randomization, then analyzes it on the ITT set. The SAP’s primary analysis is the 30-day risk difference (Section 26.8). The time-to-event analysis here is supportive. It describes when the same composite events occurred.

28.4.1 Derive ADSL

ADSL has exactly one row per subject and carries everything a downstream analysis stratifies or filters on. Each date comes from its proper source. RANDDT comes from the RANDOMIZED milestone in DS. TRTSDT and TRTEDT come from the first start and last end of exposure in EX, never from the disposition date. Usual-care subjects who received no home-health visit have no EX rows, so their treatment dates are missing, which is correct.

randomized <- ds |>
  filter(DSDECOD == 'RANDOMIZED') |>
  transmute(USUBJID, RANDDT = as.Date(DSSTDTC))

exposure <- ex |>
  group_by(USUBJID) |>
  summarize(TRTSDT = min(as.Date(EXSTDTC)),
            TRTEDT = max(as.Date(EXENDTC)),
            .groups = 'drop')

arms <- c('Usual care', 'Home health')
adsl <- dm |>
  left_join(randomized, by = 'USUBJID',
            relationship = 'one-to-one', unmatched = 'error') |>
  left_join(exposure, by = 'USUBJID',
            relationship = 'one-to-one') |>
  mutate(
    TRT01P  = factor(ARM, levels = arms),
    TRT01A  = factor(ACTARM, levels = arms),
    AGEGR1  = if_else(AGE < 65, '<65', '>=65'),
    ITTFL   = if_else(!is.na(RANDDT), 'Y', 'N'),
    PPROTFL = if_else(TRT01A == TRT01P, 'Y', 'N')
  ) |>
  select(STUDYID, USUBJID, SUBJID, SITEID, AGE, AGEGR1, SEX, RACE,
         TRT01P, TRT01A, RANDDT, TRTSDT, TRTEDT, ITTFL, PPROTFL)

stopifnot(nrow(adsl) == nrow(dm), !anyDuplicated(adsl$USUBJID))
count(adsl, TRT01P, PPROTFL)
#>        TRT01P PPROTFL    n
#> 1  Usual care       N   64
#> 2  Usual care       Y 1152
#> 3 Home health       N  197
#> 4 Home health       Y 1019

The per-protocol flag is included only to show what it does. Restricting HF-HOME to subjects who received their assigned care compares two subsets selected after randomization. Section 26.2 explains why that targets none of the estimands the SAP could state.

28.4.2 Derive ADTTE

ADTTE is a BDS dataset: one row per subject per time-to-event parameter. The clock starts at RANDDT, because the estimand is defined from randomization. The home-health visit happens after randomization or not at all. The event is the first of a readmission (from HO) or a death (from DS) within 30 days. A subject without an event is censored at day 30 (CNSR = 1), or, if lost to follow-up, at the last contact (CNSR = 2).

disposition <- ds |>
  filter(DSCAT == 'DISPOSITION EVENT') |>
  transmute(USUBJID, DSDECOD, DISPDT = as.Date(DSSTDTC))

first_readmit <- ho |>
  group_by(USUBJID) |>
  summarize(READMDT = min(as.Date(HOSTDTC)), .groups = 'drop')

deaths <- disposition |>
  filter(DSDECOD == 'DEATH') |>
  transmute(USUBJID, DTHDT = DISPDT)

adtte <- adsl |>
  select(STUDYID, USUBJID, TRT01P, TRT01A, ITTFL, RANDDT) |>
  left_join(disposition, by = 'USUBJID',
            relationship = 'one-to-one', unmatched = 'error') |>
  left_join(first_readmit, by = 'USUBJID',
            relationship = 'one-to-one') |>
  left_join(deaths, by = 'USUBJID', relationship = 'one-to-one') |>
  mutate(
    PARAMCD  = 'RDTH30',
    PARAM    = 'Time to readmission or death within 30 days (days)',
    STARTDT  = RANDDT,
    EVNTDT   = pmin(READMDT, DTHDT, na.rm = TRUE),
    CNSR     = case_when(
      !is.na(EVNTDT) & EVNTDT <= STARTDT + 30 ~ 0L,
      DSDECOD == 'LOST TO FOLLOW-UP'          ~ 2L,
      .default                                = 1L),
    ADT      = case_when(
      CNSR == 0L ~ EVNTDT,
      CNSR == 2L ~ pmin(DISPDT, STARTDT + 30),
      .default   = STARTDT + 30),
    AVAL     = as.numeric(ADT - STARTDT),
    EVNTDESC = case_when(
      CNSR == 0L & !is.na(READMDT) & EVNTDT == READMDT ~ 'READMISSION',
      CNSR == 0L ~ 'DEATH',
      CNSR == 2L ~ 'LOST TO FOLLOW-UP',
      .default   = 'NO EVENT BY DAY 30')
  ) |>
  select(STUDYID, USUBJID, TRT01P, TRT01A, ITTFL, PARAMCD, PARAM,
         STARTDT, ADT, AVAL, CNSR, EVNTDESC)

stopifnot(nrow(adtte) == nrow(adsl),
          all(adtte$AVAL >= 0 & adtte$AVAL <= 30))
count(adtte, CNSR, EVNTDESC)
#>   CNSR           EVNTDESC    n
#> 1    0              DEATH   79
#> 2    0        READMISSION  429
#> 3    1 NO EVENT BY DAY 30 1761
#> 4    2  LOST TO FOLLOW-UP  163

AVAL here is ADT - STARTDT. Many sponsors add one day so that an event on the start date has AVAL = 1. Either is defensible, and the specification states which.2

2 The SAP and the ADaM specification should agree on this and on the censoring date for subjects lost to follow-up (last contact, here; some plans use the last date of known status). Neither choice changes the estimand; both change AVAL.

TipVerification

Re-derive the event count and the event days from the raw outcome file, which never passed through SDTM, and compare.

raw_events <- read_hf('outcomes.csv') |>
  filter(event_30d == 1) |>
  transmute(USUBJID = paste('HFHOME', patient_id, sep = '-'),
            days = days_to_event)
adtte_events <- adtte |>
  filter(CNSR == 0) |>
  select(USUBJID, days = AVAL)

stopifnot(
  nrow(raw_events) == nrow(adtte_events),
  isTRUE(all.equal(arrange(raw_events, USUBJID),
                   arrange(adtte_events, USUBJID),
                   check.attributes = FALSE))
)
nrow(adtte_events)
#> [1] 508

Two derivations from different sources that agree subject by subject are evidence that the censoring logic is right. A count that agrees with days that do not would point at the date logic.

28.4.3 Analyze from ADTTE

The analysis filters on the ITT flag and converts the censoring code once, at the boundary, with CNSR == 0. HF-HOME’s ADTTE contains CNSR = 2, so 1 - CNSR would drop the subjects lost to follow-up.

analysis <- adtte |>
  filter(ITTFL == 'Y', PARAMCD == 'RDTH30')

fit <- survfit(Surv(AVAL, CNSR == 0) ~ TRT01P, data = analysis)
summary(fit, times = 30)
#> Call: survfit(formula = Surv(AVAL, CNSR == 0) ~ TRT01P, data = analysis)
#> 
#>                 TRT01P=Usual care 
#>         time       n.risk      n.event     survival      std.err lower 95% CI 
#>      30.0000     871.0000     268.0000       0.7650       0.0126       0.7408 
#> upper 95% CI 
#>       0.7901 
#> 
#>                 TRT01P=Home health 
#>         time       n.risk      n.event     survival      std.err lower 95% CI 
#>      30.0000     912.0000     240.0000       0.7951       0.0118       0.7723 
#> upper 95% CI 
#>       0.8186

cox <- coxph(Surv(AVAL, CNSR == 0) ~ TRT01P, data = analysis)
hr <- summary(cox)$conf.int
hr
#>                   exp(coef) exp(-coef) lower .95 upper .95
#> TRT01PHome health 0.8517262   1.174086 0.7155703  1.013789
stopifnot(cox$n == nrow(analysis))

The hazard ratio for home health against usual care is 0.85 (95% confidence interval 0.72 to 1.01). The interval includes 1, so this supportive analysis, like the primary one, is inconclusive. It does not show that home health reduces early readmission or death. Nor does it rule out a reduction of the size the trial was designed to detect. The stopifnot() confirms that no subject was dropped on the way into the model. Figure 28.3 shows the cumulative incidence by arm, with the risk table that regulatory reviewers expect beneath the curve.

library(survminer)

ggsurvplot(fit, data = analysis,
           fun          = 'event',
           conf.int     = TRUE,
           risk.table   = TRUE,
           break.time.by = 10,
           xlab         = 'Days from randomization',
           ylab         = 'Cumulative incidence',
           legend.title = 'Arm',
           legend.labs  = arms,
           ggtheme      = theme_minimal())
Two rising step curves of cumulative incidence over 30 days, one per randomized arm, with overlapping shaded confidence bands; the usual-care curve lies slightly above the home-health curve. A risk table beneath the axis lists the number of subjects still at risk in each arm at days 0, 10, 20, and 30.
Figure 28.3: Cumulative incidence of readmission or death within 30 days of randomization, by randomized arm, from the HF-HOME ADTTE (ITT set). Shaded bands are pointwise 95% confidence intervals; the table beneath gives the number still at risk.

The row granularity changed at every step, and you have to track it. dm has one row per subject, ex one per home-health visit, ds two per subject, and ho one per readmission. adsl returns to one per subject, and adtte has one per subject per parameter. The declared relationship = on every join and the stopifnot() after each derivation are the minimum.

28.4.4 Exercises

  1. Stack a second parameter into ADTTE: time to death within 30 days (PARAMCD = 'DTH30'), censored at day 30 or at last contact as before. Verify that the stacked dataset has two rows per subject and that its number of DTH30 events equals the number of DEATH records in DS.
adtte_dth <- adsl |>
  select(STUDYID, USUBJID, TRT01P, TRT01A, ITTFL, RANDDT) |>
  left_join(disposition, by = 'USUBJID',
            relationship = 'one-to-one', unmatched = 'error') |>
  left_join(deaths, by = 'USUBJID', relationship = 'one-to-one') |>
  mutate(
    PARAMCD  = 'DTH30',
    PARAM    = 'Time to death within 30 days (days)',
    STARTDT  = RANDDT,
    CNSR     = case_when(
      !is.na(DTHDT)                  ~ 0L,
      DSDECOD == 'LOST TO FOLLOW-UP' ~ 2L,
      .default                       = 1L),
    ADT      = case_when(
      CNSR == 0L ~ DTHDT,
      CNSR == 2L ~ pmin(DISPDT, STARTDT + 30),
      .default   = STARTDT + 30),
    AVAL     = as.numeric(ADT - STARTDT),
    EVNTDESC = case_when(
      CNSR == 0L ~ 'DEATH',
      CNSR == 2L ~ 'LOST TO FOLLOW-UP',
      .default   = 'NO EVENT BY DAY 30')
  ) |>
  select(all_of(names(adtte)))

adtte2 <- bind_rows(adtte, adtte_dth)
stopifnot(
  nrow(adtte2) == 2 * nrow(adsl),
  all(count(adtte2, USUBJID)$n == 2),
  sum(adtte2$PARAMCD == 'DTH30' & adtte2$CNSR == 0) ==
    sum(ds$DSDECOD == 'DEATH')
)
count(adtte2, PARAMCD, CNSR)
#>   PARAMCD CNSR    n
#> 1   DTH30    0  111
#> 2   DTH30    1 2158
#> 3   DTH30    2  163
#> 4  RDTH30    0  508
#> 5  RDTH30    1 1761
#> 6  RDTH30    2  163

BDS datasets grow downward. A second endpoint is more rows with a different PARAMCD, never a second AVAL column. select(all_of(names(adtte))) keeps the two blocks stackable. bind_rows() of frames with different columns succeeds and fills the gaps with NA. That is how a BDS dataset quietly acquires columns that apply to one parameter only. Deaths are a subset of the composite events, so the DTH30 event count must be smaller than the RDTH30 count. Deaths after a readmission are events here and not there.

  1. Build a minimal BDS ADLB for NT-proBNP (N-terminal pro-B-type natriuretic peptide) from labs.csv and visits.csv: one row per subject per analysis visit (AVISIT of 'BASELINE' for discharge and 'DAY 30' for the day-30 clinic), with AVAL, ABLFL, BASE, and CHG. Restrict it to randomized subjects, and assert one row per subject and visit.
visit_map <- read_hf('visits.csv') |>
  filter(visit_type %in% c('discharge', 'clinic_day30')) |>
  select(visit_id, visit_type)

adlb <- read_hf('labs.csv') |>
  filter(test_code == 'NTPROBNP') |>
  distinct(patient_id, visit_id, test_code, value) |>
  inner_join(visit_map, by = 'visit_id',
             relationship = 'one-to-one') |>
  transmute(USUBJID = paste('HFHOME', patient_id, sep = '-'),
            PARAMCD = 'NTPROBNP',
            AVISIT  = if_else(visit_type == 'discharge',
                              'BASELINE', 'DAY 30'),
            AVAL    = value) |>
  semi_join(adsl, by = 'USUBJID') |>
  group_by(USUBJID) |>
  mutate(ABLFL = if_else(AVISIT == 'BASELINE', 'Y', NA_character_),
         BASE  = AVAL[AVISIT == 'BASELINE'][1],
         CHG   = if_else(AVISIT == 'BASELINE', NA_real_,
                         AVAL - BASE)) |>
  ungroup()

stopifnot(!anyDuplicated(adlb[c('USUBJID', 'AVISIT')]),
          all(adlb$USUBJID %in% adsl$USUBJID))
count(adlb, AVISIT)
#> # A tibble: 2 × 2
#>   AVISIT       n
#>   <chr>    <int>
#> 1 BASELINE  2432
#> 2 DAY 30    1648

Two planted defects meet this derivation. The exact duplicate of one discharge NT-proBNP row is removed by distinct() on all columns. This is safe only because the rows are identical, and the assertion after it would catch a conflicting pair. The orphan patient 2433 has labs but no visit record, so the inner join to visits already drops it. The semi_join() to ADSL states the rule that guarantees it, because ADaM contains randomized subjects only. ABLFL is 'Y' or missing, never 'N', as for every ADaM flag of this kind.

Question. Why does the HF-HOME ADTTE start the clock at RANDDT rather than TRTSDT?

Answer. The estimand is defined for every randomized subject from randomization. TRTSDT (the first home-health visit) is missing for most usual-care subjects and comes after randomization for the rest. Starting at TRTSDT would drop or shift exactly the subjects whose care differed from assignment. The comparison would then no longer be between randomized groups.

28.5 Industry practice: tables, validation, double programming

28.5.1 The pharmaverse

Until the late 2010s, almost all ADaM work in industry was done in SAS (Chapter 29). The admiral package (Mancini et al., 2026) first reached CRAN (the Comprehensive R Archive Network) in about 2022. Since then a cross-company collaboration called the pharmaverse has produced R packages for each step of the pipeline. These include admiral for ADaM derivations, metacore and metatools to read and apply specifications, and xportr to write the SAS transport (XPT) files the FDA requires. At a sponsor that has adopted R, expect these in production.

28.5.2 Tables, listings, and figures

Every table in a CSR is built from ADaM, and several R packages build them. gtsummary (Sjoberg et al., 2021) is the general one. The demographics table below is computed from ADSL.

library(gtsummary)

adsl |>
  filter(ITTFL == 'Y') |>
  select(TRT01P, AGE, AGEGR1, SEX) |>
  tbl_summary(by = TRT01P,
              label = list(AGE ~ 'Age, years',
                           AGEGR1 ~ 'Age group', SEX ~ 'Sex')) |>
  add_overall()
Characteristic Overall
N = 2,4321
Usual care
N = 1,2161
Home health
N = 1,2161
Age, years 72 (64, 79) 72 (64, 79) 72 (64, 79)
Age group


    <65 634 (26%) 317 (26%) 317 (26%)
    >=65 1,798 (74%) 899 (74%) 899 (74%)
Sex


    F 1,066 (44%) 553 (45%) 513 (42%)
    M 1,366 (56%) 663 (55%) 703 (58%)
1 Median (Q1, Q3); n (%)

Two families are built for regulatory output. rtables, with the analysis functions of tern, describes a table as a layout that is then applied to the data. Tplyr builds a table from layers of counts and descriptive statistics. Neither is installed in this book’s environment, so the code is display-only and unverified here:

library(rtables)
library(tern)
basic_table() |>
  split_cols_by('TRT01P') |>
  add_overall_col('All') |>
  analyze_vars(c('AGE', 'SEX')) |>
  build_table(adsl)

library(Tplyr)
tplyr_table(adsl, TRT01P) |>
  add_layer(group_desc(AGE)) |>
  add_layer(group_count(SEX)) |>
  build()

28.5.3 Publication and submission tables: shells and mocks

The gtsummary demographics table above was built in one tbl_summary() call against whichever columns of ADSL seemed useful to look at. That is appropriate for exploration, and for the many tables a biostatistician builds while checking a dataset or drafting a manuscript. The tables of a clinical study report are built differently. The software can be the same. What differs is what exists before anyone writes code.

A CSR table, listing, or figure (collectively, a TLF) is built against a shell. The shell specifies the table’s title, its population, every row and row group, every column and column header, the footnotes, the decimal rules, and often the exact page layout. The biostatistician and the lead statistical programmer agree on it and sign it off before the database is locked. The shell is part of the TLF specification that accompanies the SAP. It is numbered so that every reviewer can find ‘Table 14.2.1’ and know in advance what it will contain and what it will not. That holds from the sponsor’s own QC programmer to an FDA statistical reviewer reading the final CSR. Nothing about the shell depends on what the data turn out to show. Suppose a reviewer sees the primary efficacy table laid out one way in the SAP and a different way in the CSR. That reviewer has reason to ask whether the second table was shaped by a look at the results. This is the appearance a pre-specified shell exists to avoid.

A mock is the shell filled with placeholder values. It is typeset and reviewed before the data exist or before they are unblinded. The review confirms that the layout reads correctly, that long row labels do not wrap badly, and that the table fits a printed page the way the shell’s author intended. A mock for HF-HOME’s composite-endpoint table might look like this, with every number a placeholder:

Table 14.2.1  Supportive Analysis: Time to 30-Day Readmission or Death
              (Intention-to-Treat Population)

                                Usual care     Home health
                                (N=xxx)        (N=xxx)
  Subjects with event, n (%)    xx (xx.x%)     xx (xx.x%)
  Hazard ratio (95% CI)                    x.xx (x.xx, x.xx)
  Log-rank p-value                              x.xxx

Program: adtte.R / tlf-14-2-1.R    Output generated: ddMONyyyy hh:mm

Once the shell and mock are signed off, the programmer implements the layout in code. From then on the layout decides what appears, not the programmer’s judgment at table-building time. In tern, the shell becomes a rtables layout. The column split, the row-generating functions, and their order are fixed once. The same layout code is then applied to whatever data a given run provides. In Tplyr, the shell becomes a sequence of layers, each one a row group (group_desc() for a continuous summary, group_count() for a categorical one). The layers are added in the order the shell specifies. Neither package lets the real numbers rearrange the table. A hazard ratio of 1.3 and a hazard ratio of 0.6 print into the same cell, because the cell was fixed before either number existed. Below is a sketch of HF-HOME’s table in tern. It is display-only because the package is not installed in this book’s environment:

library(rtables)
library(tern)

lyt <- basic_table(
    title = 'Table 14.2.1  Supportive Analysis: Time to 30-Day
             Readmission or Death (Intention-to-Treat Population)',
    subtitles = 'Cox proportional hazards model, usual care as
                 reference'
  ) |>
  split_cols_by('TRT01P') |>
  add_colcounts() |>
  analyze_vars('CNSR', afun = s_proportion,
               .stats = 'n_prop') |>
  summarize_coxreg(variables = list(tte = 'AVAL', is_event = 'event'),
                    control = control_coxreg())

build_table(lyt, adtte)

The shell this code implements is identical, row for row, to the mock above. Between a dry run on placeholder data and the locked-data run, only the numbers the layout computes change. The rows and columns that appear do not. This is also why a shell is reviewed so early. Consider a row the SAP’s analysis does not support, or a row the shell omits that the SAP requires. Either is a cheap fix before any code exists. It is an expensive one once a locked dataset’s TLFs are already being QC’d against the shell.

Two further conventions follow from the shell existing at all. First, the exact column structure is part of the shell and is never a programmer’s choice at build time. This includes column order, the definition of any ‘Total’ or ‘Overall’ column, and whether a column reports counts, percentages, or both. Two programmers building the same shell from the same data must produce column-identical tables. This holds even before double programming compares the numbers inside them. Second, the shell commits to a population and an analysis before the shell’s author has seen any outcome data. This is a weaker but related form of the pre-specification this book has argued for throughout. An estimand and an analysis plan fixed before results exist cannot be reshaped by what the results turn out to be (Section 26.2).

The same shell discipline governs listings and figures, the other two letters of ‘TLF’. A listing has a shell too. It specifies exactly which SDTM or ADaM variables appear, in what order, and sorted by what key. It also states the footnotes about truncation or suppression of confidential fields. A figure’s shell specifies the plot type, axes, legend, and any reference lines. This is the way ggsurvplot()’s arguments above fix the axis labels and the arm legend before any data are plotted. Consider a Kaplan-Meier figure built during exploratory analysis and a CSR figure built from the same fit object. The two then share their statistics and differ only in presentation. This holds provided the shell for the CSR figure’s axes and legend was agreed in advance. The code that builds it, display-only or not, must also implement that shell exactly.

TLFs are QC’d the same way ADaM datasets are. A second programmer independently reproduces the numbers inside the shell, often with a different package or a simpler ad hoc script. The programmer then compares them to the primary output, cell by cell. This is the same discipline as the diffdf comparison in Section 28.5, applied to a table instead of a dataset. A gtsummary table built quickly from the locked data is a reasonable independent check on a tern table’s numbers. The reason is that the two packages compute the summary statistics by different code paths from the same shell’s row and column definitions. Agreement between them is evidence about the numbers. Agreement between two runs of the same tern layout is evidence about nothing new. The reason is the same one that made a second run of identical code add nothing to the ADaM double-programming check earlier in this chapter.

TipVerification

Before trusting a built TLF, check it against its own shell line by line: same title text, same column headers in the same order, same row labels in the same order, same footnotes. A table that computes the right numbers in the wrong shell is still a finding to fix, because the shell is itself a reviewed, agreed artifact.

Question. A programmer builds the primary efficacy table, notices that a ‘Difference in proportions’ row would make the comparison clearer, and adds it. The added row is correctly computed. What is wrong?

Answer. The row was not in the shell the biostatistician and the lead programmer signed off on. Adding it, even correctly, changes the table that reaches the SAP’s reviewers and ultimately FDA. That table now differs from the one specified and agreed before the data were seen. This is exactly the appearance of data-driven table-building that a pre-specified shell exists to rule out. The right process is to propose the row as a shell change, get it reviewed and signed off, and only then implement it. A good idea discovered while coding is still a specification change, not a coding decision.

28.5.4 Exercises

  1. Sketch a shell, as a plain-text mock like the one above, for a TLF reporting HF-HOME’s NT-proBNP change from baseline to day 30 (ADLB, from the worked example’s exercise 3) by randomized arm. Decide, and state explicitly, what the shell’s footnotes should disclose about missing day-30 values, since Section 28.4’s ADLB has no row for a subject who lacks a day-30 measurement.

A minimal shell:

Table 14.x.x  Change from Baseline in NT-proBNP to Day 30
              (Intention-to-Treat Population)

                              Usual care      Home health
                              (N=xxx)         (N=xxx)
  Baseline, mean (SD)         xxx.x (xx.xx)   xxx.x (xx.xx)
  Day 30, mean (SD)           xxx.x (xx.xx)   xxx.x (xx.xx)
  Change, mean (SD)           xxx.x (xx.xx)   xxx.x (xx.xx)
  n with day-30 value         xxx             xxx

Footnote: Subjects without a day-30 NT-proBNP measurement are excluded
from the day-30 and change rows; the denominator for each row is
stated as n, not N, to make this explicit.

The main decision is the footnote. ADLB as built in the worked example has one row per subject per visit actually measured. A subject missing the day-30 draw therefore contributes no day-30 row and no CHG value, rather than an explicit missing-data code. Suppose a shell reports only N in the header, without an n row for each statistic. A reader could then assume the change row was computed on every randomized subject, which it was not. The footnote is the shell’s way of committing in advance to disclose that gap. It does not leave a programmer to decide, after seeing how much data is missing, whether the gap is worth mentioning.

28.5.5 R in submissions and validated packages

R is accepted in submissions. The R Consortium’s R Submissions Working Group has run pilot submissions to FDA built in R. Pilot 1, four TLFs, received FDA’s final review response in March 2022. Pilot 2, a Shiny application, received its response in September 2023. Pilot 3, ADaM datasets and TLFs built in R, received its final response letter in August 2024. Pilot 4, the Shiny application delivered through WebAssembly and through a container, received FDA’s review letter in May 2026.3 These are test submissions, not drug approvals. What a sponsor must show is that the software it relies on is fit for purpose. The R Validation Hub, another R Consortium working group, publishes a risk-based approach to that question. Its riskmetric package scores a package on documentation, testing, maintenance, and use (display-only; not installed here):

3 As of 2026-10. Dates are from the working group’s pilot pages (rconsortium.github.io/submissions-wg), the pilot repositories on GitHub (github.com/RConsortium), and R Consortium announcements of August 2024 (Pilot 3) and May 2026 (Pilot 4). Pilot 5 replaces XPT with Dataset-JSON: it was submitted to FDA in fall 2025, FDA requested minor rework, and the team resubmitted in January 2026, with completion hoped for spring 2026. Check the working group’s pilot pages for the current status before citing a result.

library(riskmetric)
pkg_ref('survival') |>
  pkg_assess() |>
  pkg_score()

As of this writing, riskmetric is maintenance-only. The Validation Hub has moved its development effort to a successor, val.meter, and directs feature requests there. Bug reports for riskmetric itself are still accepted. Check both packages’ status before adopting either.

28.5.6 Double programming

The standard validation of an ADaM dataset or a table in industry is double programming. A second programmer derives the same output independently from the specification, without reading the first programmer’s code. The two outputs are then compared value by value. Any difference is investigated until both agree or the specification is clarified. The diffdf package is the usual comparison tool in R (display-only; not installed here):

diffdf::diffdf(base = adtte, compare = adtte_qc, keys = 'USUBJID')

The chunk below is the same idea with tools already loaded: an independent derivation of the whole ADTTE, from the raw CSV files rather than from SDTM, compared row by row.

last_contact <- read_hf('visits.csv') |>
  group_by(patient_id) |>
  summarize(last_day = max(visit_day), .groups = 'drop')

adtte_qc <- read_hf('outcomes.csv') |>
  left_join(last_contact, by = 'patient_id',
            relationship = 'one-to-one') |>
  transmute(
    USUBJID = paste('HFHOME', patient_id, sep = '-'),
    AVAL = case_when(event_30d == 1 ~ days_to_event,
                     !ascertained   ~ pmin(last_day, 30),
                     .default       = 30),
    CNSR = case_when(event_30d == 1 ~ 0L,
                     !ascertained   ~ 2L,
                     .default       = 1L)
  ) |>
  arrange(USUBJID)

primary <- adtte |>
  select(USUBJID, AVAL, CNSR) |>
  arrange(USUBJID)

mismatches <- primary |>
  inner_join(adtte_qc, by = 'USUBJID', suffix = c('', '_qc'),
             relationship = 'one-to-one', unmatched = 'error') |>
  filter(AVAL != AVAL_qc | CNSR != CNSR_qc)
stopifnot(nrow(mismatches) == 0)
nrow(mismatches)
#> [1] 0

The QC derivation shares no code and no intermediate dataset with the primary one. It uses visits.csv for the last contact where the primary used the DS date. It uses the outcome flags where the primary used HO and DS. Agreement on all 2432 subjects is evidence about the derivation. A second run of the same code would be evidence about nothing.

ImportantLLM prompt

An independent re-derivation by a model is the AI analogue of double programming, and it has the same rule: the second derivation must not see the first.

Context. I am validating an ADaM ADTTE dataset. The specification is below: [the ADTTE rows of the ADaM specification, with each variable’s source and derivation]. The source files are described by these variable lists and types: [column names and types of outcomes.csv and visits.csv, and three synthetic rows of each].

Constraints. Write an R function that derives USUBJID, AVAL, and CNSR from the two source files using dplyr only. Use CNSR = 0 for the event and the positive codes in the specification for censoring. Declare relationship = on every join. Do not ask for, and do not use, any existing derivation code.

Criteria. List every assumption you make where the specification is silent (the censoring date for a subject lost to follow-up, the treatment of a death after a readmission). I will compare your output to the primary dataset subject by subject.

Failure mode. A model shown the primary code reproduces its errors, which defeats the comparison. A model not shown the specification invents a censoring rule, often CNSR = 1 for every censored subject. Check. Run its function on the real files inside your environment and compare with the mismatches join above, which must return no rows. Then investigate every assumption it listed against the SAP. Real SDTM and ADaM are individual patient data and the sponsor’s confidential information. Send the specification and synthetic rows, never the datasets (Section 12.3).

Question. A programmer validates an ADTTE by re-running the primary program on a second machine and comparing outputs. They agree exactly. What has been shown?

Answer. That the program is deterministic, not that it is correct. Double programming works because the second derivation is independent. It is different code, written from the specification by someone who has not seen the first. A shared misreading is therefore unlikely. A misread censoring rule survives any number of re-runs of the same code.

28.6 Regulated-industry computing

Double programming (Section 28.5) is evidence about one dataset. Two further layers of rule govern the computing environment that produces every dataset and table in a submission. The first is a US regulation on what counts as a trustworthy electronic record. The second is an international guideline on how a sponsor manages the risk that its computerized systems introduce into a trial’s data. R and its packages are among those systems. A biostatistician who only ever sees SAS or R code will still meet both. The usual point of contact is a sponsor’s own standard operating procedures (SOPs), which exist to implement them.

28.6.1 21 CFR Part 11: electronic records and electronic signatures

Title 21, Part 11 of the US Code of Federal Regulations (US Food and Drug Administration, 1997) sets the conditions under which the FDA accepts electronic records and electronic signatures as equivalent to paper records and handwritten signatures. It does not, by itself, require that any particular record be kept. Rather, it applies once a sponsor chooses to keep a required record in electronic form. The requirement itself comes from some other FDA regulation (the ‘predicate rule’). The clinical data underlying a new drug application are one instance. Three obligations matter most to a statistician or programmer who works inside a system built to satisfy Part 11.

Audit trails. A system covered by Part 11 must generate a computer-generated, time-stamped audit trail. The trail records who created, modified, or deleted a record, and when, without obscuring the earlier entries. For an ADaM dataset this means the specification, the programs, and the dataset itself typically live in a validated system that logs every change. Examples are a clinical trial management system or a controlled document and code repository. They do not live in a shared folder where a file can be overwritten without a trace. A git history is a step in this direction but is not, by itself, a Part 11 audit trail. Part 11 requires the trail to be part of a controlled, access-restricted system with its own retention guarantees. Plain version control does not provide that on its own.

Access controls. Only authorized individuals may operate the system. Each is identified by a unique credential, with access rights set by role (read-only reviewer, programmer with write access to a particular study, and so on). Suppose a programmer shares a login with a colleague, even briefly. That breaks the link between the audit trail’s record of ‘who’ and the person who actually acted. This link is the specific guarantee Part 11 is built to provide.

Record retention. Records kept to satisfy a predicate rule must remain retrievable, and reproducible in a readable form, for the retention period that rule specifies. That period can run well beyond a study’s active life. It can also outlast the working life of the software that produced the record. A sponsor’s SOPs for archiving an R environment, down to the package versions a study used, exist to keep that promise when R itself, or a package on CRAN, has moved on.

Electronic signatures. A signature may be required for sign-off on a SAP, approval of a locked dataset, or release of a CSR. In each case Part 11 requires that the signature be uniquely linked to one individual, never reused or reassigned to someone else. It must be applied only by its genuine owner, typically through a two-component mechanism such as a credential plus a password or token. Consider a biostatistician’s electronic approval of an ADaM specification inside a controlled document system. It is the Part 11 analogue of a wet signature on a paper memo. It carries the same legal weight once the system itself meets the regulation.

Part 11 is US-specific and narrower than it sounds. It is a rule about what makes an electronic record acceptable in place of a paper one. It is not a general statement of good computing practice. The broader question of how much validation and control a given computerized system needs is addressed by ICH guidance.

These obligations reach a biostatistician who never touches a validated system directly. The FDA inspects study sites and sponsors under its Bioresearch Monitoring (BIMO) program. Such an inspection can and does ask to see the audit trail behind a reported result. That is, it asks who changed a value in the clinical database, when, and under whose approval a locked dataset was released for analysis. Consider a derivation that exists only as an interactive session typed at a console, with no record of who ran it or when. Neither Part 11 nor a sponsor’s SOPs will accept it as the basis for a submitted result, however correct its numbers turn out to be. The record of how a result was produced is treated as part of the evidence for it.

28.6.2 ICH E6(R3): data governance and computerized systems

ICH E6 is the Good Clinical Practice (GCP) guideline. It has been revised twice since its original 1996 text. The third revision, E6(R3), reached ICH Step 4 on 6 January 2025. Step 4 is the point at which the ICH Assembly adopts the final text and recommends it to its member regulatory authorities. The European Medicines Agency’s Step 5 adoption of the principles and Annex 1 took effect on 23 July 2025 (International Council for Harmonisation, 2025). As of this writing, Annex 2 of E6(R3) is on a later timetable; check the ICH database for the current status before citing a date for it.

E6(R3)’s most consequential change for a statistician or programmer is a shift to risk-based quality management, applied explicitly to computerized systems. The guideline does not prescribe a fixed checklist for every system regardless of what it does. Instead, it asks the sponsor to identify what could go wrong with a given system’s data. Examples are a wrong randomization code, a corrupted export, or an unvalidated calculation silently feeding a reported result. The sponsor then scales the system’s validation, access control, and documentation to the size and likelihood of that risk. A sponsor’s own patient randomization system warrants more scrutiny than a read-only reporting dashboard built on already-locked data. E6(R3) asks the sponsor to be able to show that it reasoned this way. It is not enough to show that one uniform procedure was applied to both.

Regulators and industry commonly summarize the resulting data-integrity expectations with the mnemonic ALCOA+: data should be attributable, legible, contemporaneous, original, and accurate (the original ALCOA), and, as elaborated since, complete, consistent, enduring, and available. E6(R3) does not use this acronym in its own text. However, its data governance expectations align with it. These include traceable changes, protection against unauthorized alteration, and systems fit for their intended use. The mnemonic is a convenient checklist against which to read a sponsor’s data-management SOPs.

Part 11 and E6(R3) are not redundant. Part 11 is a US rule about when an electronic record substitutes for a paper one. E6(R3) is an international guideline about how a sponsor manages the quality of a clinical trial. The integrity of its computerized systems is one part of that. A sponsor operating a Part 11-compliant system has satisfied one specific US requirement. It has not, by that fact alone, satisfied E6(R3)’s broader expectation that the system’s validation effort was scaled to its risk and documented as such. A global sponsor running a multinational trial needs to show both.

28.6.3 Validating R packages for regulated use

Under a risk-based framework, R itself, and every package an analysis depends on, is a computerized system whose risk to the trial’s data must be assessed and, where warranted, mitigated. Sponsors that use R do not re-derive that assessment from first principles for every study. The R Validation Hub was introduced in Section 28.5 for riskmetric and its successor val.meter. It offers the industry a shared approach for R. A package is assessed once per environment on its test coverage, its maintenance activity, the stability of its exported interface, and the size of its user base. That documented assessment is then reused across the studies that run in the same validated environment. There is no need to re-justify the choice of survival::coxph() in every SAP.

Double programming (Section 28.5) is per-analysis evidence: it shows that this dataset’s derivation, run against this study’s source data, reproduces independently. Package risk assessment is per-environment evidence: it shows that the software both derivations relied on behaves as its documentation claims, before either derivation is attempted. Neither substitutes for the other. A correctly validated copy of survival run with a transposed censoring code still produces the wrong curve (Section 28.3). Conversely, consider a careful, independently double-programmed derivation built on a package that silently drops NA rows from a join. It is still wrong, and double programming alone will not surface the reason. Both programmers may make the same assumption about the package. A sponsor’s R validation SOP and the study team’s double programming plan are two different controls. They address two different layers of risk, and both are expected.

The practical effect for a programmer joining such a sponsor is a validated environment rather than a free choice of package versions. That is, an renv.lock (Chapter 9) is pinned to a specific, already-assessed set of package versions. It is changed only through a controlled process that re-triggers the relevant risk assessment. It is not upgraded package by package whenever a newer CRAN release appears. This can feel like friction to someone used to running renv::update() freely. However, it is the same logic as SDTM’s immutability (Section 28.1). Suppose a result is traced to a package version that the validation record no longer describes. The computational basis of that result can no longer be reconstructed. This is precisely the failure that E6(R3)’s risk-based framework and Part 11’s retention requirement are both written to prevent.

28.6.4 eSubmission mechanics: eCTD and pkglite

The datasets, programs, and Define-XML discussed earlier in this chapter (Section 28.1) reach FDA assembled into the electronic Common Technical Document (eCTD). The eCTD is the standardized, XML-backboned folder structure that ICH regions require for a regulatory submission. At a high level, an eCTD submission is organized into five numbered modules. Module 1 holds region-specific administrative information. Modules 2 through 4 hold the Common Technical Document summaries, quality, and nonclinical information. Module 5 holds the clinical study reports. For each study it includes the datasets, the ADaM and SDTM metadata (Define-XML), and the analysis programs, in a defined subfolder structure. A submission is built incrementally over a product’s life cycle. Each later submission adds or replaces eCTD ‘leaves’ rather than restarting the folder from scratch. This is part of why the ADRG and SDRG (Table 28.1) exist as narrative guides to what changed and why. Within Module 5, a study’s materials sit under a folder keyed to its study identifier. Conventional subfolders separate the datasets themselves from the programs that produced them. Most sponsors have converged on the names datasets/ and analysis/programs/, though the eCTD standard itself does not mandate these exact names. Define-XML lives beside the datasets it describes. A reviewer opening the study folder can therefore move from a variable’s entry in Define-XML to the dataset that contains it. Where provided, the reviewer can also move on to the program that derived it, without leaving the submission’s own folder structure.

The eCTD’s file-format rules have historically been a poor fit for R source code. FDA’s eCTD gateway accepted a restricted list of file types. A source R package, with its nested R/, man/, tests/, and data/ subdirectories, did not sit comfortably inside a single accepted leaf. pkglite (Zhang et al., 2026) was built at Merck to solve exactly this problem. It collates a package’s source files into one or a small number of plain-text files, in a documented, lossless format. These files pack back into the original package structure with a single call. Consider a programmer preparing an R package for inclusion in an eCTD submission (display-only; not installed here). The programmer collates the package using the file_ectd() specification, which selects the files an eCTD submission expects. The result is then packed into a single text file:

library(pkglite)

collate(pkg = 'path/to/mypackage', file_ectd()) |>
  pack(output = 'mypackage.txt')

A reviewer, or the original team at a later submission, restores the package from that text file with unpack(). As of this writing, the R Consortium reports that FDA has since expanded the file formats its eCTD portal accepts for R. A sponsor can therefore in some cases submit a non-public R package directly as a .zip archive. However, pkglite’s plain-text, line-by-line output remains useful on its own terms, independent of what the gateway accepts. A text file is readable, diffable, and version-controllable in a way a zipped binary archive is not. That matters for a reviewer trying to see what changed between two submitted versions of a package.

WarningPitfall

Treating Part 11 compliance as sufficient for a computerized system’s regulatory standing. A system can generate a flawless, tamper-evident audit trail and still be running an unvalidated, undocumented R package whose output no one has assessed for risk. Part 11 governs the record, not the software that produced it. Satisfying one says nothing about having satisfied the other. A sponsor’s own validation SOPs, not Part 11 itself, are what close that gap.

28.6.5 Exercises

  1. HF-HOME’s ADTTE derivation in this chapter relies on dplyr and survival. Using the risk factors the R Validation Hub’s approach considers (test coverage, maintenance activity, interface stability, and size of the user base, as introduced in Section 28.5), write two or three sentences arguing which of the two packages likely carries the lower risk to a submission, and what evidence you would want to see before accepting that assessment.

What follows is a plausible argument, not a settled fact. survival has shipped with base R’s recommended package set for decades. It has an exceptionally large user base and changes its exported interface rarely. All of these argue for lower risk under the Hub’s framework. However, the argument is only as good as its evidence. The right next step is to check the two packages’ versions actually pinned in the study’s renv.lock. For those versions we would check their CRAN check status, their last release date, and their test coverage (for instance with covr). A riskmetric or val.meter run (Section 28.5) is built to summarize exactly this, rather than leaving it to intuition.

  1. A sponsor’s SOP requires that every ADaM program be reviewed and electronically approved before the dataset it produces is released for TLF generation. List the Part 11 obligation that this approval step satisfies, and the ICH E6(R3) obligation (distinct from Part
    1. that justifies requiring the review in the first place.

The electronic approval itself, if it uniquely identifies the approver and cannot be reassigned or reused by someone else, satisfies Part 11’s electronic-signature requirement. The requirement to review the program before release is not a Part 11 obligation at all. Part 11 is silent on what a sponsor must review. It speaks only to what makes an electronic record and signature acceptable once a review happens. The review requirement itself follows from E6(R3)’s risk-based quality-management expectation. A program that derives a reported ADaM variable is a computerized-system output with real risk to data integrity. The SOP’s review step is the control a sponsor has chosen to manage that risk before the output is trusted downstream.

28.7 Rules of thumb

  1. Habit 2: raw data are evidence; derived data are a build product. SDTM is never edited; every analytic decision becomes an ADaM variable with a documented derivation.
  2. Habit 6: count before and after every join. One row per subject in ADSL, one per subject per parameter in ADTTE; declare the relationship and assert the counts at every step.
  3. Habit 9: test the statistics, not the shape. A dataset with the right columns can carry the wrong censoring; an independent derivation compared value by value is the test.

28.8 Cumulative practice

  1. Cumulative (uses Chapter 26). Write the ADaM specification for the HF-HOME ADTTE as a table with one row per variable (name, label, type, source, derivation), with the derivations stated so that a second programmer could implement them without this chapter’s code. Then assert in R that every variable in adtte appears in your specification and no specification row is missing from adtte.
  2. On your own work (no key). Install admiral and pharmaverseadam, and compare pharmaverseadam::adsl with the ADSL built here. List the variables that the simplified version lacks, and for each, say which analysis would need it.
adtte_spec <- tribble(
  ~variable,  ~label,                           ~source,
  'STUDYID',  'Study identifier',               'ADSL.STUDYID',
  'USUBJID',  'Unique subject identifier',      'ADSL.USUBJID',
  'TRT01P',   'Planned treatment',              'ADSL.TRT01P',
  'TRT01A',   'Actual treatment',               'ADSL.TRT01A',
  'ITTFL',    'ITT population flag',            'ADSL.ITTFL',
  'PARAMCD',  'Parameter code',                 'Assigned',
  'PARAM',    'Parameter',                      'Assigned',
  'STARTDT',  'Time-to-event origin date',      'ADSL.RANDDT',
  'ADT',      'Analysis date',                  'HO.HOSTDTC, DS.DSSTDTC',
  'AVAL',     'Analysis value (days)',          'ADT - STARTDT',
  'CNSR',     'Censor (0 = event)',             'HO, DS',
  'EVNTDESC', 'Event or censoring description', 'HO, DS'
)
stopifnot(setequal(adtte_spec$variable, names(adtte)))
adtte_spec
#> # A tibble: 12 × 3
#>    variable label                          source                
#>    <chr>    <chr>                          <chr>                 
#>  1 STUDYID  Study identifier               ADSL.STUDYID          
#>  2 USUBJID  Unique subject identifier      ADSL.USUBJID          
#>  3 TRT01P   Planned treatment              ADSL.TRT01P           
#>  4 TRT01A   Actual treatment               ADSL.TRT01A           
#>  5 ITTFL    ITT population flag            ADSL.ITTFL            
#>  6 PARAMCD  Parameter code                 Assigned              
#>  7 PARAM    Parameter                      Assigned              
#>  8 STARTDT  Time-to-event origin date      ADSL.RANDDT           
#>  9 ADT      Analysis date                  HO.HOSTDTC, DS.DSSTDTC
#> 10 AVAL     Analysis value (days)          ADT - STARTDT         
#> 11 CNSR     Censor (0 = event)             HO, DS                
#> 12 EVNTDESC Event or censoring description HO, DS

A full specification adds a type and a derivation column. The derivation for CNSR, for instance, reads ‘0 if the first of HO.HOSTDTC (readmission) or DS.DSSTDTC where DS.DSDECOD = 'DEATH' falls within 30 days of STARTDT; 2 if DS.DSDECOD = 'LOST TO FOLLOW-UP'; otherwise 1’. The setequal() check is a structural check: it confirms that the specification and the dataset name the same variables, not that the derivations agree. The double-programming comparison in Section 28.5 is the check on the values.

28.9 Cheat sheet

Table 28.3: The ADaM variable card.
Variable Dataset Meaning Trap
USUBJID All Unique subject identifier, study-wide Join on it, never on SUBJID alone
TRT01P, TRT01A ADSL Planned and actual treatment, period 1 As-randomized analyses use TRT01P
RANDDT ADSL Randomization date, from DS The origin for ITT time-to-event
TRTSDT, TRTEDT ADSL First and last exposure, from EX Not from the disposition date
ITTFL, FASFL ADSL Randomized, analyzed as randomized The set is not the estimand’s population
SAFFL ADSL Received any treatment, analyzed as treated Not an efficacy set
PPROTFL ADSL No important protocol deviations Selected after randomization
PARAMCD, PARAM BDS Parameter code (8 characters at most) and name New endpoint, new rows
AVAL, AVALC BDS Analysis value, numeric and character Units belong in PARAM
AVISIT, AVISITN BDS Analysis visit, character and numeric Not the collected VISIT
ABLFL, BASE, CHG BDS Baseline flag, baseline value, change Flags are 'Y' or missing, never 'N'
STARTDT, ADT ADTTE Origin and event or censoring date AVAL convention: with or without + 1
CNSR ADTTE 0 = event; positive = censored, by reason Surv(AVAL, CNSR == 0)
EVNTDESC ADTTE Event or censoring description Must agree with CNSR
ANL01FL BDS Record used in an analysis Filter on it when the SAP says so
ASTDT, TRTEMFL OCCDS Analysis start date; treatment-emergent flag Window usually closes at TRTEDT plus a lag; partial dates need a rule

28.10 Further reading

  • CDISC Foundational Standards at cdisc.org/standards/foundational, the authoritative reference for SDTM and ADaM.
  • (Mancini et al., 2026), the admiral package and its vignettes, which derive every common ADaM dataset in R.
  • (US Food and Drug Administration, 2024), the FDA Study Data Technical Conformance Guide, which states what a submission must contain.
  • (International Council for Harmonisation, 2025), the ICH E6(R3) Good Clinical Practice guideline, for its risk-based approach to computerized systems and data governance.

28.11 Prerequisites answers

  1. SDTM (Study Data Tabulation Model) holds the submitted record of the collected clinical data, organized into domains such as DM, AE, LB, and EX. ADaM (Analysis Data Model) holds analysis-ready datasets derived from SDTM. In industry, statistical programmers typically build ADaM against specifications written or reviewed by the biostatistician, who also writes the SAP. SDTM is built by data management or clinical programmers.
  2. A censored observation. CNSR = 0 is the event, and other positive integers may code other censoring reasons. Pass CNSR == 0 to survival::Surv() as the event.
  3. ADSL is the subject-level anchor dataset, with exactly one row per subject: treatment assignment, demographics, baseline covariates, key dates, and population flags. Every other ADaM dataset (ADLB, ADTTE, ADAE) joins back to ADSL by USUBJID and takes treatment and population flags from it.