knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

This article describes creating a BDS finding ADaM. Examples are currently presented and tested in the context of ADVS. However, the examples could be applied to other BDS Finding ADaMs such as ADEG, ADLB, etc. where a single result is captured in an SDTM Finding domain on a single date and/or time.

Note: All examples assume CDISC SDTM and/or ADaM format as input unless otherwise specified.

Programming Workflow

Read in Data {#readdata}

To start, all data frames needed for the creation of ADVS should be read into the environment. This will be a company specific process. Some of the data frames needed may be VS, SUPPVS, and ADSL.

For example purpose, the CDISC Pilot SDTM and ADaM datasets---which are included in {admiral.test}---are used.

library(admiral)
library(dplyr)
library(admiral.test)
library(lubridate)
library(stringr)
library(tibble)

data("adsl")
data("vs")
vs <- convert_blanks_to_na(vs)
vs <- filter(vs, USUBJID %in% c('01-701-1015', '01-701-1023', '01-703-1086', '01-703-1096', '01-707-1037', '01-716-1024'))

The SUPPVS domain can be joined to the VS domain using the function derive_vars_suppqual().

This function will transpose the supplemental SDTM domain (e.g. SUPPVS) and join the transposed data to the parent domain (e.g. VS) by STUDYID, USUBJID using the IDVAR and IDVARVAL as an additional join variable.

Example call:

vs <- derive_vars_suppqual(vs, suppvs)

Please note, the CDISC pilot did not include a SUPPVS dataset and therefore this join is not demonstrated.

At this step, it may be useful to join ADSL to your VS domain. Only the ADSL variables used for derivations are selected at this step. The rest of the relevant ADSL would be added later.

adsl_vars <- vars(TRTSDT, TRTEDT, TRT01A, TRT01P)

advs <- left_join(
  vs,
  select(adsl, STUDYID, USUBJID, !!!adsl_vars),
  by = c("STUDYID", "USUBJID")
)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, VSTESTCD, VSDTC, VISIT, TRTSDT, TRTEDT, TRT01A, TRT01P),
  filter = VSTESTCD == "DIABP" & VISIT == "WEEK 2"
)

Derive/Impute Numeric Date/Time and Analysis Day (ADT, ADTM, ADY, ADTF, ATMF) {#datetime}

The function derive_vars_dt() can be used to derive ADT. This function allows the user to impute the date as well.

Example calls:

advs <- derive_vars_dt(advs, new_vars_prefix = "A", dtc = VSDTC)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, VISIT, VSDTC, ADT, ADTF),
  filter = VSTESTCD == "DIABP"
)

If imputation is needed and the date is to be imputed to the first of the month, the call would be:

advs_old <- advs

advs <- advs %>% 
  mutate(
    VSDTC = if_else(
      USUBJID == "01-716-1024" & VISIT == "SCREENING 1",
      "2012-07",
      VSDTC
    )
  ) %>% 
  select(-ADT, -ADTF)
advs <- derive_vars_dt(
  advs, 
  new_vars_prefix = "A", 
  dtc = VSDTC, 
  date_imputation = "FIRST"
)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, VISIT, VSDTC, ADT, ADTF),
  filter = USUBJID == "01-716-1024"
)
advs <- advs_old

Similarly, ADTM may be created using the function derive_vars_dtm(). Imputation may be done on both the date and time components of ADTM.

# CDISC Pilot data does not contain times and the output of the derivation
# ADTM is not presented.
advs <- derive_vars_dtm(
  advs, 
  new_vars_prefix = "A", 
  dtc = VSDTC, 
  date_imputation = "FIRST"
)

By default, the variable ADTF for derive_vars_dt() or ADTF and ATMF for derive_vars_dtm() will be created and populated with the controlled terminology outlined in the ADaM IG for date imputations.

See also Date and Time Imputation.

Once ADT is derived, the function derive_var_ady() can be used to derive ADY. This example assumes both ADT and TRTSDT exist on the data frame.

advs <- derive_var_ady(advs, reference_date = TRTSDT, date = ADT)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, VISIT, ADT, ADY, TRTSDT),
  filter = USUBJID == "01-716-1024"
)

