h_stack_by_baskets {tern} | R Documentation |
Helper function to create a new SMQ variable in ADAE by stacking SMQ and/or CQ records.
Description
Helper function to create a new SMQ variable in ADAE that consists of all adverse events belonging to
selected Standardized/Customized queries. The new dataset will only contain records of the adverse events
belonging to any of the selected baskets. Remember that na_str
must match the needed pre-processing
done with df_explicit_na()
to have the desired output.
Usage
h_stack_by_baskets(
df,
baskets = grep("^(SMQ|CQ).+NAM$", names(df), value = TRUE),
smq_varlabel = "Standardized MedDRA Query",
keys = c("STUDYID", "USUBJID", "ASTDTM", "AEDECOD", "AESEQ"),
aag_summary = NULL,
na_str = "<Missing>"
)
Arguments
df |
( |
baskets |
( |
smq_varlabel |
( |
keys |
( |
aag_summary |
( |
na_str |
( |
Value
A data.frame
with variables in keys
taken from df
and new variable SMQ containing
records belonging to the baskets selected via the baskets
argument.
Examples
adae <- tern_ex_adae[1:20, ] %>% df_explicit_na()
h_stack_by_baskets(df = adae)
aag <- data.frame(
NAMVAR = c("CQ01NAM", "CQ02NAM", "SMQ01NAM", "SMQ02NAM"),
REFNAME = c(
"D.2.1.5.3/A.1.1.1.1 aesi", "X.9.9.9.9/Y.8.8.8.8 aesi",
"C.1.1.1.3/B.2.2.3.1 aesi", "C.1.1.1.3/B.3.3.3.3 aesi"
),
SCOPE = c("", "", "BROAD", "BROAD"),
stringsAsFactors = FALSE
)
basket_name <- character(nrow(aag))
cq_pos <- grep("^(CQ).+NAM$", aag$NAMVAR)
smq_pos <- grep("^(SMQ).+NAM$", aag$NAMVAR)
basket_name[cq_pos] <- aag$REFNAME[cq_pos]
basket_name[smq_pos] <- paste0(
aag$REFNAME[smq_pos], "(", aag$SCOPE[smq_pos], ")"
)
aag_summary <- data.frame(
basket = aag$NAMVAR,
basket_name = basket_name,
stringsAsFactors = TRUE
)
result <- h_stack_by_baskets(df = adae, aag_summary = aag_summary)
all(levels(aag_summary$basket_name) %in% levels(result$SMQ))
h_stack_by_baskets(
df = adae,
aag_summary = NULL,
keys = c("STUDYID", "USUBJID", "AEDECOD", "ARM"),
baskets = "SMQ01NAM"
)