Usage
s_num_patients(
x,
labelstr,
.N_col,
count_by = NULL,
unique_count_suffix = TRUE
)
s_num_patients_content(
df,
labelstr = "",
.N_col,
.var,
required = NULL,
count_by = NULL,
unique_count_suffix = TRUE
)
summarize_num_patients(
lyt,
var,
.stats = NULL,
.formats = NULL,
.labels = c(unique = "Number of patients with at least one event", nonunique =
"Number of events"),
indent_mod = 0L,
...
)
analyze_num_patients(
lyt,
vars,
.stats = NULL,
.formats = NULL,
.labels = c(unique = "Number of patients with at least one event", nonunique =
"Number of events"),
show_labels = c("default", "visible", "hidden"),
indent_mod = 0L,
...
)
Arguments
- x
(
character
orfactor
)
vector of patient IDs.- labelstr
(
character
)
label of the level of the parent split currently being summarized (must be present as second argument in Content Row Functions).- .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 byrtables
.- count_by
(
character
orfactor
)
optional vector to be combined withx
when countingnonunique
records.- unique_count_suffix
(
logical
)
should"(n)"
suffix be added tounique_count
labels. Defaults toTRUE
.- df
(
data.frame
)
data set containing all analysis variables.- .var, var
(
string
)
single variable name that is passed byrtables
when requested by a statistics function.- required
(
character
orNULL
)
optional name of a variable that is required to be non-missing.- lyt
(
layout
)
input layout where analyses will be added to.- .stats
(
character
)
statistics to select for the table.- .formats
(named
character
orlist
)
formats for the statistics.- .labels
(named
character
)
labels for the statistics (without indent).- indent_mod
(
count
)
it can be negative. Modifier for the default indent position for the structure created by this function(subtable, content table, or row) and all of that structure's children. Defaults to 0, which corresponds to the unmodified default behavior.- ...
additional arguments for the lower level functions.
- vars
(
character
)
variable names for the primary analysis variable to be iterated over.- show_labels
label visibility: one of "default", "visible" and "hidden".
Value
A list with:
- unique
vector of count and percentage.
- nonunique
vector of count.
- unique_count
count.
Details
In general, functions that starts with analyze*
are expected to
work like rtables::analyze()
, while functions that starts with summarize*
are based upon rtables::summarize_row_groups()
. The latter provides a
value for each dividing split in the row and column space, but, being it
bound to the fundamental splits, it is repeated by design in every page
when pagination is involved.
Functions
s_num_patients()
: Statistics function which counts the number of unique patients, the corresponding percentage taken with respect to the total number of patients, and the number of non-unique patients.s_num_patients_content()
: Counts the number of unique patients in a column (variable), the corresponding percentage taken with respect to the total number of patients, and the number of non-unique patients in the column. Function serves as a wrapper that carries over both expected argumentsdf
andlabelstr
incfun
ofsummarize_row_groups()
.summarize_num_patients()
: Layout creating function which adds content rows using the statistics functions_num_patients_content()
and desired format.analyze_num_patients()
: Identically tosummarize_num_patients()
, This function creates a layout which adds content rows using the statistics functions_num_patients_content()
and desired format. Differently from its counterpart, this function does not impose the produced rows to be repeated.
Examples
# Use the statistics function to count number of unique and nonunique patients.
s_num_patients(x = as.character(c(1, 1, 1, 2, 4, NA)), labelstr = "", .N_col = 6L)
#> $unique
#> [1] 3.0 0.5
#> attr(,"label")
#> [1] ""
#>
#> $nonunique
#> [1] 5
#> attr(,"label")
#> [1] ""
#>
#> $unique_count
#> [1] 3
#> attr(,"label")
#> [1] " (n)"
#>
s_num_patients(
x = as.character(c(1, 1, 1, 2, 4, NA)),
labelstr = "",
.N_col = 6L,
count_by = as.character(c(1, 1, 2, 1, 1, 1))
)
#> $unique
#> [1] 3.0 0.5
#> attr(,"label")
#> [1] ""
#>
#> $nonunique
#> [1] 4
#> attr(,"label")
#> [1] ""
#>
#> $unique_count
#> [1] 3
#> attr(,"label")
#> [1] " (n)"
#>
# Count number of unique and non-unique patients.
df <- data.frame(
USUBJID = as.character(c(1, 2, 1, 4, NA)),
EVENT = as.character(c(10, 15, 10, 17, 8))
)
s_num_patients_content(df, .N_col = 5, .var = "USUBJID")
#> $unique
#> [1] 3.0 0.6
#> attr(,"label")
#> [1] ""
#>
#> $nonunique
#> [1] 4
#> attr(,"label")
#> [1] ""
#>
#> $unique_count
#> [1] 3
#> attr(,"label")
#> [1] " (n)"
#>
df_by_event <- data.frame(
USUBJID = as.character(c(1, 2, 1, 4, NA)),
EVENT = as.character(c(10, 15, 10, 17, 8))
)
s_num_patients_content(df_by_event, .N_col = 5, .var = "USUBJID")
#> $unique
#> [1] 3.0 0.6
#> attr(,"label")
#> [1] ""
#>
#> $nonunique
#> [1] 4
#> attr(,"label")
#> [1] ""
#>
#> $unique_count
#> [1] 3
#> attr(,"label")
#> [1] " (n)"
#>
s_num_patients_content(df_by_event, .N_col = 5, .var = "USUBJID", count_by = "EVENT")
#> $unique
#> [1] 3.0 0.6
#> attr(,"label")
#> [1] ""
#>
#> $nonunique
#> [1] 3
#> attr(,"label")
#> [1] ""
#>
#> $unique_count
#> [1] 3
#> attr(,"label")
#> [1] " (n)"
#>
df_tmp <- data.frame(
USUBJID = as.character(c(1, 2, 1, 4, NA, 6, 6, 8, 9)),
ARM = c("A", "A", "A", "A", "A", "B", "B", "B", "B"),
AGE = c(10, 15, 10, 17, 8, 11, 11, 19, 17)
)
tbl <- basic_table() %>%
split_cols_by("ARM") %>%
add_colcounts() %>%
analyze_num_patients("USUBJID", .stats = c("unique")) %>%
build_table(df_tmp)
tbl
#> A B
#> (N=5) (N=4)
#> ——————————————————————————————————————————————————————————————————
#> Number of patients with at least one event 3 (60.0%) 3 (75.0%)