Assign PARAMCD, PARAM, PARAMN, PARCAT1 {#paramcd}

To assign parameter level values such as PARAMCD, PARAM, PARAMN, PARCAT1, etc., a lookup can be created to join to the source data.

For example, when creating ADVS, a lookup based on the SDTM --TESTCD value may be created:

VSTESTCD | PARAMCD | PARAM | PARAMN | PARCAT1 | PARCAT1N --------- | --------- | -------- | ------- | --------- | ---------- HEIGHT | HEIGHT | Height (cm) | 1 | Subject Characteristic | 1 WEIGHT | WEIGHT | Weight (kg) | 2 | Subject Characteristic | 1 DIABP | DIABP | Diastolic Blood Pressure (mmHg) | 3 | Vital Sign | 2 MAP | MAP | Mean Arterial Pressure | 4 | Vital Sign | 2 PULSE | PULSE | Pulse Rate (beats/min) | 5 | Vital Sign | 2 SYSBP | SYSBP | Systolic Blood Pressure (mmHg) | 6 | Vital Sign | 2 TEMP | TEMP | Temperature (C) | 7 | Vital Sign | 2

This lookup may now be joined to the source data:

param_lookup <- tribble(
  ~VSTESTCD, ~PARAMCD, ~PARAM, ~PARAMN, ~PARCAT1, ~PARCAT1N,
  "HEIGHT", "HEIGHT", "Height (cm)", 1, "Subject Characteristic", 1,
  "WEIGHT", "WEIGHT", "Weight (kg)", 2, "Subject Characteristic", 1,
  "DIABP", "DIABP", "Diastolic Blood Pressure (mmHg)", 3, "Vital Sign", 2,
  "MAP", "MAP", "Mean Arterial Pressure (mmHg)", 4, "Vital Sign", 2,
  "BSA", "BSA", "Body Surface Area (m^2)", 5, "Vital Sign", 2,
  "PULSE", "PULSE", "Pulse Rate (beats/min)", 6, "Vital Sign", 2,
  "SYSBP", "SYSBP", "Systolic Blood Pressure (mmHg)", 7, "Vital Sign",2,
  "TEMP", "TEMP", "Temperature (C)", 8, "Vital Sign", 2
)
attr(param_lookup$VSTESTCD, "label") <- "Vital Signs Test Short Name"

At this stage, only PARAMCD is required to perform the derivations. Additional derived parameters may be added, so only PARAMCD is joined to the datasets at this point. All other variables related to PARAMCD (e.g. PARAM, PARAMCAT1, ...) will be added when all PARAMCD are derived.

advs <- left_join(advs, select(param_lookup, VSTESTCD, PARAMCD), by = "VSTESTCD")
advs_param <- distinct(advs, USUBJID, PARAMCD, VSTESTCD)

dataset_vignette(advs_param, display_vars = vars(USUBJID, VSTESTCD, PARAMCD))

Please note, it may be necessary to include other variables in the join. For example, perhaps the PARAMCD is based on VSTESTCD and VSPOS, it may be necessary to expand this lookup or create a separate look up for PARAMCD.

Derive Results (AVAL, AVALC) {#aval}

The mapping of AVAL and AVALC is left to the ADaM programmer. An example mapping may be:

advs <- mutate(
  advs, 
  AVAL = VSSTRESN,
  AVALC = VSSTRESC
)
dataset_vignette(
  advs, 
  display_vars = vars(VSTESTCD, PARAMCD, VSSTRESN, VSSTRESC, AVAL, AVALC),
  filter = USUBJID == "01-716-1024"
)

Derive Additional Parameters (e.g. BSA, BMI or MAP for ADVS) {#derive_param}

Optionally derive new parameters creating PARAMCD and AVAL. Below is an example of creating Mean Arterial Pressure for ADVS, see also Example 3 in section below Derive New Rows for alternative way of creating new parameters.

advs <- derive_param_map(
  advs,
  by_vars = vars(STUDYID, USUBJID, !!!adsl_vars, VISIT, VISITNUM, ADT, ADY, VSTPT, VSTPTNUM),
  set_values_to = vars(PARAMCD = "MAP"),
  get_unit_expr = VSSTRESU,
  filter = VSSTAT != "NOT DONE" | is.na(VSSTAT)
)
dataset_vignette(
  arrange(advs, USUBJID, VISITNUM, VSTPTNUM, ADT, PARAMCD),
  display_vars = vars(VSTESTCD, PARAMCD, VISIT, VSTPT, AVAL, AVALC),
  filter = USUBJID == "01-701-1015" & PARAMCD %in% c("MAP", "DIABP","SYSBP")
)

Likewise, function call below, to create parameter Body Surface Area and Body Mass Index for ADVS domain.

advs <- derive_param_bsa(
  advs,
  by_vars = vars(STUDYID, USUBJID, !!!adsl_vars, VISIT, VISITNUM, ADT, ADY, VSTPT, VSTPTNUM),
  method = "Mosteller",
  set_values_to = vars(PARAMCD = "BSA"),
  get_unit_expr = VSSTRESU,
  filter = VSSTAT != "NOT DONE" | is.na(VSSTAT)
)

advs <- derive_param_bmi(
  advs,
  by_vars = vars(STUDYID, USUBJID, !!!adsl_vars, VISIT, VISITNUM, ADT, ADY, VSTPT, VSTPTNUM),
  set_values_to = vars(PARAMCD = "BMI"),
  get_unit_expr = VSSTRESU,
  filter = VSSTAT != "NOT DONE" | is.na(VSSTAT)
)
dataset_vignette(
  arrange(advs, USUBJID, VISITNUM, VSTPTNUM, ADT, PARAMCD),
  display_vars = vars(USUBJID, VSTESTCD, PARAMCD, VISIT, VSTPT, AVAL, AVALC),
  filter = PARAMCD %in% c("BSA", "BMI")
)

Similarly, for ADEG domain, the parameters QTCBF QTCBS and QTCL can be created with a function call. See example below for PARAMCD = QTCF.

adeg <- derive_param_qtcf(
  adeg,
  by_vars = vars(USUBJID, VISIT, ADT),
  set_values_to = vars(PARAMCD = "QTCFR")
)

When all PARAMCD have been derived and added to the dataset, the other information from the look-up table (PARAM, PARAMCAT1,...) should be added.

# Derive PARAM and PARAMN
advs <- left_join(advs, select(param_lookup, -VSTESTCD), by = "PARAMCD")
dataset_vignette(
  advs, 
  display_vars = vars(VSTESTCD, PARAMCD, PARAM, PARAMN, PARCAT1, PARCAT1N),
  filter = USUBJID == "01-716-1024"
)

Derive Timing Variables (e.g. APHASE, AVISIT, APERIOD) {#timing}

Categorical timing variables are protocol and analysis dependent. Below is a simple example.

advs <- advs %>% 
  mutate(
    AVISIT = case_when(
      str_detect(VISIT, "SCREEN") ~ NA_character_,
      str_detect(VISIT, "UNSCHED") ~ NA_character_,
      str_detect(VISIT, "RETRIEVAL") ~ NA_character_,
      str_detect(VISIT, "AMBUL") ~ NA_character_,
      !is.na(VISIT) ~ str_to_title(VISIT)
    ),
    AVISITN = as.numeric(case_when(
      VISIT == "BASELINE" ~ "0",
      str_detect(VISIT, "WEEK") ~ str_trim(str_replace(VISIT, "WEEK", ""))
    )),
    ATPT = VSTPT,
    ATPTN = VSTPTNUM
  )


count(advs, VISITNUM, VISIT, AVISITN, AVISIT)

count(advs, VSTPTNUM, VSTPT, ATPTN, ATPT)

Timing Flag Variables (e.g. ONTRTFL) {#timingflag}

In some analyses, it may be necessary to flag an observation as on-treatment. The admiral function derive_var_ontrtfl() can be used.

For example, if on-treatment is defined as any observation between treatment start and treatment end, the flag may be derived as:

advs <- derive_var_ontrtfl(
  advs, 
  start_date = ADT, 
  ref_start_date = TRTSDT, 
  ref_end_date = TRTEDT
)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, PARAMCD, ADT, TRTSDT, TRTEDT, ONTRTFL),
  filter = PARAMCD == "DIABP" & VISIT == "WEEK 2"
)

This function returns the original data frame with the column ONTRTFL added. Additionally, this function does have functionality to handle a window on the ref_end_date. For example, if on-treatment is defined as between treatment start and treatment end plus 60 days, the call would be:

advs <- select(advs, -ONTRTFL)
advs <- derive_var_ontrtfl(
  advs, 
  start_date = ADT, 
  ref_start_date = TRTSDT, 
  ref_end_date = TRTEDT,
  ref_end_window = 60
)

In addition, the function does allow you to filter out pre-treatment observations that occurred on the start date. For example, if observations with VSTPT == PRE should not be considered on-treatment when the observation date falls between the treatment start and end date, the user may specify this using the filter_pre_timepoint parameter:

advs <- select(advs, -ONTRTFL)
advs <- derive_var_ontrtfl(
  advs,
  start_date = ADT,
  ref_start_date = TRTSDT,
  ref_end_date = TRTEDT,
  filter_pre_timepoint = ATPT == "AFTER LYING DOWN FOR 5 MINUTES"
)

Lastly, the function does allow you to create any on-treatment flag based on the analysis needs. For example, if variable ONTR01FL is needed, showing the on-treatment flag during Period 01, you need to set new var = ONTR01FL. In addition, for Period 01 Start Date and Period 01 End Date, you need ref_start_date = AP01SDT and ref_end_date = AP01EDT.

advs_pre <- select(advs, -ONTRTFL)

advs <- tibble::tribble(
  ~USUBJID, ~ASTDT,              ~AP01SDT,           ~AP01EDT,           ~AENDT,
  "P01",    ymd("2020-03-15"), ymd("2020-01-01"), ymd("2020-03-01"), ymd("2020-12-01"),
  "P02",    ymd("2019-04-30"), ymd("2020-01-01"), ymd("2020-03-01"), ymd("2020-03-15"),
  "P03",    ymd("2019-04-30"), ymd("2020-01-01"), ymd("2020-03-01"), NA,
)
advs <- derive_var_ontrtfl(
 advs,
 new_var = ONTR01FL,
 start_date = ASTDT,
 end_date = AENDT,
 ref_start_date = AP01SDT,
 ref_end_date = AP01EDT,
 span_period = "Y"
)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, ASTDT, AENDT, AP01SDT, AP01EDT, ONTR01FL)
)

Assign Reference Range Indicator (ANRIND) {#referencerange}

The admiral function derive_var_anrind() may be used to derive the reference range indicator ANRIND.

This function requires the reference range boundaries to exist on the data frame (ANRLO, ANRHI) and also accommodates the additional boundaries A1LO and A1HI.

range_lookup <- tibble::tribble(
  ~PARAMCD, ~ANRLO, ~ANRHI, ~A1LO, ~A1HI,
  "SYSBP", 90, 130, 70, 140,
  "DIABP", 60, 80, 40, 90,
  "PULSE", 60, 100, 40, 110,
  "TEMP", 36.5, 37.5, 35, 38
)

advs <- left_join(advs_pre, range_lookup, by = "PARAMCD")

The function is called as:

advs <- derive_var_anrind(advs)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, PARAMCD, AVAL, ANRLO, ANRHI, A1LO, A1HI, ANRIND),
  filter = PARAMCD == "DIABP" & VISIT == "WEEK 2"
)

