derive_var_last_dose_amt: Derive Last Dose Amount

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/derive_var_last_dose_amt.R

Description

Add a variable for dose amount from the last dose to the input dataset.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
derive_var_last_dose_amt(
  dataset,
  dataset_ex,
  filter_ex = NULL,
  by_vars = vars(STUDYID, USUBJID),
  dose_id = vars(),
  dose_date,
  analysis_date,
  single_dose_condition = (EXDOSFRQ == "ONCE"),
  new_var,
  dose_var = EXDOSE,
  traceability_vars = NULL
)

Arguments

dataset

Input dataset. The variables specified by the by_vars and analysis_date parameters are expected.

dataset_ex

Input EX dataset. The variables specified by the by_vars, dose_date, new_vars parameters, and source variables from traceability_vars parameter are expected.

filter_ex

Filtering condition applied to EX dataset. For example, it can be used to filter for valid dose. Defaults to NULL.

by_vars

Variables to join by (created by dplyr::vars).

dose_id

Variables to identify unique dose (created by dplyr::vars). Defaults to empty vars().

dose_date

The EX dose date variable.

analysis_date

The analysis date variable.

single_dose_condition

The condition for checking if dataset_ex is single dose. An error is issued if the condition is not true. Defaults to (EXDOSFRQ == "ONCE").

new_var

The new variable added to dataset.

dose_var

The EX source dose amount variable. Defaults to EXDOSE.

traceability_vars

A named list returned by vars() listing the traceability variables, e.g. vars(LDOSEDOM = "EX", LDOSESEQ = EXSEQ). The left-hand side (names of the list elements) gives the names of the traceability variables in the returned dataset. The right-hand side (values of the list elements) gives the values of the traceability variables in the returned dataset. These can be either strings or symbols referring to existing variables.

Details

The last dose amount is derived as the dose amount where the maximum dose_date is lower to or equal to the analysis_date per by_vars for each observation in dataset.

Value

Input dataset with additional column new_var.

Author(s)

Annie Yang

See Also

derive_vars_last_dose()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(dplyr, warn.conflicts = FALSE)
library(admiral.test)
data(ae)
data(ex_single)

ae %>%
  head(100) %>%
  derive_var_last_dose_amt(
    head(ex_single, 100),
    filter_ex = (EXDOSE > 0 | (EXDOSE == 0 & grepl("PLACEBO", EXTRT))) &
      nchar(EXENDTC) >= 10,
    dose_date = EXENDTC,
    analysis_date = AESTDTC,
    single_dose_condition = (EXSTDTC == EXENDTC),
    new_var = LDOSE,
    dose_var = EXDOSE
  ) %>%
  select(STUDYID, USUBJID, AESEQ, AESTDTC, LDOSE)

# or with traceability variables
ae %>%
  head(100) %>%
  derive_var_last_dose_amt(
    head(ex_single, 100),
    filter_ex = (EXDOSE > 0 | (EXDOSE == 0 & grepl("PLACEBO", EXTRT))) &
      nchar(EXENDTC) >= 10,
    dose_date = EXENDTC,
    analysis_date = AESTDTC,
    single_dose_condition = (EXSTDTC == EXENDTC),
    new_var = LDOSE,
    dose_var = EXDOSE,
    traceability_vars = dplyr::vars(LDOSEDOM = "EX", LDOSESEQ = EXSEQ, LDOSEVAR = "EXDOSE")
  ) %>%
  select(STUDYID, USUBJID, AESEQ, AESTDTC, LDOSEDOM, LDOSESEQ, LDOSEVAR, LDOSE)

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