admiral-adae
Derives an ADaM Adverse Events Analysis Dataset (ADAE) using the {admiral} R package and pharmaverse ecosystem. Use when a user needs to create ADAE from SDTM AE and supporting domains, derive standard adverse event analysis variables (severity, seriousness, treatment-emergent flags, study day variables, baseline flags), or generate QC-ready R code following CDISC ADaM conventions. Requires SDTM input data, ADSL, and an ADaM spec.
RConsortium · 已有 AI 审核记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add RConsortium/pharma-skills --skill admiral-adae技能说明
name: admiral-adae description: > Derives an ADaM Adverse Events Analysis Dataset (ADAE) using the {admiral} R package and pharmaverse ecosystem. Use when a user needs to create ADAE from SDTM AE and supporting domains, derive standard adverse event analysis variables (severity, seriousness, treatment-emergent flags, study day variables, baseline flags), or generate QC-ready R code following CDISC ADaM conventions. Requires SDTM input data, ADSL, and an ADaM spec. license: MIT metadata: author: Navitas Data Sciences version: "0.1" pharmaverse: "true" compatibility: > Requires R with admiral, dplyr, lubridate, and pharmaversesdtm installed. Designed for use in a GxP-compliant environment with access to SDTM datasets, a completed ADSL dataset, and an ADaM ADAE specification.
admiral-adae
Derives a CDISC-conformant ADAE dataset using {admiral}. Outputs executable, QC-ready R code with derivation logic traceable to the ADaM specification.
The primary design challenge in ADAE is the treatment-emergent adverse event (TEAE) flag (TRTEMFL) and its supporting date infrastructure. All date and study day derivations must flow from this before any analysis variables are added.
Inputs
Before generating code, confirm the following are available or explicitly noted as absent:
| Input | Required | Notes |
|---|---|---|
| AE | Yes | One record per AE per subject; subject spine for ADAE |
| ADSL | Yes | Provides TRTSDT, TRTEDT, TRT01P/A, population flags |
| MH | No | Medical history; needed for pre-existing condition flag (PREFL) |
| CM | No | Concomitant medications; sometimes linked to AE causality |
| ADaM ADAE spec | Yes | Variable list, derivation rules, TEAE definition, grading rules |
| Study context | Yes | TEAE window definition, SMQ/grouping flag scope, severity scale |
If AE or ADSL are absent, stop and request them. If optional domains are absent, omit the corresponding derivations and note this in code comments.
Note on pharmaversesdtm test data: The pharmaversesdtm::ae dataset does
not contain AETOXGR. Users running this skill against pharmaverse test data
should skip the AETOXGR derivation in Step 7. The derivation is retained in
the skill for use with real study data where NCI CTCAE grading was collected.
Critical ADSL dependency: ADAE must merge a defined set of ADSL variables onto every AE record. Confirm with the statistician which ADSL variables are required — at minimum: TRTSDT, TRTEDT, TRTSDTM, TRT01P, TRT01PN, TRT01A, TRT01AN, and all population flags in scope (SAFFL, ITTFL).
Workflow
Follow these steps in order. Generate code section by section, not as a single block.
Step 1 — Setup and domain loading
library(admiral)
library(dplyr)
library(lubridate)
library(pharmaversesdtm)
# Load SDTM domains
ae <- pharmaversesdtm::ae
adsl <- adsl # assumed derived upstream; replace with path/load as needed
# mh <- pharmaversesdtm::mh # uncomment if pre-existing condition flag in scope
# Remove DOMAIN from AE to avoid variable conflicts in merges
ae <- ae |> select(-DOMAIN)
# Confirm AE has at least one record
stopifnot(nrow(ae) > 0)
Step 2 — Subject spine from AE
ADAE is a one-record-per-AE dataset; the subject spine is AE itself. Start here and add ADSL variables in the next step.
adae <- ae
Step 3 — Merge ADSL variables
Merge a controlled subset of ADSL variables onto every AE record. Do not merge all of ADSL — select only variables referenced in the ADAE derivation logic and required for the output dataset per the ADaM spec.
# REVIEW: Confirm which ADSL variables are required per the ADAE spec.
# The list below covers the minimum set for TEAE flag derivation and treatment
# labelling. Extend with population flags and other ADSL variables as needed.
adsl_vars <- exprs(
STUDYID, USUBJID,
TRTSDT, TRTEDT, TRTSDTM,
TRT01P, TRT01PN, TRT01A, TRT01AN,
SAFFL, ITTFL
)
adae <- adae |>
derive_vars_merged(
dataset_add = adsl |> select(!!!adsl_vars),
by_vars = exprs(STUDYID, USUBJID)
)
Step 4 — AE date variables (ASTDT, ASTDTF, AENDT, AENDTF)
Derive analysis start and end dates from AE.AESTDTC and AE.AEENDTC. Always
use derive_vars_dt() — never as.Date() directly on DTC variables.
Use date_imputation = "first" for start dates and "last" for end dates per
CDISC convention. Always retain imputation flag variables (ASTDTF, AENDTF).
adae <- adae |>
derive_vars_dt(
dtc = AESTDTC,
new_vars_prefix = "AST",
date_imputation = "first",
flag_imputation = "auto"
) |>
derive_vars_dt(
dtc = AEENDTC,
new_vars_prefix = "AEN",
date_imputation = "last",
flag_imputation = "auto"
)
Step 5 — Study day variables (ASTDY, AENDY)
Use derive_vars_dy() relative to TRTSDT from ADSL. Do not compute study days
manually with date subtraction — this bypasses the Day 1 = first dose date
offset logic required by ADaM.
adae <- adae |>
derive_vars_dy(
reference_date = TRTSDT,
source_vars = exprs(ASTDT, AENDT)
)
Step 6 — Treatment-emergent flag (TRTEMFL)
This is the central derivation in ADAE. TRTEMFL = "Y" when:
- AE onset date (ASTDT) >= first dose date (TRTSDT), and
- AE onset date (ASTDT) <= last dose date (TRTEDT) + study-specific window
The derive_var_trtemfl() function handles this logic. The end_window
parameter defines how many days post-last-dose an AE is still considered
treatment-emergent — this is study- and protocol-specific.
# REVIEW: end_window is protocol-specific. Common values are 30 days post-last
# dose for SAEs and 7 days for non-serious AEs, but always confirm from the
# SAP. If the protocol does not specify a post-treatment window, set end_window
# to 0 to include only AEs on or before the last dose date.
# The ignore_time_for_trt_end argument should be TRUE if TRTEDTM is not
# reliable for all subjects — confirm
阅读完整来源 ↗