Derive Baseline (BASETYPE, ABLFL, BASE, BASEC, BNRIND) {#baseline}

The BASETYPE should be derived using the function derive_var_basetype(). The parameter basetypes of this function requires a named list of expression detailing how the BASETYPE should be assigned. Note, if a record falls into multiple expressions within the basetypes expression, a row will be produced for each BASETYPE.

advs <- derive_var_basetype(
  dataset = advs,
  basetypes = exprs(
    "LAST: AFTER LYING DOWN FOR 5 MINUTES" = ATPTN == 815,
    "LAST: AFTER STANDING FOR 1 MINUTE" = ATPTN == 816,
    "LAST: AFTER STANDING FOR 3 MINUTES" = ATPTN == 817,
    "LAST" = is.na(ATPTN)
  )
)

count(advs, ATPT, ATPTN, BASETYPE)

It is important to derive BASETYPE first so that it can be utilized in subsequent derivations. This will be important if the data frame contains multiple values for BASETYPE.

Next, the analysis baseline flag ABLFL can be derived using the {admiral} function derive_var_extreme_flag(). For example, if baseline is defined as the last non-missing AVAL prior or on TRTSDT, the function call for ABLFL would be:

advs <- derive_var_extreme_flag(
  advs,
  by_vars = vars(STUDYID, USUBJID, BASETYPE, PARAMCD),
  order = vars(ADT, ATPTN, VISITNUM),
  new_var = ABLFL,
  mode = "last",
  filter = (!is.na(AVAL) & ADT <= TRTSDT & !is.na(BASETYPE))
)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, BASETYPE, PARAMCD, ADT, TRTSDT, ATPTN, TRTSDT, ABLFL),
  filter = PARAMCD == "DIABP" & VISIT %in% c("WEEK 2", "BASELINE")
)

