Skip to contents

Functions to score occurrence table subtables and rows which can be used in the sorting of occurrence tables.

[Stable]

Usage

score_occurrences(table_row)

score_occurrences_cols(...)

score_occurrences_subtable(...)

score_occurrences_cont_cols(...)

Arguments

table_row

(TableRow)
an analysis row in a occurrence table.

...

arguments for row or column access, see rtables_access: either col_names (character) including the names of the columns which should be used, or alternatively col_indices (integer) giving the indices directly instead.

Value

score_occurrences() returns the sum of counts across all columns of a table row.

score_occurrences_cols() returns a function that sums counts across all specified columns of a table row.

score_occurrences_subtable() returns a function that sums counts in each subtable across all specified columns.

Functions

  • score_occurrences(): Scoring function which sums the counts across all columns.

  • score_occurrences_cols(): Scoring functions can be produced by this constructor to only include specific columns in the scoring.

  • score_occurrences_subtable(): Scoring functions produced by this constructor can be used on subtables: They sum up all specified column counts in the subtable. This is useful when there is no available content row summing up these counts.

  • score_occurrences_cont_cols(): Produce score function for sorting table by summing the first content row in specified columns. Note that this is extending rtables::cont_n_onecol() and rtables::cont_n_allcols().

Examples


library(scda)
library(rtables)
adsl <- synthetic_cdisc_data("latest")$adsl
adae <- synthetic_cdisc_data("latest")$adae

lyt <- basic_table() %>%
  split_cols_by("ARM") %>%
  add_colcounts() %>%
  summarize_num_patients(
    var = "USUBJID",
    .stats = c("unique"),
    .labels = c("Total number of patients with at least one event")
  ) %>%
  split_rows_by("AEBODSYS", child_labels = "visible", nested = FALSE) %>%
  summarize_num_patients(
    var = "USUBJID",
    .stats = c("unique", "nonunique"),
    .labels = c(
      "Total number of patients with at least one event",
      "Total number of events"
    )
  ) %>%
  count_occurrences(vars = "AEDECOD")

rtable_object <- build_table(lyt, adae, alt_counts_df = adsl) %>%
  prune_table()

rtable_object_sorted <- rtable_object %>%
  sort_at_path(path = c("AEBODSYS", "*", "AEDECOD"), scorefun = score_occurrences)

rtable_object_sorted
#>                                                        A: Drug X    B: Placebo    C: Combination
#>                                                         (N=134)       (N=134)        (N=132)    
#> ————————————————————————————————————————————————————————————————————————————————————————————————
#> Total number of patients with at least one event       122 (91%)    123 (91.8%)    120 (90.9%)  
#>   cl A.1                                                                                        
#>     Total number of patients with at least one event   78 (58.2%)    75 (56%)       89 (67.4%)  
#>     Total number of events                                132           130            160      
#>       dcd A.1.1.1.1                                    50 (37.3%)   45 (33.6%)      63 (47.7%)  
#>       dcd A.1.1.1.2                                    48 (35.8%)   48 (35.8%)      50 (37.9%)  
#>   cl B.1                                                                                        
#>     Total number of patients with at least one event   47 (35.1%)   49 (36.6%)      43 (32.6%)  
#>     Total number of events                                 56           60              62      
#>       dcd B.1.1.1.1                                    47 (35.1%)   49 (36.6%)      43 (32.6%)  
#>   cl B.2                                                                                        
#>     Total number of patients with at least one event    79 (59%)    74 (55.2%)      85 (64.4%)  
#>     Total number of events                                129           138            143      
#>       dcd B.2.2.3.1                                    48 (35.8%)   54 (40.3%)      51 (38.6%)  
#>       dcd B.2.1.2.1                                    49 (36.6%)   44 (32.8%)      52 (39.4%)  
#>   cl C.1                                                                                        
#>     Total number of patients with at least one event   43 (32.1%)   46 (34.3%)      43 (32.6%)  
#>     Total number of events                                 55           63              64      
#>       dcd C.1.1.1.3                                    43 (32.1%)   46 (34.3%)      43 (32.6%)  
#>   cl C.2                                                                                        
#>     Total number of patients with at least one event   35 (26.1%)   48 (35.8%)      55 (41.7%)  
#>     Total number of events                                 48           53              65      
#>       dcd C.2.1.2.1                                    35 (26.1%)   48 (35.8%)      55 (41.7%)  
#>   cl D.1                                                                                        
#>     Total number of patients with at least one event    79 (59%)     67 (50%)       80 (60.6%)  
#>     Total number of events                                127           106            135      
#>       dcd D.1.1.1.1                                    50 (37.3%)   42 (31.3%)      51 (38.6%)  
#>       dcd D.1.1.4.2                                    48 (35.8%)   42 (31.3%)      50 (37.9%)  
#>   cl D.2                                                                                        
#>     Total number of patients with at least one event   47 (35.1%)   58 (43.3%)      57 (43.2%)  
#>     Total number of events                                 62           72              74      
#>       dcd D.2.1.5.3                                    47 (35.1%)   58 (43.3%)      57 (43.2%)  
score_cols_a_and_b <- score_occurrences_cols(col_names = c("A: Drug X", "B: Placebo"))

# Note that this here just sorts the AEDECOD inside the AEBODSYS. The AEBODSYS are not sorted.
# That would require a second pass of `sort_at_path`.
rtable_object_sorted <- rtable_object %>%
  sort_at_path(path = c("AEBODSYS", "*", "AEDECOD"), scorefun = score_cols_a_and_b)

