| count_patients_with_flags {tern} | R Documentation | 
Count the number of patients with particular flags
Description
The primary analysis variable .var denotes the unique patient identifier.
Usage
count_patients_with_flags(
  lyt,
  var,
  flag_variables,
  flag_labels = NULL,
  var_labels = var,
  show_labels = "hidden",
  riskdiff = FALSE,
  na_str = default_na_str(),
  nested = TRUE,
  ...,
  table_names = paste0("tbl_flags_", var),
  .stats = "count_fraction",
  .formats = NULL,
  .indent_mods = NULL
)
s_count_patients_with_flags(
  df,
  .var,
  flag_variables,
  flag_labels = NULL,
  .N_col,
  .N_row,
  denom = c("n", "N_row", "N_col")
)
a_count_patients_with_flags(
  df,
  .var,
  flag_variables,
  flag_labels = NULL,
  .N_col,
  .N_row,
  denom = c("n", "N_row", "N_col")
)
Arguments
| lyt | ( | 
| var | ( | 
| flag_variables | ( | 
| flag_labels | ( | 
| var_labels | ( | 
| show_labels | ( | 
| riskdiff | ( | 
| na_str | ( | 
| nested | ( | 
| ... | additional arguments for the lower level functions. | 
| table_names | ( | 
| .stats | ( | 
| .formats | (named  | 
| .indent_mods | (named  | 
| df | ( | 
| .var | ( | 
| .N_col | ( | 
| .N_row | ( | 
| denom | ( 
 | 
Value
-  count_patients_with_flags()returns a layout object suitable for passing to further layouting functions, or tortables::build_table(). Adding this function to anrtablelayout will add formatted rows containing the statistics froms_count_patients_with_flags()to the table layout.
-  s_count_patients_with_flags()returns the count and the fraction of unique identifiers with each particular flag as a list of statisticsn,count,count_fraction, andn_blq, with one element per flag.
-  a_count_patients_with_flags()returns the corresponding list with formattedrtables::CellValue().
Functions
-  count_patients_with_flags(): Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper forrtables::analyze().
-  s_count_patients_with_flags(): Statistics function which counts the number of patients for which a particular flag variable isTRUE.
-  a_count_patients_with_flags(): Formatted analysis function which is used asafunincount_patients_with_flags().
Note
If flag_labels is not specified, variables labels will be extracted from df. If variables are not
labeled, variable names will be used instead. Alternatively, a named vector can be supplied to
flag_variables such that within each name-value pair the name corresponds to the variable name and the value is
the label to use for this variable.
See Also
Examples
library(dplyr)
# Add labelled flag variables to analysis dataset.
adae <- tern_ex_adae %>%
  mutate(
    fl1 = TRUE %>% with_label("Total AEs"),
    fl2 = (TRTEMFL == "Y") %>%
      with_label("Total number of patients with at least one adverse event"),
    fl3 = (TRTEMFL == "Y" & AEOUT == "FATAL") %>%
      with_label("Total number of patients with fatal AEs"),
    fl4 = (TRTEMFL == "Y" & AEOUT == "FATAL" & AEREL == "Y") %>%
      with_label("Total number of patients with related fatal AEs")
  )
# `count_patients_with_flags()`
lyt2 <- basic_table() %>%
  split_cols_by("ARM") %>%
  add_colcounts() %>%
  count_patients_with_flags(
    "SUBJID",
    flag_variables = c("fl1", "fl2", "fl3", "fl4"),
    denom = "N_col"
  )
build_table(lyt2, adae, alt_counts_df = tern_ex_adsl)
# `s_count_patients_with_flags()`
s_count_patients_with_flags(
  adae,
  "SUBJID",
  flag_variables = c("fl1", "fl2", "fl3", "fl4"),
  denom = "N_col",
  .N_col = 1000
)
#  We need to ungroup `count_fraction` first so that the `rtables` formatting
# function `format_count_fraction()` can be applied correctly.
# `a_count_patients_with_flags()`
afun <- make_afun(a_count_patients_with_flags,
  .stats = "count_fraction",
  .ungroup_stats = "count_fraction"
)
afun(
  adae,
  .N_col = 10L,
  .N_row = 10L,
  .var = "USUBJID",
  flag_variables = c("fl1", "fl2", "fl3", "fl4")
)