Skip to contents

Constructor function which creates a combined Formatted Analysis function for use in layout creating functions summarize_vars() and summarize_colvars().

Usage

create_afun_summary(.stats, .formats, .labels, .indent_mods)

Arguments

.stats

(character)
statistics to select for the table.

.formats

(named character or list)
formats for the statistics.

.labels

(named character)
labels for the statistics (without indent).

.indent_mods

(named integer)
indent modifiers for the labels.

Note

Since a_summary() is generic and we want customization of the formatting arguments via rtables::make_afun(), we need to create another temporary generic function, with corresponding customized methods. Then in order for the methods to be found, we need to wrap them in a combined afun. Since this is required by two layout creating functions (and possibly others in the future), we provide a constructor that does this: create_afun_summary().

Examples

# `create_afun_summary()` to create combined `afun`

afun <- create_afun_summary(
  .stats = NULL,
  .formats = c(median = "xx."),
  .labels = c(median = "My median"),
  .indent_mods = c(median = 1L)
)
## Fabricated dataset.
dta_test <- data.frame(
  USUBJID = rep(1:6, each = 3),
  PARAMCD = rep("lab", 6 * 3),
  AVISIT  = rep(paste0("V", 1:3), 6),
  ARM     = rep(LETTERS[1:3], rep(6, 3)),
  AVAL    = c(9:1, rep(NA, 9))
)

l <- basic_table() %>%
  split_cols_by(var = "ARM") %>%
  split_rows_by(var = "AVISIT") %>%
  analyze(vars = "AVAL", afun = afun)

build_table(l, df = dta_test)
#>                                        A              B       C 
#> ————————————————————————————————————————————————————————————————
#> V1                                                              
#>   n                                    2              1       0 
#>   Sum                                15.0            3.0      NA
#>   Mean                                7.5            3.0      NA
#>   SD                                  2.1            NA       NA
#>   SE                                  1.5            NA       NA
#>   Mean (SD)                        7.5 (2.1)      3.0 (NA)    NA
#>   Mean (SE)                        7.5 (1.5)      3.0 (NA)    NA
#>   Mean 95% CI                   (-11.56, 26.56)      NA       NA
#>   Mean -/+ 1xSE                  (6.00, 9.00)        NA       NA
#>   Mean -/+ 1xSD                  (5.38, 9.62)        NA       NA
#>   Mean p-value (H0: mean = 0)        0.13            NA       NA
#>     My median                          8              3       NA
#>   Median Absolute Deviation           0.0            0.0      NA
#>   Median 95% CI                       NA             NA       NA
#>   25% and 75%-ile                  6.0 - 9.0      3.0 - 3.0   NA
#>   IQR                                 3.0            0.0      NA
#>   Min - Max                        6.0 - 9.0      3.0 - 3.0   NA
#>   CV (%)                             28.3            NA       NA
#>   Minimum                             6.0            3.0      NA
#>   Maximum                             9.0            3.0      NA
#>   Geometric Mean                      7.3            3.0      NA
#>   CV % Geometric Mean                29.3            NA       NA
#> V2                                                              
#>   n                                    2              1       0 
#>   Sum                                13.0            2.0      NA
#>   Mean                                6.5            2.0      NA
#>   SD                                  2.1            NA       NA
#>   SE                                  1.5            NA       NA
#>   Mean (SD)                        6.5 (2.1)      2.0 (NA)    NA
#>   Mean (SE)                        6.5 (1.5)      2.0 (NA)    NA
#>   Mean 95% CI                   (-12.56, 25.56)      NA       NA
#>   Mean -/+ 1xSE                  (5.00, 8.00)        NA       NA
#>   Mean -/+ 1xSD                  (4.38, 8.62)        NA       NA
#>   Mean p-value (H0: mean = 0)        0.14            NA       NA
#>     My median                          6              2       NA
#>   Median Absolute Deviation           0.0            0.0      NA
#>   Median 95% CI                       NA             NA       NA
#>   25% and 75%-ile                  5.0 - 8.0      2.0 - 2.0   NA
#>   IQR                                 3.0            0.0      NA
#>   Min - Max                        5.0 - 8.0      2.0 - 2.0   NA
#>   CV (%)                             32.6            NA       NA
#>   Minimum                             5.0            2.0      NA
#>   Maximum                             8.0            2.0      NA
#>   Geometric Mean                      6.3            2.0      NA
#>   CV % Geometric Mean                34.2            NA       NA
#> V3                                                              
#>   n                                    2              1       0 
#>   Sum                                11.0            1.0      NA
#>   Mean                                5.5            1.0      NA
#>   SD                                  2.1            NA       NA
#>   SE                                  1.5            NA       NA
#>   Mean (SD)                        5.5 (2.1)      1.0 (NA)    NA
#>   Mean (SE)                        5.5 (1.5)      1.0 (NA)    NA
#>   Mean 95% CI                   (-13.56, 24.56)      NA       NA
#>   Mean -/+ 1xSE                  (4.00, 7.00)        NA       NA
#>   Mean -/+ 1xSD                  (3.38, 7.62)        NA       NA
#>   Mean p-value (H0: mean = 0)        0.17            NA       NA
#>     My median                          6              1       NA
#>   Median Absolute Deviation           0.0            0.0      NA
#>   Median 95% CI                       NA             NA       NA
#>   25% and 75%-ile                  4.0 - 7.0      1.0 - 1.0   NA
#>   IQR                                 3.0            0.0      NA
#>   Min - Max                        4.0 - 7.0      1.0 - 1.0   NA
#>   CV (%)                             38.6            NA       NA
#>   Minimum                             4.0            1.0      NA
#>   Maximum                             7.0            1.0      NA
#>   Geometric Mean                      5.3            1.0      NA
#>   CV % Geometric Mean                41.2            NA       NA