Skip to contents

[Stable]

Functions to retrieve default settings for summary statistics and customize these settings.

Usage

summary_formats(type = "numeric", include_pval = FALSE)

summary_labels(type = "numeric", include_pval = FALSE)

summary_custom(
  type = "numeric",
  include_pval = FALSE,
  stats_custom = NULL,
  formats_custom = NULL,
  labels_custom = NULL,
  indent_mods_custom = NULL
)

Arguments

type

(character)
choice of summary data type. Only counts and numeric types are currently supported.

include_pval

(logical)
whether p-value should be included as a default statistic.

stats_custom

(named vector of character)
vector of statistics to include if not the defaults. This argument overrides include_pval and other custom value arguments such that only settings for these statistics will be returned.

formats_custom

(named vector of character)
vector of custom statistics formats to use in place of the defaults defined in summary_formats(). Names should be a subset of the statistics defined in stats_custom (or default statistics if this is NULL).

labels_custom

(named vector of character)
vector of custom statistics labels to use in place of the defaults defined in summary_labels(). Names should be a subset of the statistics defined in stats_custom (or default statistics if this is NULL).

indent_mods_custom

(integer or named vector of integer)
vector of custom indentation modifiers for statistics to use instead of the default of 0L for all statistics. Names should be a subset of the statistics defined in stats_custom (or default statistics if this is NULL). Alternatively, the same indentation modifier can be applied to all statistics by setting indent_mods_custom to a single integer value.

Value

  • summary_formats returns a named vector of default statistic formats for the given data type.

  • summary_labels returns a named vector of default statistic labels for the given data type.

  • summary_custom returns a list of 4 named elements: stats, formats, labels, and indent_mods.

Functions

  • summary_formats(): Function to retrieve default formats for summary statistics. Returns format patterns for descriptive statistics which are understood by rtables.

  • summary_labels(): Function to retrieve default labels for summary statistics. Returns labels of descriptive statistics which are understood by rtables.

  • summary_custom(): Function to configure settings for default or custom summary statistics for a given data type. In addition to selecting a custom subset of statistics, the user can also set custom formats, labels, and indent modifiers for any of these statistics.

Examples

summary_formats()
#>                    n                  sum                 mean 
#>                "xx."               "xx.x"               "xx.x" 
#>                   sd                   se              mean_sd 
#>               "xx.x"               "xx.x"        "xx.x (xx.x)" 
#>              mean_se              mean_ci             mean_sei 
#>        "xx.x (xx.x)"     "(xx.xx, xx.xx)"     "(xx.xx, xx.xx)" 
#>             mean_sdi            mean_pval               median 
#>     "(xx.xx, xx.xx)"              "xx.xx"               "xx.x" 
#>                  mad            median_ci            quantiles 
#>               "xx.x"     "(xx.xx, xx.xx)"        "xx.x - xx.x" 
#>                  iqr                range                  min 
#>               "xx.x"        "xx.x - xx.x"               "xx.x" 
#>                  max         median_range                   cv 
#>               "xx.x" "xx.x (xx.x - xx.x)"               "xx.x" 
#>            geom_mean         geom_mean_ci              geom_cv 
#>               "xx.x"     "(xx.xx, xx.xx)"               "xx.x" 
summary_formats(type = "count", include_pval = TRUE)
#>                    n                  sum                 mean 
#>                "xx."               "xx.x"               "xx.x" 
#>                   sd                   se              mean_sd 
#>               "xx.x"               "xx.x"        "xx.x (xx.x)" 
#>              mean_se              mean_ci             mean_sei 
#>        "xx.x (xx.x)"     "(xx.xx, xx.xx)"     "(xx.xx, xx.xx)" 
#>             mean_sdi            mean_pval               median 
#>     "(xx.xx, xx.xx)"              "xx.xx"               "xx.x" 
#>                  mad            median_ci            quantiles 
#>               "xx.x"     "(xx.xx, xx.xx)"        "xx.x - xx.x" 
#>                  iqr                range                  min 
#>               "xx.x"        "xx.x - xx.x"               "xx.x" 
#>                  max         median_range                   cv 
#>               "xx.x" "xx.x (xx.x - xx.x)"               "xx.x" 
#>            geom_mean         geom_mean_ci              geom_cv 
#>               "xx.x"     "(xx.xx, xx.xx)"               "xx.x" 
#>                 pval 
#> "x.xxxx | (<0.0001)" 

