Count the Number of Patients with a Particular Event
Source:R/count_patients_with_event.R
      count_patients_with_event.RdUsage
s_count_patients_with_event(
  df,
  .var,
  filters,
  .N_col,
  .N_row,
  denom = c("n", "N_row", "N_col")
)
a_count_patients_with_event(
  df,
  .var,
  filters,
  .N_col,
  .N_row,
  denom = c("n", "N_row", "N_col")
)
count_patients_with_event(
  lyt,
  vars,
  ...,
  table_names = vars,
  .stats = "count_fraction",
  .formats = NULL,
  .labels = NULL,
  .indent_mods = NULL
)Arguments
- df
- ( - data.frame)
 data set containing all analysis variables.
- .var
- ( - character)
 name of the column that contains the unique identifier.
- filters
- ( - character)
 a character vector specifying the column names and flag variables to be used for counting the number of unique identifiers satisfying such conditions. Multiple column names and flags are accepted in this format- c("column_name1" = "flag1", "column_name2" = "flag2"). Note that only equality is being accepted as condition.
- .N_col
- ( - count)
 row-wise N (row group count) for the group of observations being analyzed (i.e. with no column-based subsetting) that is passed by- rtables.
- .N_row
- ( - count)
 column-wise N (column count) for the full column that is passed by- rtables.
- denom
- 
( string)
 choice of denominator for proportion. Options are:- n: number of values in this row and column intersection.
- N_row: total number of values in this row across columns.
- N_col: total number of values in this column across rows.
 
- lyt
- ( - layout)
 input layout where analyses will be added to.
- vars
- ( - character)
 variable names for the primary analysis variable to be iterated over.
- ...
- additional arguments for the lower level functions. 
- table_names
- ( - character)
 this can be customized in case that the same- varsare analyzed multiple times, to avoid warnings from- rtables.
- .stats
- ( - character)
 statistics to select for the table.
- .formats
- (named - characteror- list)
 formats for the statistics.
- .labels
- (named - character)
 labels for the statistics (without indent).
- .indent_mods
- (named - integer)
 indent modifiers for the labels. Defaults to 0, which corresponds to the unmodified default behavior. Can be negative.
Value
- s_count_patients_with_event()returns the count and fraction of unique identifiers with the defined event.
- a_count_patients_with_event()returns the corresponding list with formatted- rtables::CellValue().
- count_patients_with_event()returns a layout object suitable for passing to further layouting functions, or to- rtables::build_table(). Adding this function to an- rtablelayout will add formatted rows containing the statistics from- s_count_patients_with_event()to the table layout.
Functions
- s_count_patients_with_event(): Statistics function which counts the number of patients for which the defined event has occurred.
- a_count_patients_with_event(): Formatted analysis function which is used as- afunin- count_patients_with_event().
- count_patients_with_event(): Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper for- rtables::analyze().
Examples
library(dplyr)
# `s_count_patients_with_event()`
s_count_patients_with_event(
  tern_ex_adae,
  .var = "SUBJID",
  filters = c("TRTEMFL" = "Y")
)
#> $n
#> [1] 164
#> 
#> $count
#> [1] 164
#> 
#> $count_fraction
#> [1] 164   1
#> 
#> $n_blq
#> [1] 0
#> 
s_count_patients_with_event(
  tern_ex_adae,
  .var = "SUBJID",
  filters = c("TRTEMFL" = "Y", "AEOUT" = "FATAL")
)
#> $n
#> [1] 164
#> 
#> $count
#> [1] 79
#> 
#> $count_fraction
#> [1] 79.0000000  0.4817073
#> 
#> $n_blq
#> [1] 0
#> 
s_count_patients_with_event(
  tern_ex_adae,
  .var = "SUBJID",
  filters = c("TRTEMFL" = "Y", "AEOUT" = "FATAL"),
  denom = "N_col",
  .N_col = 456
)
#> $n
#> [1] 164
#> 
#> $count
#> [1] 79
#> 
#> $count_fraction
#> [1] 79.0000000  0.1732456
#> 
#> $n_blq
#> [1] 0
#> 
# `a_count_patients_with_event()`
a_count_patients_with_event(
  tern_ex_adae,
  .var = "SUBJID",
  filters = c("TRTEMFL" = "Y"),
  .N_col = 100,
  .N_row = 100
)
#> RowsVerticalSection (in_rows) object print method:
#> ----------------------------
#>         row_name formatted_cell indent_mod      row_label
#> 1              n            164          0              n
#> 2          count            164          0          count
#> 3 count_fraction     164 (100%)          0 count_fraction
#> 4          n_blq              0          0          n_blq
# `count_patients_with_event()`
lyt <- basic_table() %>%
  split_cols_by("ARM") %>%
  add_colcounts() %>%
  count_values(
    "STUDYID",
    values = "AB12345",
    .stats = "count",
    .labels = c(count = "Total AEs")
  ) %>%
  count_patients_with_event(
    "SUBJID",
    filters = c("TRTEMFL" = "Y"),
    .labels = c(count_fraction = "Total number of patients with at least one adverse event"),
    table_names = "tbl_all"
  ) %>%
  count_patients_with_event(
    "SUBJID",
    filters = c("TRTEMFL" = "Y", "AEOUT" = "FATAL"),
    .labels = c(count_fraction = "Total number of patients with fatal AEs"),
    table_names = "tbl_fatal"
  ) %>%
  count_patients_with_event(
    "SUBJID",
    filters = c("TRTEMFL" = "Y", "AEOUT" = "FATAL", "AEREL" = "Y"),
    .labels = c(count_fraction = "Total number of patients with related fatal AEs"),
    .indent_mods = c(count_fraction = 2L),
    table_names = "tbl_rel_fatal"
  )
build_table(lyt, tern_ex_adae, alt_counts_df = tern_ex_adsl)
#>                                                            A: Drug X    B: Placebo   C: Combination
#>                                                              (N=69)       (N=73)         (N=58)    
#> ———————————————————————————————————————————————————————————————————————————————————————————————————
#> Total AEs                                                     202          177            162      
#> Total number of patients with at least one adverse event   59 (100%)    57 (100%)      48 (100%)   
#> Total number of patients with fatal AEs                    28 (47.5%)   31 (54.4%)     20 (41.7%)  
#>     Total number of patients with related fatal AEs        28 (47.5%)   31 (54.4%)     20 (41.7%)