ADaM Datasets with admiral
SDTM organizes what a trial collected. ADaM organizes the data and metadata used in its analyses, with structures suited to different kinds of records.
| Structure | Unit of a record | Example |
|---|---|---|
| ADSL | One subject | Treatment, population flags and treatment dates |
| Basic Data Structure, BDS | An analysis parameter for a subject, with time and other qualifiers where needed | A laboratory value in ADLB |
| Occurrence Data Structure, OCCDS | An occurrence for a subject | An adverse event in ADAE |
A BDS lab dataset can hold the analysis value in AVAL, its baseline in BASE, and
its change from baseline in CHG. An adverse event needs occurrence information and
analysis flags instead. The CDISC OCCDS guide
covers adverse events, concomitant medications and medical history. BDS is therefore
not the structure of every analysis dataset beyond ADSL.
admiral is the pharmaverse toolbox for those derivations. It was started by Roche
and GSK and is now a wider collaboration, and it is deliberately a programming
library rather than a one-button generator: you state each derivation as a function
call, and the call records the decision. This page uses the independent synthetic
study from the SDTM lesson. It derives selected
ADSL variables and two laboratory parameters, then compares them with reference
values computed by base R in the fixture generator. The generator imports no
admiral functions. The invented observations use CC0 1.0 and support no clinical
conclusion. This is not a complete submission dataset.
library(admiral)library(dplyr)study <- readRDS("/opt/fixtures/pharmaverse/synthetic_study.rds")
# Convert any blank source fields to missing values.dm <- convert_blanks_to_na(study$dm)ex <- convert_blanks_to_na(study$ex)
dim(dm)[1] 36 10ADSL: treatment dates and population flags
Section titled “ADSL: treatment dates and population flags”The planned and actual treatment columns come straight from DM. The work is in the
dates: exposure starts and ends live in EX as character datetimes, possibly partial,
so they are parsed to real datetimes first, then the earliest start and latest end
per subject become TRTSDTM and TRTEDTM. The filter in the merge is the study’s
definition of treated: a dose above zero, or a zero dose whose name says placebo,
which is the explicit exposure rule in this synthetic study.
adsl <- dm %>% select(-DOMAIN) %>% mutate(TRT01P = ARM, TRT01A = ACTARM)
# Parse the exposure datetimes, then take the first start and the last end.ex_ext <- ex %>% derive_vars_dtm(dtc = EXSTDTC, new_vars_prefix = "EXST") %>% derive_vars_dtm(dtc = EXENDTC, new_vars_prefix = "EXEN", time_imputation = "last")
adsl <- adsl %>% derive_vars_merged( dataset_add = ex_ext, filter_add = (EXDOSE > 0 | (EXDOSE == 0 & stringr::str_detect(EXTRT, "PLACEBO"))) & !is.na(EXSTDTM), new_vars = exprs(TRTSDTM = EXSTDTM, TRTSTMF = EXSTTMF), order = exprs(EXSTDTM, EXSEQ), mode = "first", by_vars = exprs(STUDYID, USUBJID) ) %>% derive_vars_merged( dataset_add = ex_ext, filter_add = (EXDOSE > 0 | (EXDOSE == 0 & stringr::str_detect(EXTRT, "PLACEBO"))) & !is.na(EXENDTM), new_vars = exprs(TRTEDTM = EXENDTM, TRTETMF = EXENTMF), order = exprs(EXENDTM, EXSEQ), mode = "last", by_vars = exprs(STUDYID, USUBJID) ) %>% derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>% derive_var_trtdurd()
adsl %>% filter(!is.na(TRTSDT)) %>% select(USUBJID, TRT01A, TRTSDT, TRTEDT, TRTDURD) %>% head(4)# A tibble: 4 × 5 USUBJID TRT01A TRTSDT TRTEDT TRTDURD <chr> <chr> <date> <date> <dbl>1 BTISYN01-001 Active Low 2025-01-10 2025-01-23 142 BTISYN01-002 Placebo 2025-01-10 2025-01-23 143 BTISYN01-003 Active High 2025-01-10 2025-01-23 144 BTISYN01-004 Placebo 2025-01-10 2025-01-23 14The population flag is the
same decision expressed as an existence check: a subject is in the safety population
when at least one treated exposure record exists. The three untreated subjects and three screen failures have no EX records, so
they receive SAFFL = "N".
adsl <- adsl %>% derive_var_merged_exist_flag( dataset_add = ex, by_vars = exprs(STUDYID, USUBJID), new_var = SAFFL, false_value = "N", missing_value = "N", condition = (EXDOSE > 0 | (EXDOSE == 0 & stringr::str_detect(EXTRT, "PLACEBO"))) )
table(adsl$SAFFL) N Y 6 30Check an independent reference
Section titled “Check an independent reference”The fixture generator computes treatment dates with base R and tests explicit cases for treated subjects, an untreated subject, and a screen failure. The comparison below covers every subject and verifies that no subject disappears from the join. These checks do not call the admiral derivations they test.
ref_adsl <- study$ref_adsl
cmp <- adsl %>% select(USUBJID, TRTSDT, TRTEDT, TRTDURD, SAFFL) %>% inner_join( select(ref_adsl, USUBJID, TRTSDT_REF = TRTSDT, TRTEDT_REF = TRTEDT, TRTDURD_REF = TRTDURD, SAFFL_REF = SAFFL), by = "USUBJID" )
stopifnot(nrow(cmp) == nrow(adsl), nrow(cmp) == nrow(ref_adsl))stopifnot(identical(cmp$SAFFL, cmp$SAFFL_REF))stopifnot(isTRUE(all.equal(cmp$TRTSDT, cmp$TRTSDT_REF)))stopifnot(isTRUE(all.equal(cmp$TRTEDT, cmp$TRTEDT_REF)))stopifnot(isTRUE(all.equal(cmp$TRTDURD, cmp$TRTDURD_REF)))cat("subjects compared:", nrow(cmp), "\n")cat("SAFFL differing:", sum(cmp$SAFFL != cmp$SAFFL_REF), "\n")cat("TRTSDT differing:", sum(cmp$TRTSDT != cmp$TRTSDT_REF, na.rm = TRUE) + sum(xor(is.na(cmp$TRTSDT), is.na(cmp$TRTSDT_REF))), "\n")cat("TRTSDT missing in both:", sum(is.na(cmp$TRTSDT) & is.na(cmp$TRTSDT_REF)), "\n")cat("TRTEDT and TRTDURD independent checks: PASS\n")subjects compared: 36SAFFL differing: 0TRTSDT differing: 0TRTSDT missing in both: 6TRTEDT and TRTDURD independent checks: PASSADLB: the BDS skeleton
Section titled “ADLB: the BDS skeleton”This ADLB example adds treatment variables, an analysis date, a parameter code,
and an analysis value to each selected LB record. The study specification maps
cholesterol to PARAMCD = "CHOLES" and retains ALT as the second parameter.
lb <- convert_blanks_to_na(study$lb)
adsl_vars <- exprs(TRTSDT, TRTEDT, TRT01A, TRT01P)
param_lookup <- tibble::tribble( ~LBTESTCD, ~PARAMCD, ~PARAM, "CHOL", "CHOLES", "Cholesterol (mmol/L)", "ALT", "ALT", "Alanine Aminotransferase (U/L)")
adlb <- lb %>% filter(LBTESTCD %in% param_lookup$LBTESTCD) %>% derive_vars_merged( dataset_add = adsl, new_vars = adsl_vars, by_vars = exprs(STUDYID, USUBJID) ) %>% derive_vars_dt(new_vars_prefix = "A", dtc = LBDTC) %>% derive_vars_dy(reference_date = TRTSDT, source_vars = exprs(ADT)) %>% derive_vars_merged( dataset_add = param_lookup, new_vars = exprs(PARAMCD, PARAM), by_vars = exprs(LBTESTCD) ) %>% mutate(AVAL = LBSTRESN) %>% # Analysis visits: screening collapses to Baseline, weeks keep their number. mutate( AVISIT = case_when( stringr::str_detect(VISIT, "SCREEN") ~ "Baseline", !is.na(VISIT) ~ stringr::str_to_title(VISIT), TRUE ~ NA_character_ ), AVISITN = case_when(AVISIT == "Baseline" ~ 0, TRUE ~ VISITNUM) )
adlb %>% filter(USUBJID == "BTISYN01-001", PARAMCD == "CHOLES") %>% select(USUBJID, PARAMCD, VISIT, AVISIT, ADT, ADY, AVAL) %>% head(5)# A tibble: 4 × 7 USUBJID PARAMCD VISIT AVISIT ADT ADY AVAL <chr> <chr> <chr> <chr> <date> <dbl> <dbl>1 BTISYN01-001 CHOLES SCREENING 1 Baseline 2025-01-03 -7 4.32 BTISYN01-001 CHOLES SCREENING 2 Baseline 2025-01-09 -1 4.53 BTISYN01-001 CHOLES WEEK 1 Week 1 2025-01-17 8 4.74 BTISYN01-001 CHOLES WEEK 2 Week 2 2025-01-24 15 4.9SDTM’s LBDTC is a character string and its LBDY counts from a study-specific
reference; ADaM’s ADT is a real date and ADY counts days from the first dose,
with day one being the day of first dose and no day zero. The visit mapping beside it is the same idea applied to timepoints: the
collected visit name becomes a controlled analysis visit with a number that sorts.
Baseline and change from baseline
Section titled “Baseline and change from baseline”The baseline rule for this study is the usual one: the last non-missing measurement
on or before the first dose. restrict_derivation runs the extreme-record flag only
on the rows that pass that filter, then derive_var_base copies the flagged value
into every row of the parameter. Change from baseline is computed on post-baseline
analysis visits only, which leaves CHG missing at baseline. This choice follows
the method template and the synthetic study specification. A missing second
screening value makes the first screening value the baseline. Subjects without a
first dose have no eligible baseline.
adlb <- adlb %>% restrict_derivation( derivation = derive_var_extreme_flag, args = params( by_vars = exprs(STUDYID, USUBJID, PARAMCD), order = exprs(ADT, VISITNUM, LBSEQ), new_var = ABLFL, mode = "last" ), filter = !is.na(AVAL) & ADT <= TRTSDT ) %>% derive_var_base( by_vars = exprs(STUDYID, USUBJID, PARAMCD), source_var = AVAL, new_var = BASE ) %>% restrict_derivation( derivation = derive_var_chg, filter = AVISITN > 0 ) %>% restrict_derivation( derivation = derive_var_pchg, filter = AVISITN > 0 )
adlb %>% filter(USUBJID == "BTISYN01-001", PARAMCD == "CHOLES") %>% arrange(ADY) %>% select(USUBJID, PARAMCD, AVISIT, ADY, AVAL, ABLFL, BASE, CHG) %>% head(6)# A tibble: 4 × 8 USUBJID PARAMCD AVISIT ADY AVAL ABLFL BASE CHG <chr> <chr> <chr> <dbl> <dbl> <chr> <dbl> <dbl>1 BTISYN01-001 CHOLES Baseline -7 4.3 <NA> 4.5 NA2 BTISYN01-001 CHOLES Baseline -1 4.5 Y 4.5 NA3 BTISYN01-001 CHOLES Week 1 8 4.7 <NA> 4.5 0.2004 BTISYN01-001 CHOLES Week 2 15 4.9 <NA> 4.5 0.400The independent reference selects baseline records with base R date comparisons and computes differences with arithmetic. The fixture checks include explicit expected values for a complete baseline, a missing second screening value, and an untreated subject. The page compares all selected records, including missing values, and checks the join size before it reports differences.
ref_adlb <- study$ref_adlb
cmp_lb <- adlb %>% select(USUBJID, PARAMCD, LBSEQ, ADT, AVAL, ABLFL, BASE, CHG, PCHG) %>% inner_join( ref_adlb %>% select(USUBJID, PARAMCD, LBSEQ, ADT, ABLFL_REF = ABLFL, BASE_REF = BASE, CHG_REF = CHG, PCHG_REF = PCHG), by = c("USUBJID", "PARAMCD", "LBSEQ", "ADT") )
stopifnot(nrow(cmp_lb) == nrow(adlb), nrow(cmp_lb) == nrow(ref_adlb))stopifnot(identical(cmp_lb$ABLFL, cmp_lb$ABLFL_REF))stopifnot(isTRUE(all.equal(cmp_lb$BASE, cmp_lb$BASE_REF)))stopifnot(isTRUE(all.equal(cmp_lb$CHG, cmp_lb$CHG_REF)))stopifnot(isTRUE(all.equal(cmp_lb$PCHG, cmp_lb$PCHG_REF)))
# Compare missingness and numeric values separately.cat("records compared:", nrow(cmp_lb), "\n")cat("baseline flags differing:", sum(xor(is.na(cmp_lb$ABLFL), is.na(cmp_lb$ABLFL_REF))) + sum(cmp_lb$ABLFL != cmp_lb$ABLFL_REF, na.rm = TRUE), "\n")cat("BASE differing:", sum(xor(is.na(cmp_lb$BASE), is.na(cmp_lb$BASE_REF))) + sum(abs(cmp_lb$BASE - cmp_lb$BASE_REF) > 1e-10, na.rm = TRUE), "\n")cat("CHG differing:", sum(xor(is.na(cmp_lb$CHG), is.na(cmp_lb$CHG_REF))) + sum(abs(cmp_lb$CHG - cmp_lb$CHG_REF) > 1e-10, na.rm = TRUE), "\n")cat("PCHG independent check: PASS\n")records compared: 288baseline flags differing: 0BASE differing: 0CHG differing: 0PCHG independent check: PASSWhat a production ADSL adds
Section titled “What a production ADSL adds”A submission ADSL goes further: disposition status from DS, death variables from AE
and DS, age and region groupings, and the last-known-alive date assembled from every
domain at once, all with the same derivation verbs. The therapeutic-area extensions
(admiralonco, admiralvaccine, admiralophtha and siblings) package exactly that
kind of extra derivation for their endpoints, and each admiral package ships its
template programs through use_ad_template. Each study still needs reviewed
derivation rules and independent checks. The tables
page turns these datasets into the submission’s
tables.
Scientific references
Section titled “Scientific references”The admiral package by Mancini and colleagues supplies the ADaM derivation functions in R.
Further reading
Section titled “Further reading”-
The vignette shows treatment datetime imputation, exposure selection, and population flags. These are study rules that must agree with the intended analysis population.
-
The template separates baseline selection from derived change values and restricts CHG and PCHG to post-baseline visits. It explains the producer choices used in the reference comparison.
-
The specification defines the exposure and baseline rules and the explicit expected cases. The generator uses base R for the reference comparisons and supplies no patient observations.