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,
  ...
)

Arguments

data

(data.frame)
A data frame.

variable

(tidy-select)
Variable to tabulate. Typically the post-baseline grade.

strata

(tidy-select)
Stratifying variable. Typically the baseline grade.

by

(tidy-select)
Variable to report results by. Typical value is the treatment arm.

data_header

(data.frame)
Data frame used to calculate the Ns in the table header. Only include the columns needed to merge with data: these are typically the 'USUBJID' and the treatment arm only, e.g ADSL[c("USUBJID", "ARM")].

strata_location

(string)
Specifies the location where the individual stratum levels will be printed. Must be one of c("new_column", "header"). "new_column": stratum labels are placed in a new column to the left of the tabulated results. "header": stratum labels are placed in a header row above the tabulations.

strata_label

(string)
A glue-string that inserts stratum level. Default is '{strata}', and {n} is also available to insert.

header

(string)
String that is passed to gtsummary::modify_header(all_stat_cols() ~ header).

label

(formula-list-selector)
Used to specify the labels for the strata and variable columns. Default is to use the column label attribute.

nonmissing, nonmissing_text, ...

Argument passed to tbl_roche_summary(). See details below for call details to tbl_roche_summary().

x

(tbl_shift)
Object of class 'tbl_shift'.

col_label

(string)
String indicating the column label. Default is "All Participants \nN = {gtsummary::style_number(n)}"

last

(scalar logical)
Logical indicator to display overall column last in table. Default is FALSE, which will display overall column first.

Value

a 'gtsummary' table

Details

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)
)

Examples

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
)
Baseline
NCI-CTCAE Grade
Post-baseline
NCI-CTCAE Grade
Placebo
N = 86
Xanomeline High Dose
N = 72
Xanomeline Low Dose
N = 96
0 Total 81 70 94

0 77 (95.1%) 66 (94.3%) 91 (96.8%)

1 2 (2.5%) 4 (5.7%) 1 (1.1%)

2 2 (2.5%) 0 2 (2.1%)
1 Total 0 0 1

1 0 0 1 (100%)
2 Total 5 2 1

2 5 (100%) 2 (100%) 1 (100%)
# 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 )
Baseline NCI-CTCAE Grade
    Post-baseline NCI-CTCAE Grade
Placebo
N = 86
Xanomeline High Dose
N = 72
Xanomeline Low Dose
N = 96
0


    Total 81 70 94
    0 77 (95.1%) 66 (94.3%) 91 (96.8%)
    1 2 (2.5%) 4 (5.7%) 1 (1.1%)
    2 2 (2.5%) 0 2 (2.1%)
1


    Total 0 0 1
    1 0 0 1 (100%)
2


    Total 5 2 1
    2 5 (100%) 2 (100%) 1 (100%)
# 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" )
Lab
     Baseline NCI-CTCAE Grade
         Post-baseline NCI-CTCAE Grade
Placebo
N = 86
Xanomeline High Dose
N = 72
Xanomeline Low Dose
N = 96
Cholesterol (mmol/L)


    0


        Total 81 70 94
        0 77 (95.1%) 66 (94.3%) 91 (96.8%)
        1 2 (2.5%) 4 (5.7%) 1 (1.1%)
        2 2 (2.5%) 0 2 (2.1%)
    1


        Total 0 0 1
        1 0 0 1 (100%)
    2


        Total 5 2 1
        2 5 (100%) 2 (100%) 1 (100%)
Glucose (mmol/L)


    0


        Total 85 72 96
        0 84 (98.8%) 66 (91.7%) 95 (99.0%)
        3 1 (1.2%) 6 (8.3%) 1 (1.0%)
    3


        Total 1 0 0
        3 1 (100%) 0 0
# 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") #> Converting column "ATOXGRH" to a factor.
Actual Treatment Baseline
NCI-CTCAE Grade
Worst Post-baseline NCI-CTCAE Grade
0 1 2
Placebo, N=86 0 77 (89.5%) 2 (2.3%) 2 (2.3%)

2 0 0 5 (5.8%)
Xanomeline High Dose, N=72 0 66 (91.7%) 4 (5.6%) 0

2 0 0 2 (2.8%)
Xanomeline Low Dose, N=96 0 91 (94.8%) 1 (1.0%) 2 (2.1%)

1 0 1 (1.0%) 0

2 0 0 1 (1.0%)