getStats: Get default set of statistics for one particular variable.

View source: R/stats-getStats.R

getStatsR Documentation

Get default set of statistics for one particular variable.

Description

This set of statistics can be passed directly to the stats parameter of the of the package functions.

Usage

getStats(
  type = "summary",
  includeName = TRUE,
  x = NULL,
  nDecCont = getMaxNDecimals,
  nDecN = 0,
  nDecm = nDecN,
  formatPercentage = inTextSummaryTable::formatPercentage
)

Arguments

type

Character vector with type of statistics (multiple are possible). Available statistics are specified in the section 'Formatted statistics' and formatting in 'Statistics formatting' in in-text table statistics.

includeName

Logical, should the statistics name be included (TRUE by default)? This is applied for the statistic names used in each for the set defined in type; and for the label of the list if type is of length 2. If there are multiple type or statistics within a set, the names are retained (to avoid confusion).

x

(optional, recommended for continuous variable) Numeric vector for which the statistics should be computed on.
This is used to derive the number of decimals to include for a continuous variable.
If not specified, the values are rounded with formatC.

nDecCont

Integer with base number of decimals for continuous variable, or function returning this number based on x (getNDecimals by default).

nDecN, nDecm

Integer with number of decimals for number of subjects/records (0 by default).

formatPercentage

Function used to format the percentages (see formatPercentage for default behaviour).

Value

Expression (or call object) containing function to extract requested summary statistics. If multiple type are specified, they are combined to a list. Names of the list will be typically used to name the statistic in the summary table.

Author(s)

Laure Cougnaud

See Also

getStatsData

Examples

## default set of statistics are available for:

# for count table:
getStats("count")
getStats("n (%)")
getStats("n")
getStats("%")
getStats("m")
getStats("%m")
getStats("m (%)")
# for continuous variable:
getStats("summary")
getStats("mean (se)")
getStats("mean (sd)")
getStats("median (range)")
getStats("median\n(range)")
getStats(c("Mean", "SE"))

## to not include statistic name in the table
getStats("median\n(range)", includeName = FALSE)
getStats(c("summary", "median\n(range)"), includeName = FALSE)

## to extract the number of decimals based on a continuous variable (see ?getMaxNDecimals) 
exampleData <- data.frame(
  USUBJID = 1 : 4, 
  WEIGHT = c(67, 78, 83, 61), 
  SEX = c("F", "M", "M", "F"), 
  stringsAsFactors = FALSE
)
getStats(type = c('median (range)', 'mean (se)'), x = exampleData$WEIGHT)
# compare with when 'x' is not specified:
getStats(type = c('median (range)', 'mean (se)'))

## custom function to format the percentages:
getStats(type = "count", formatPercentage = function(x) round(x, 2))

inTextSummaryTable documentation built on Sept. 12, 2023, 5:06 p.m.