rtable_object_sorted
#>                                                        A: Drug X    B: Placebo    C: Combination
#>                                                         (N=134)       (N=134)        (N=132)    
#> ————————————————————————————————————————————————————————————————————————————————————————————————
#> Total number of patients with at least one event       122 (91%)    123 (91.8%)    120 (90.9%)  
#>   cl A.1                                                                                        
#>     Total number of patients with at least one event   78 (58.2%)    75 (56%)       89 (67.4%)  
#>     Total number of events                                132           130            160      
#>       dcd A.1.1.1.2                                    48 (35.8%)   48 (35.8%)      50 (37.9%)  
#>       dcd A.1.1.1.1                                    50 (37.3%)   45 (33.6%)      63 (47.7%)  
#>   cl B.1                                                                                        
#>     Total number of patients with at least one event   47 (35.1%)   49 (36.6%)      43 (32.6%)  
#>     Total number of events                                 56           60              62      
#>       dcd B.1.1.1.1                                    47 (35.1%)   49 (36.6%)      43 (32.6%)  
#>   cl B.2                                                                                        
#>     Total number of patients with at least one event    79 (59%)    74 (55.2%)      85 (64.4%)  
#>     Total number of events                                129           138            143      
#>       dcd B.2.2.3.1                                    48 (35.8%)   54 (40.3%)      51 (38.6%)  
#>       dcd B.2.1.2.1                                    49 (36.6%)   44 (32.8%)      52 (39.4%)  
#>   cl C.1                                                                                        
#>     Total number of patients with at least one event   43 (32.1%)   46 (34.3%)      43 (32.6%)  
#>     Total number of events                                 55           63              64      
#>       dcd C.1.1.1.3                                    43 (32.1%)   46 (34.3%)      43 (32.6%)  
#>   cl C.2                                                                                        
#>     Total number of patients with at least one event   35 (26.1%)   48 (35.8%)      55 (41.7%)  
#>     Total number of events                                 48           53              65      
#>       dcd C.2.1.2.1                                    35 (26.1%)   48 (35.8%)      55 (41.7%)  
#>   cl D.1                                                                                        
#>     Total number of patients with at least one event    79 (59%)     67 (50%)       80 (60.6%)  
#>     Total number of events                                127           106            135      
#>       dcd D.1.1.1.1                                    50 (37.3%)   42 (31.3%)      51 (38.6%)  
#>       dcd D.1.1.4.2                                    48 (35.8%)   42 (31.3%)      50 (37.9%)  
#>   cl D.2                                                                                        
#>     Total number of patients with at least one event   47 (35.1%)   58 (43.3%)      57 (43.2%)  
#>     Total number of events                                 62           72              74      
#>       dcd D.2.1.5.3                                    47 (35.1%)   58 (43.3%)      57 (43.2%)  
score_subtable_all <- score_occurrences_subtable(col_names = names(rtable_object))

# Note that this code just sorts the AEBODSYS, not the AEDECOD within AEBODSYS. That
# would require a second pass of `sort_at_path`.
rtable_object_sorted <- rtable_object %>%
  sort_at_path(path = c("AEBODSYS"), scorefun = score_subtable_all, decreasing = FALSE)

rtable_object_sorted
#>                                                        A: Drug X    B: Placebo    C: Combination
#>                                                         (N=134)       (N=134)        (N=132)    
#> ————————————————————————————————————————————————————————————————————————————————————————————————
#> Total number of patients with at least one event       122 (91%)    123 (91.8%)    120 (90.9%)  
#>   cl C.2                                                                                        
#>     Total number of patients with at least one event   35 (26.1%)   48 (35.8%)      55 (41.7%)  
#>     Total number of events                                 48           53              65      
#>       dcd C.2.1.2.1                                    35 (26.1%)   48 (35.8%)      55 (41.7%)  
#>   cl C.1                                                                                        
#>     Total number of patients with at least one event   43 (32.1%)   46 (34.3%)      43 (32.6%)  
#>     Total number of events                                 55           63              64      
#>       dcd C.1.1.1.3                                    43 (32.1%)   46 (34.3%)      43 (32.6%)  
#>   cl B.1                                                                                        
#>     Total number of patients with at least one event   47 (35.1%)   49 (36.6%)      43 (32.6%)  
#>     Total number of events                                 56           60              62      
#>       dcd B.1.1.1.1                                    47 (35.1%)   49 (36.6%)      43 (32.6%)  
#>   cl D.2                                                                                        
#>     Total number of patients with at least one event   47 (35.1%)   58 (43.3%)      57 (43.2%)  
#>     Total number of events                                 62           72              74      
#>       dcd D.2.1.5.3                                    47 (35.1%)   58 (43.3%)      57 (43.2%)  
#>   cl D.1                                                                                        
#>     Total number of patients with at least one event    79 (59%)     67 (50%)       80 (60.6%)  
#>     Total number of events                                127           106            135      
#>       dcd D.1.1.1.1                                    50 (37.3%)   42 (31.3%)      51 (38.6%)  
#>       dcd D.1.1.4.2                                    48 (35.8%)   42 (31.3%)      50 (37.9%)  
#>   cl B.2                                                                                        
#>     Total number of patients with at least one event    79 (59%)    74 (55.2%)      85 (64.4%)  
#>     Total number of events                                129           138            143      
#>       dcd B.2.1.2.1                                    49 (36.6%)   44 (32.8%)      52 (39.4%)  
#>       dcd B.2.2.3.1                                    48 (35.8%)   54 (40.3%)      51 (38.6%)  
#>   cl A.1                                                                                        
#>     Total number of patients with at least one event   78 (58.2%)    75 (56%)       89 (67.4%)  
#>     Total number of events                                132           130            160      
#>       dcd A.1.1.1.1                                    50 (37.3%)   45 (33.6%)      63 (47.7%)  
#>       dcd A.1.1.1.2                                    48 (35.8%)   48 (35.8%)      50 (37.9%)