summary_labels()
#>                             n                           sum 
#>                           "n"                         "Sum" 
#>                          mean                            sd 
#>                        "Mean"                          "SD" 
#>                            se                       mean_sd 
#>                          "SE"                   "Mean (SD)" 
#>                       mean_se                       mean_ci 
#>                   "Mean (SE)"                 "Mean 95% CI" 
#>                      mean_sei                      mean_sdi 
#>               "Mean -/+ 1xSE"               "Mean -/+ 1xSD" 
#>                     mean_pval                        median 
#> "Mean p-value (H0: mean = 0)"                      "Median" 
#>                           mad                     median_ci 
#>   "Median Absolute Deviation"               "Median 95% CI" 
#>                     quantiles                           iqr 
#>             "25% and 75%-ile"                         "IQR" 
#>                         range                           min 
#>                   "Min - Max"                     "Minimum" 
#>                           max                  median_range 
#>                     "Maximum"          "Median (Min - Max)" 
#>                            cv                     geom_mean 
#>                      "CV (%)"              "Geometric Mean" 
#>                  geom_mean_ci                       geom_cv 
#>       "Geometric Mean 95% CI"         "CV % Geometric Mean" 
summary_labels(type = "count", include_pval = TRUE)
#>                             n                           sum 
#>                           "n"                         "Sum" 
#>                          mean                            sd 
#>                        "Mean"                          "SD" 
#>                            se                       mean_sd 
#>                          "SE"                   "Mean (SD)" 
#>                       mean_se                       mean_ci 
#>                   "Mean (SE)"                 "Mean 95% CI" 
#>                      mean_sei                      mean_sdi 
#>               "Mean -/+ 1xSE"               "Mean -/+ 1xSD" 
#>                     mean_pval                        median 
#> "Mean p-value (H0: mean = 0)"                      "Median" 
#>                           mad                     median_ci 
#>   "Median Absolute Deviation"               "Median 95% CI" 
#>                     quantiles                           iqr 
#>             "25% and 75%-ile"                         "IQR" 
#>                         range                           min 
#>                   "Min - Max"                     "Minimum" 
#>                           max                  median_range 
#>                     "Maximum"          "Median (Min - Max)" 
#>                            cv                     geom_mean 
#>                      "CV (%)"              "Geometric Mean" 
#>                  geom_mean_ci                       geom_cv 
#>       "Geometric Mean 95% CI"         "CV % Geometric Mean" 
#>                          pval 
#>            "p-value (t-test)" 