Note: Additional examples of the derive_var_extreme_flag() function can be found above.

Lastly, the BASE, BASEC and BNRIND columns can be derived using the {admiral} function derive_var_base(). Example calls are:

advs <- derive_var_base(
  advs,
  by_vars = vars(STUDYID, USUBJID, PARAMCD, BASETYPE),
  source_var = AVAL, 
  new_var = BASE
)

advs <- derive_var_base(
  advs,
  by_vars = vars(STUDYID, USUBJID, PARAMCD, BASETYPE),
  source_var = AVALC, 
  new_var = BASEC
)

advs <- derive_var_base(
  advs,
  by_vars = vars(STUDYID, USUBJID, PARAMCD, BASETYPE),
  source_var = ANRIND, 
  new_var = BNRIND
)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, BASETYPE, PARAMCD, ABLFL, BASE, BASEC, ANRIND, BNRIND),
  filter = PARAMCD == "DIABP" & VISIT %in% c("WEEK 2", "BASELINE")
)

Derive Change from Baseline (CHG, PCHG) {#bchange}

Change and percent change from baseline can be derived using the {admiral} functions derive_var_chg() and derive_var_pchg(). These functions expect AVAL and BASE to exist in the data frame. The CHG is simply AVAL - BASE and the PCHG is (AVAL - BASE) / absolute value (BASE) * 100. Examples calls are:

advs <- derive_var_chg(advs)

advs <- derive_var_pchg(advs)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, VISIT, BASE, AVAL, CHG, PCHG),
  filter = PARAMCD == "DIABP" & VISIT %in% c("WEEK 2", "WEEK 8")
)

