Skip to contents
  • continuous_summary_fns() returns a named list of summary functions for continuous variables. Some functions include slight modifications to their base equivalents. For example, the min() and max() functions return NA instead of Inf when an empty vector is passed. Statistics "p25" and "p75" are calculated with quantile(type = 2), which matches SAS's default value.

  • categorical_summary_fns() returns a named list of summary statistics for categorical variables. Options are "n", "N", and "p". If a user requests, for example, only "p", the function will return "n" and "N" as well, since they are needed to calculate "p". These statistics will be stored as a vector within the tabulation list element.

  • missing_summary_fns() returns a named list of summary functions suitable for variable-level summaries, such as number and rate of missing data.

Usage

continuous_summary_fns(
  summaries = c("N", "mean", "sd", "median", "p25", "p75", "min", "max"),
  other_stats = NULL
)

categorical_summary_fns(summaries = c("n", "p", "N"), other_stats = NULL)

missing_summary_fns(
  summaries = c("N_obs", "N_miss", "N_nonmiss", "p_miss", "p_nonmiss")
)

Arguments

summaries

(character)
a character vector of results to include in output.

  • continuous_summary_fns(): Select one or more from 'N', 'mean', 'sd', 'median', 'p25', 'p75', 'min', 'max'.

  • categorical_summary_fns(): Select one or more from 'n', 'p', 'N'.

  • missing_summary_fns(): Select one or more from 'N_obs', 'N_miss', 'N_nonmiss', 'p_miss', 'p_nonmiss'.

other_stats

(named list)
named list of other statistic functions to supplement the pre-programmed functions.

Value

continuous_summary_fns() and missing_summary_fns() return a named list of summary functions, categorical_summary_fns() returns a named list of summary statistics.

Examples

# continuous variable summaries
ard_continuous(
  ADSL,
  variables = "AGE",
  statistic = ~ continuous_summary_fns(c("N", "median"))
)
#> {cards} data frame: 2 x 8
#>   variable   context stat_name stat_label stat fmt_fn
#> 1      AGE continuo…         N          N  254      0
#> 2      AGE continuo…    median     Median   77      1
#>  2 more variables: warning, error

# categorical variable summaries
ard_categorical(
  ADSL,
  variables = "AGEGR1",
  statistic = ~ categorical_summary_fns(c("n", "N"))
)
#> {cards} data frame: 6 x 9
#>   variable variable_level   context stat_name stat_label stat
#> 1   AGEGR1          65-80 categori…         n          n  144
#> 2   AGEGR1          65-80 categori…         N          N  254
#> 3   AGEGR1            <65 categori…         n          n   33
#> 4   AGEGR1            <65 categori…         N          N  254
#> 5   AGEGR1            >80 categori…         n          n   77
#> 6   AGEGR1            >80 categori…         N          N  254
#>  3 more variables: fmt_fn, warning, error

# summary for rates of missing data
ard_missing(
  ADSL,
  variables = c("AGE", "AGEGR1"),
  statistic = ~ missing_summary_fns()
)
#> {cards} data frame: 10 x 8
#>    variable context stat_name stat_label stat fmt_fn
#> 1       AGE missing     N_obs  Vector L…  254      0
#> 2       AGE missing    N_miss  N Missing    0      0
#> 3       AGE missing N_nonmiss  N Non-mi…  254      0
#> 4       AGE missing    p_miss  % Missing    0   <fn>
#> 5       AGE missing p_nonmiss  % Non-mi…    1   <fn>
#> 6    AGEGR1 missing     N_obs  Vector L…  254      0
#> 7    AGEGR1 missing    N_miss  N Missing    0      0
#> 8    AGEGR1 missing N_nonmiss  N Non-mi…  254      0
#> 9    AGEGR1 missing    p_miss  % Missing    0   <fn>
#> 10   AGEGR1 missing p_nonmiss  % Non-mi…    1   <fn>
#>  2 more variables: warning, error