Counting Patients and Events in Columns
Source:R/count_patients_events_in_cols.R
count_patients_events_in_cols.Rd
Counting the number of unique patients and the total number of all and specific events when a column table layout is required.
Usage
s_count_patients_and_multiple_events(
df,
id,
filters_list,
empty_stats = character(),
labelstr = "",
custom_label = NULL
)
summarize_patients_events_in_cols(
lyt,
id = "USUBJID",
filters_list = list(),
...,
.stats = c("unique", "all", names(filters_list)),
.labels = c(unique = "Patients (All)", all = "Events (All)",
labels_or_names(filters_list)),
col_split = TRUE
)
Arguments
- df
(
data.frame
)
data set containing all analysis variables.- id
(
string
)
subject variable name.- filters_list
(named
list
ofcharacter
)
each element in this list describes one type of event describe by filters, in the same format ass_count_patients_with_event()
. If it has a label, then this will be used for the column title.- empty_stats
(
character
)
optional names of the statistics that should be returned empty such that corresponding table cells will stay blank.- labelstr
(
character
)
label of the level of the parent split currently being summarized (must be present as second argument in Content Row Functions).- custom_label
(
string
orNULL
)
if provided andlabelstr
is empty then this will be used as label.- lyt
(
layout
)
input layout where analyses will be added to.- ...
additional arguments for the lower level functions.
- .stats
(
character
)
statistics to select for the table.- .labels
(named
character
)
labels for the statistics (without indent).- col_split
(
flag
)
whether the columns should be split. Set toFALSE
when the required column split has been done already earlier in the layout pipe.
Value
s_count_patients_and_multiple_events()
returns a list with the statistics:
unique
: number of unique patients indf
.all
: number of rows indf
.one element with the same name as in
filters_list
: number of rows indf
, i.e. events, fulfilling the filter condition.
Functions
s_count_patients_and_multiple_events()
: Statistics function which counts numbers of patients and multiple events defined by filters.summarize_patients_events_in_cols()
: Layout creating function which adds the count statistics of patients and events in the column layout as content rows.
Examples
# `s_count_patients_and_multiple_events()`
df <- data.frame(
USUBJID = rep(c("id1", "id2", "id3", "id4"), c(2, 3, 1, 1)),
ARM = c("A", "A", "B", "B", "B", "B", "A"),
AESER = rep("Y", 7),
AESDTH = c("Y", "Y", "N", "Y", "Y", "N", "N"),
AEREL = c("Y", "Y", "N", "Y", "Y", "N", "Y"),
AEDECOD = c("A", "A", "A", "B", "B", "C", "D"),
AEBODSYS = rep(c("SOC1", "SOC2", "SOC3"), c(3, 3, 1))
)
# Internal function - s_count_patients_and_multiple_events
if (FALSE) {
s_count_patients_and_multiple_events(
df = df,
id = "USUBJID",
filters_list = list(
serious = c(AESER = "Y"),
fatal = c(AESDTH = "Y")
)
)
}
# `summarize_patients_events_in_cols()`
basic_table() %>%
summarize_patients_events_in_cols(
filters_list = list(
related = formatters::with_label(c(AEREL = "Y"), "Events (Related)"),
fatal = c(AESDTH = "Y"),
fatal_related = c(AEREL = "Y", AESDTH = "Y")
),
custom_label = "%s Total number of patients and events"
) %>%
build_table(df)
#> Patients (All) Events (All) Events (Related) fatal fatal_related
#> —————————————————————————————————————————————————————————————————————————————————————————————————————————————————
#> %s Total number of patients and events 4 7 5 4 4