Derive Analysis Flags (e.g. ANL01FL) {#analysisrec}

In most finding ADaMs, an analysis flag is derived to identify the appropriate observation(s) to use for a particular analysis when a subject has multiple observations within a particular timing period.

In this situation, an analysis flag (e.g. ANLxxFL) may be used to choose the appropriate record for analysis.

This flag may be derived using the {admiral} function derive_var_extreme_flag(). For this example, we will assume we would like to choose the latest and highest value by USUBJID, PARAMCD, AVISIT, and ATPT.

advs <- derive_var_extreme_flag(
  advs,
  by_vars = vars(USUBJID, PARAMCD, AVISIT),
  order = vars(ADT, ATPTN, AVAL),
  new_var = ANL01FL,
  mode = "last",
  filter = !is.na(AVISITN)
)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, PARAMCD, AVISIT, ATPTN, ADT, AVAL, ANL01FL),
  filter = PARAMCD == "DIABP" & VISIT %in% c("WEEK 2", "WEEK 8")
)

Another common example would be flagging the worst value for a subject, parameter, and visit. For this example, we will assume we have 3 PARAMCD values (SYSBP, DIABP, and RESP). We will also assume high is worst for SYSBP and DIABP and low is worst for RESP.

advs <- derive_var_worst_flag(
  advs,
  by_vars = vars(USUBJID, PARAMCD, AVISIT),
  order = vars(ADT, ATPTN),
  new_var = WORSTFL,
  param_var = PARAMCD,
  analysis_var = AVAL,
  worst_high = c("SYSBP", "DIABP"),
  worst_low = "PULSE",
  filter = !is.na(AVISIT) & !is.na(AVAL)
)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, PARAMCD, AVISIT, AVAL, ADT, ATPTN, WORSTFL),
  filter = USUBJID == "01-701-1015"
)

Assign Treatment (TRTA, TRTP) {#treatment}

TRTA and TRTP must correlate to treatment TRTxxP and/or TRTxxA in ADSL. The derivation of TRTA and TRTP for a record are protocol and analysis specific.
{admiral} does not currently have functionality to assist with TRTA and TRTP assignment.

However, an example of a simple implementation could be:

advs <- mutate(advs, TRTP = TRT01P, TRTA = TRT01A)

count(advs, TRTP, TRTA, TRT01P, TRT01A)

Assign ASEQ {#aseq}

The {admiral} function derive_var_obs_number() can be used to derive ASEQ. An example call is:

advs <- derive_var_obs_number(
  advs,
  new_var = ASEQ,
  by_vars = vars(STUDYID, USUBJID),
  order = vars(PARAMCD, ADT, AVISITN, VISITNUM, ATPTN),
  check_type = "error"
)
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, PARAMCD, ADT, AVISITN, ATPTN, VISIT, ADT, ASEQ),
  filter = USUBJID == "01-701-1015"
)

