tbl_shift | R Documentation |
Typical use is tabulating post-baseline measurement stratified by the baseline measurement.
tbl_shift(
data,
variable,
strata = NULL,
by = NULL,
data_header = NULL,
strata_location = c("new_column", "header"),
strata_label = "{strata}",
header = "{level} \nN = {n}",
label = NULL,
nonmissing = "always",
nonmissing_text = "Total",
...
)
## S3 method for class 'tbl_shift'
add_overall(
x,
col_label = "All Participants \n(N = {gtsummary::style_number(n)})",
last = FALSE,
...
)
data |
( |
variable |
( |
strata |
( |
by |
( |
data_header |
( |
strata_location |
( |
strata_label |
( |
header |
( |
label |
( |
nonmissing , nonmissing_text , ... |
Argument passed to |
x |
( |
col_label |
( |
last |
(scalar |
Broadly, this function is a wrapper for chunk below with some additional
calls to gtsummary::modify_*()
function to update the table's
headers, indentation, column alignment, etc.
gtsummary::tbl_strata2( data = data, strata = strata, ~ tbl_roche_summary(.x, include = variable, by = by) )
a 'gtsummary' table
library(dplyr, warn.conflicts = FALSE)
# subsetting ADLB on one PARAM, and the highest grade
adlb <- pharmaverseadam::adlb |>
select("USUBJID", "TRT01A", "PARAM", "PARAMCD", "ATOXGRH", "BTOXGRH", "VISITNUM") |>
mutate(TRT01A = factor(TRT01A)) |>
filter(PARAMCD %in% c("CHOLES", "GLUC")) |>
slice_max(by = c(USUBJID, PARAMCD), order_by = ATOXGRH, n = 1L, with_ties = FALSE) |>
labelled::set_variable_labels(
BTOXGRH = "Baseline \nNCI-CTCAE Grade",
ATOXGRH = "Post-baseline \nNCI-CTCAE Grade"
)
adsl <- pharmaverseadam::adsl[c("USUBJID", "TRT01A")] |>
filter(TRT01A != "Screen Failure")
# Example 1 ----------------------------------
# tabulate baseline grade by worst grade
tbl_shift(
data = filter(adlb, PARAMCD %in% "CHOLES"),
strata = BTOXGRH,
variable = ATOXGRH,
by = TRT01A,
data_header = adsl
)
# Example 2 ----------------------------------
# same as Ex1, but with the stratifying variable levels in header rows
adlb |>
filter(PARAMCD %in% "CHOLES") |>
labelled::set_variable_labels(
BTOXGRH = "Baseline NCI-CTCAE Grade",
ATOXGRH = "Post-baseline NCI-CTCAE Grade"
) |>
tbl_shift(
data = ,
strata = BTOXGRH,
variable = ATOXGRH,
strata_location = "header",
by = TRT01A,
data_header = adsl
)
# Example 3 ----------------------------------
# same as Ex2, but with two labs
adlb |>
labelled::set_variable_labels(
BTOXGRH = "Baseline NCI-CTCAE Grade",
ATOXGRH = "Post-baseline NCI-CTCAE Grade"
) |>
tbl_strata_nested_stack(
strata = PARAM,
~ .x |>
tbl_shift(
strata = BTOXGRH,
variable = ATOXGRH,
strata_location = "header",
by = TRT01A,
data_header = adsl
)
) |>
# Update header with Lab header and indentation (the '\U00A0' character adds whitespace)
modify_header(
label = "Lab \n\U00A0\U00A0\U00A0\U00A0
Baseline NCI-CTCAE Grade \n\U00A0\U00A0\U00A0\U00A0\U00A0\U00A0\U00A0\U00A0
Post-baseline NCI-CTCAE Grade"
)
# Example 4 ----------------------------------
# Include the treatment variable in a new column
filter(adlb, PARAMCD %in% "CHOLES") |>
right_join(
pharmaverseadam::adsl[c("USUBJID", "TRT01A")] |>
filter(TRT01A != "Screen Failure"),
by = c("USUBJID", "TRT01A")
) |>
tbl_shift(
strata = TRT01A,
variable = BTOXGRH,
by = ATOXGRH,
header = "{level}",
strata_label = "{strata}, N={n}",
label = list(TRT01A = "Actual Treatment"),
percent = "cell",
nonmissing = "no"
) |>
modify_spanning_header(all_stat_cols() ~ "Worst Post-baseline NCI-CTCAE Grade")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.