count_occurrences_by_grade {tern} | R Documentation |
Occurrence counts by grade
Description
Functions for analyzing frequencies and fractions of occurrences by grade for patients with occurrence data. Multiple occurrences within one individual are counted once at the greatest intensity/highest grade level.
Usage
count_occurrences_by_grade(
lyt,
var,
id = "USUBJID",
grade_groups = list(),
remove_single = TRUE,
only_grade_groups = FALSE,
var_labels = var,
show_labels = "default",
riskdiff = FALSE,
na_str = default_na_str(),
nested = TRUE,
...,
table_names = var,
.stats = NULL,
.formats = NULL,
.indent_mods = NULL,
.labels = NULL
)
summarize_occurrences_by_grade(
lyt,
var,
id = "USUBJID",
grade_groups = list(),
remove_single = TRUE,
only_grade_groups = FALSE,
na_str = default_na_str(),
...,
.stats = NULL,
.formats = NULL,
.indent_mods = NULL,
.labels = NULL
)
s_count_occurrences_by_grade(
df,
.var,
.N_col,
id = "USUBJID",
grade_groups = list(),
remove_single = TRUE,
only_grade_groups = FALSE,
labelstr = ""
)
a_count_occurrences_by_grade(
df,
.var,
.N_col,
id = "USUBJID",
grade_groups = list(),
remove_single = TRUE,
only_grade_groups = FALSE,
labelstr = ""
)
Arguments
lyt |
( |
id |
( |
grade_groups |
(named |
remove_single |
( |
only_grade_groups |
( |
var_labels |
( |
show_labels |
( |
riskdiff |
( |
na_str |
( |
nested |
( |
... |
additional arguments for the lower level functions. |
table_names |
( |
.stats |
( |
.formats |
(named |
.indent_mods |
(named |
.labels |
(named |
df |
( |
.var , var |
( |
.N_col |
( |
labelstr |
( |
Value
-
count_occurrences_by_grade()
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_by_grade()
to the table layout.
-
summarize_occurrences_by_grade()
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_by_grade()
to the table layout.
-
s_count_occurrences_by_grade()
returns a list of counts and fractions with one element per grade level or grade level grouping.
-
a_count_occurrences_by_grade()
returns the corresponding list with formattedrtables::CellValue()
.
Functions
-
count_occurrences_by_grade()
: Layout-creating function which can take statistics function arguments and additional format arguments. This function is a wrapper forrtables::analyze()
. -
summarize_occurrences_by_grade()
: 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_by_grade()
: Statistics function which counts the number of patients by highest grade. -
a_count_occurrences_by_grade()
: Formatted analysis function which is used asafun
incount_occurrences_by_grade()
.
See Also
Relevant helper function h_append_grade_groups()
.
Examples
library(dplyr)
df <- data.frame(
USUBJID = as.character(c(1:6, 1)),
ARM = factor(c("A", "A", "A", "B", "B", "B", "A"), levels = c("A", "B")),
AETOXGR = factor(c(1, 2, 3, 4, 1, 2, 3), levels = c(1:5)),
AESEV = factor(
x = c("MILD", "MODERATE", "SEVERE", "MILD", "MILD", "MODERATE", "SEVERE"),
levels = c("MILD", "MODERATE", "SEVERE")
),
stringsAsFactors = FALSE
)
df_adsl <- df %>%
select(USUBJID, ARM) %>%
unique()
# Layout creating function with custom format.
basic_table() %>%
split_cols_by("ARM") %>%
add_colcounts() %>%
count_occurrences_by_grade(
var = "AESEV",
.formats = c("count_fraction" = "xx.xx (xx.xx%)")
) %>%
build_table(df, alt_counts_df = df_adsl)
# Define additional grade groupings.
grade_groups <- list(
"-Any-" = c("1", "2", "3", "4", "5"),
"Grade 1-2" = c("1", "2"),
"Grade 3-5" = c("3", "4", "5")
)
basic_table() %>%
split_cols_by("ARM") %>%
add_colcounts() %>%
count_occurrences_by_grade(
var = "AETOXGR",
grade_groups = grade_groups,
only_grade_groups = TRUE
) %>%
build_table(df, alt_counts_df = df_adsl)
# Layout creating function with custom format.
basic_table() %>%
add_colcounts() %>%
split_rows_by("ARM", child_labels = "visible", nested = TRUE) %>%
summarize_occurrences_by_grade(
var = "AESEV",
.formats = c("count_fraction" = "xx.xx (xx.xx%)")
) %>%
build_table(df, alt_counts_df = df_adsl)
basic_table() %>%
add_colcounts() %>%
split_rows_by("ARM", child_labels = "visible", nested = TRUE) %>%
summarize_occurrences_by_grade(
var = "AETOXGR",
grade_groups = grade_groups
) %>%
build_table(df, alt_counts_df = df_adsl)
s_count_occurrences_by_grade(
df,
.N_col = 10L,
.var = "AETOXGR",
id = "USUBJID",
grade_groups = list("ANY" = levels(df$AETOXGR))
)
# We need to ungroup `count_fraction` first so that the `rtables` formatting
# function `format_count_fraction()` can be applied correctly.
afun <- make_afun(a_count_occurrences_by_grade, .ungroup_stats = "count_fraction")
afun(
df,
.N_col = 10L,
.var = "AETOXGR",
id = "USUBJID",
grade_groups = list("ANY" = levels(df$AETOXGR))
)