summary_custom()
#> $stats
#>  [1] "n"            "sum"          "mean"         "sd"           "se"          
#>  [6] "mean_sd"      "mean_se"      "mean_ci"      "mean_sei"     "mean_sdi"    
#> [11] "mean_pval"    "median"       "mad"          "median_ci"    "quantiles"   
#> [16] "iqr"          "range"        "min"          "max"          "median_range"
#> [21] "cv"           "geom_mean"    "geom_mean_ci" "geom_cv"     
#> 
#> $formats
#>                    n                  sum                 mean 
#>                "xx."               "xx.x"               "xx.x" 
#>                   sd                   se              mean_sd 
#>               "xx.x"               "xx.x"        "xx.x (xx.x)" 
#>              mean_se              mean_ci             mean_sei 
#>        "xx.x (xx.x)"     "(xx.xx, xx.xx)"     "(xx.xx, xx.xx)" 
#>             mean_sdi            mean_pval               median 
#>     "(xx.xx, xx.xx)"              "xx.xx"               "xx.x" 
#>                  mad            median_ci            quantiles 
#>               "xx.x"     "(xx.xx, xx.xx)"        "xx.x - xx.x" 
#>                  iqr                range                  min 
#>               "xx.x"        "xx.x - xx.x"               "xx.x" 
#>                  max         median_range                   cv 
#>               "xx.x" "xx.x (xx.x - xx.x)"               "xx.x" 
#>            geom_mean         geom_mean_ci              geom_cv 
#>               "xx.x"     "(xx.xx, xx.xx)"               "xx.x" 
#> 
#> $labels
#>                             n                           sum 
#>                           "n"                         "Sum" 
#>                          mean                            sd 
#>                        "Mean"                          "SD" 
#>                            se                       mean_sd 
#>                          "SE"                   "Mean (SD)" 
#>                       mean_se                       mean_ci 
#>                   "Mean (SE)"                 "Mean 95% CI" 
#>                      mean_sei                      mean_sdi 
#>               "Mean -/+ 1xSE"               "Mean -/+ 1xSD" 
#>                     mean_pval                        median 
#> "Mean p-value (H0: mean = 0)"                      "Median" 
#>                           mad                     median_ci 
#>   "Median Absolute Deviation"               "Median 95% CI" 
#>                     quantiles                           iqr 
#>             "25% and 75%-ile"                         "IQR" 
#>                         range                           min 
#>                   "Min - Max"                     "Minimum" 
#>                           max                  median_range 
#>                     "Maximum"          "Median (Min - Max)" 
#>                            cv                     geom_mean 
#>                      "CV (%)"              "Geometric Mean" 
#>                  geom_mean_ci                       geom_cv 
#>       "Geometric Mean 95% CI"         "CV % Geometric Mean" 
#> 
#> $indent_mods
#>            n          sum         mean           sd           se      mean_sd 
#>            0            0            0            0            0            0 
#>      mean_se      mean_ci     mean_sei     mean_sdi    mean_pval       median 
#>            0            0            0            0            0            0 
#>          mad    median_ci    quantiles          iqr        range          min 
#>            0            0            0            0            0            0 
#>          max median_range           cv    geom_mean geom_mean_ci      geom_cv 
#>            0            0            0            0            0            0 
#> 
summary_custom(type = "counts", include_pval = TRUE)
#> $stats
#> [1] "n"              "count"          "count_fraction" "n_blq"         
#> [5] "pval"          
#> 
#> $formats
#> $formats$n
#> [1] "xx."
#> 
#> $formats$count
#> [1] "xx."
#> 
#> $formats$count_fraction
#> function(x, ...) {
#>   attr(x, "label") <- NULL
#> 
#>   if (any(is.na(x))) {
#>     return("NA")
#>   }
#> 
#>   checkmate::assert_vector(x)
#>   checkmate::assert_integerish(x[1])
#>   assert_proportion_value(x[2], include_boundaries = TRUE)
#> 
#>   result <- if (x[1] == 0) {
#>     "0"
#>   } else {
#>     paste0(x[1], " (", round(x[2] * 100, 1), "%)")
#>   }
#> 
#>   return(result)
#> }
#> <environment: namespace:tern>
#> 
#> $formats$n_blq
#> [1] "xx."
#> 
#> $formats$pval
#> [1] "x.xxxx | (<0.0001)"
#> 
#> 
#> $labels
#>                            n                        count 
#>                          "n"                      "count" 
#>               count_fraction                        n_blq 
#>             "count_fraction"                      "n_blq" 
#>                         pval 
#> "p-value (chi-squared test)" 
#> 
#> $indent_mods
#>              n          count count_fraction          n_blq           pval 
#>              0              0              0              0              0 
#> 
summary_custom(
  include_pval = TRUE, stats_custom = c("n", "mean", "sd", "pval"),
  labels_custom = c(sd = "Std. Dev."), indent_mods_custom = 3L
)
#> $stats
#> [1] "n"    "mean" "sd"   "pval"
#> 
#> $formats
#>                    n                 mean                   sd 
#>                "xx."               "xx.x"               "xx.x" 
#>                 pval 
#> "x.xxxx | (<0.0001)" 
#> 
#> $labels
#>                  n               mean                 sd               pval 
#>                "n"             "Mean"        "Std. Dev." "p-value (t-test)" 
#> 
#> $indent_mods
#>    n mean   sd pval 
#>    3    3    3    3 
#>