count_occurrences {tern} | R Documentation |
Occurrence counts
Description
Functions for analyzing frequencies and fractions of occurrences for patients with occurrence data. Primary analysis variables are the dictionary terms. All occurrences are counted for total counts. Multiple occurrences within patient at the lowest term level displayed in the table are counted only once.
Usage
count_occurrences(
lyt,
vars,
id = "USUBJID",
drop = TRUE,
var_labels = vars,
show_labels = "hidden",
riskdiff = FALSE,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = vars,
.stats = "count_fraction_fixed_dp",
.formats = NULL,
.labels = NULL,
.indent_mods = NULL
)
summarize_occurrences(
lyt,
var,
id = "USUBJID",
drop = TRUE,
riskdiff = FALSE,
na_str = default_na_str(),
...,
.stats = "count_fraction_fixed_dp",
.formats = NULL,
.indent_mods = NULL,
.labels = NULL
)
s_count_occurrences(
df,
denom = c("N_col", "n"),
.N_col,
.df_row,
drop = TRUE,
.var = "MHDECOD",
id = "USUBJID"
)
a_count_occurrences(
df,
labelstr = "",
id = "USUBJID",
denom = c("N_col", "n"),
drop = TRUE,
.N_col,
.var = NULL,
.df_row = NULL,
.stats = NULL,
.formats = NULL,
.labels = NULL,
.indent_mods = NULL,
na_str = default_na_str()
)
Arguments
lyt |
( |
vars |
( |
id |
( |
drop |
( |
var_labels |
( |
show_labels |
( |
riskdiff |
( |
na_str |
( |
nested |
( |
... |
additional arguments for the lower level functions. |
table_names |
( |
.stats |
( |
.formats |
(named |
.labels |
(named |
.indent_mods |
(named |
df |
( |
denom |
(
|
.N_col |
( |
.df_row |
( |
.var , var |
( |
labelstr |
( |
Value
-
count_occurrences()
returns a layout object suitable for passing to further layouting functions, or tortables::build_table()
. Adding this function to anrtable
layout will add formatted rows containing the statistics froms_count_occurrences()
to the table layout.
-
summarize_occurrences()
returns a layout object suitable for passing to further layouting functions, or tortables::build_table()
. Adding this function to anrtable
layout will add formatted content rows containing the statistics froms_count_occurrences()
to the table layout.
-
s_count_occurrences()
returns a list with:-
count
: list of counts with one element per occurrence. -
count_fraction
: list of counts and fractions with one element per occurrence. -
fraction
: list of numerators and denominators with one element per occurrence.
-
-
a_count_occurrences()
returns the corresponding list with formattedrtables::CellValue()
.
Functions
-
count_occurrences()
: Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper forrtables::analyze()
. -
summarize_occurrences()
: Layout-creating function which can take content function arguments and additional format arguments. This function is a wrapper forrtables::summarize_row_groups()
. -
s_count_occurrences()
: Statistics function which counts number of patients that report an occurrence. -
a_count_occurrences()
: Formatted analysis function which is used asafun
incount_occurrences()
.
Note
By default, occurrences which don't appear in a given row split are dropped from the table and
the occurrences in the table are sorted alphabetically per row split. Therefore, the corresponding layout
needs to use split_fun = drop_split_levels
in the split_rows_by
calls. Use drop = FALSE
if you would
like to show all occurrences.
Examples
library(dplyr)
df <- data.frame(
USUBJID = as.character(c(
1, 1, 2, 4, 4, 4,
6, 6, 6, 7, 7, 8
)),
MHDECOD = c(
"MH1", "MH2", "MH1", "MH1", "MH1", "MH3",
"MH2", "MH2", "MH3", "MH1", "MH2", "MH4"
),
ARM = rep(c("A", "B"), each = 6),
SEX = c("F", "F", "M", "M", "M", "M", "F", "F", "F", "M", "M", "F")
)
df_adsl <- df %>%
select(USUBJID, ARM) %>%
unique()
# Create table layout
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
add_colcounts() %>%
count_occurrences(vars = "MHDECOD", .stats = c("count_fraction"))
# Apply table layout to data and produce `rtable` object
tbl <- lyt %>%
build_table(df, alt_counts_df = df_adsl) %>%
prune_table()
tbl
# Layout creating function with custom format.
basic_table() %>%
add_colcounts() %>%
split_rows_by("SEX", child_labels = "visible") %>%
summarize_occurrences(
var = "MHDECOD",
.formats = c("count_fraction" = "xx.xx (xx.xx%)")
) %>%
build_table(df, alt_counts_df = df_adsl)
# Count unique occurrences per subject.
s_count_occurrences(
df,
.N_col = 4L,
.df_row = df,
.var = "MHDECOD",
id = "USUBJID"
)
a_count_occurrences(
df,
.N_col = 4L,
.df_row = df,
.var = "MHDECOD",
id = "USUBJID"
)