Derive Categorization Variables (AVALCATx) {#cat}

Admiral does not currently have a generic function to aid in assigning AVALCATx/ AVALCAxN values. Below is a simple example of how these values may be assigned:

avalcat_lookup <- tibble::tribble(
  ~PARAMCD, ~AVALCA1N, ~AVALCAT1,
  "HEIGHT", 1, ">140 cm",
  "HEIGHT", 2, "<= 140 cm"
)

format_avalcat1n <- function(param, aval) {
  case_when(
    param == "HEIGHT" & aval > 140 ~ 1,
    param == "HEIGHT" & aval <= 140 ~ 2
  )
}

advs <- advs %>% 
  mutate(AVALCA1N = format_avalcat1n(param = PARAMCD, aval = AVAL)) %>%
  left_join(avalcat_lookup, by = c("PARAMCD", "AVALCA1N"))
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, PARAMCD, AVAL, AVALCA1N, AVALCAT1),
  filter = PARAMCD == "HEIGHT"
)

Add ADSL variables {#adsl_vars}

If needed, the other ADSL variables can now be added. List of ADSL variables already merged held in vector adsl_vars

advs <- advs %>%
  left_join(
    select(adsl, !!!admiral:::negate_vars(adsl_vars)),
    by = c("STUDYID", "USUBJID")
  )
dataset_vignette(
  advs, 
  display_vars = vars(USUBJID, RFSTDTC, RFENDTC, DTHDTC, DTHFL, AGE,AGEU),
  filter = USUBJID == "01-701-1015"
)

Derive New Rows {#additional}

When deriving new rows for a data frame, it is essential the programmer takes time to insert this derivation in the correct location of the code. The location will vary depending on what previous computations should be retained on the new record and what computations must be done with the new records.

Example 1 (Creating a New Record):

For each subject and Vital Signs parameter, add a record holding last valid observation before end of treatment. Set AVISIT to "End of Treatment" and assign a unique AVISITN value.

advs_ex1 <- advs %>%
  derive_var_extreme_flag(
    by_vars = vars(STUDYID, USUBJID, PARAMCD),
    order = vars(ADT, AVISITN, ATPTN, AVAL),
    new_var = EOTFL,
    mode = "last",
    filter = (4 < AVISITN & AVISITN <= 12 & ANL01FL == "Y")
  ) %>%
  filter(EOTFL == "Y") %>%
  mutate(
    AVISIT = "End of Treatment",
    AVISITN = 99
  ) %>%
  union_all(advs) %>%
  select(-EOTFL)
dataset_vignette(
  advs_ex1, 
  display_vars = vars(USUBJID, PARAMCD, ADT, AVISITN, AVISIT, ATPTN, AVAL, ANL01FL),
  filter = USUBJID == "01-701-1015" & ANL01FL == "Y"
)

Example 2 (Deriving a Summary Record)

For each subject, Vital Signs parameter, visit, and date add a record holding the average value for observations on that date. Set DTYPE to AVERAGE.

advs_ex2 <- derive_summary_records(
  advs,
  by_vars = vars(STUDYID, USUBJID, PARAMCD, VISITNUM, ADT),
  analysis_var = AVAL,
  summary_fun = mean,
  set_values_to = vars(DTYPE = "AVERAGE")
)
dataset_vignette(
  arrange(advs_ex2, USUBJID, PARAMCD, VISITNUM, ADT, DTYPE), 
  display_vars = vars(USUBJID, PARAMCD, VISITNUM, ADT, AVAL, DTYPE),
  filter = USUBJID == "01-701-1015"
)

Example 3 (Deriving a New PARAMCD)

Use function derive_derived_param() to create a new PARAMCD. Below is an example of creating Mean Arterial Pressure (PARAMCD = MAP2) with an alternative formula.

advs_ex3 <- derive_derived_param(
  advs,
  by_vars = vars(USUBJID, VISIT, ATPT),
  parameters = c("SYSBP", "DIABP"),
  analysis_value = (AVAL.SYSBP-AVAL.DIABP)/3 + AVAL.DIABP ,
  set_values_to = vars(
    PARAMCD = "MAP2",
    PARAM = "Mean Arterial Pressure 2 (mmHg)"
  )
)
dataset_vignette(
  arrange(advs_ex3, USUBJID, VISIT, ATPT, PARAMCD), 
  display_vars = vars(USUBJID, PARAMCD, VISIT, ATPT, AVAL),
  filter = USUBJID == "01-701-1015" & PARAMCD %in% c("MAP2", "SYSBP", "DIABP") 
)

Example Scripts {#example}

ADaM | Sample Code ---- | -------------- ADEG | ad_adeg.R{target="_blank"} ADVS | ad_advs.R{target="_blank"}



epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.