tidy_stat_tbl: Tidy Stats of Tidy Distribution

View source: R/stats-tidy-stat-func-tbl.R

tidy_stat_tblR Documentation

Tidy Stats of Tidy Distribution

Description

A function to return the stat function values of a given tidy_ distribution output.

Usage

tidy_stat_tbl(
  .data,
  .x = y,
  .fns,
  .return_type = "vector",
  .use_data_table = FALSE,
  ...
)

Arguments

.data

The input data coming from a tidy_ distribution function.

.x

The default is y but can be one of the other columns from the input data.

.fns

The default is IQR, but this can be any stat function like quantile or median etc.

.return_type

The default is "vector" which returns an sapply object.

.use_data_table

The default is FALSE, TRUE will use data.table under the hood and still return a tibble. If this argument is set to TRUE then the .return_type parameter will be ignored.

...

Addition function arguments to be supplied to the parameters of .fns

Details

A function to return the value(s) of a given tidy_ distribution function output and chosen column from it. This function will only work with tidy_ distribution functions.

There are currently three different output types for this function. These are:

  • "vector" - which gives an sapply() output

  • "list" - which gives an lapply() output, and

  • "tibble" - which returns a tibble in long format.

Currently you can pass any stat function that performs an operation on a vector input. This means you can pass things like IQR, quantile and their associated arguments in the ... portion of the function.

This function also by default will rename the value column of the tibble to the name of the function. This function will also give the column name of sim_number for the tibble output with the corresponding simulation numbers as the values.

For the sapply and lapply outputs the column names will also give the simulation number information by making column names like sim_number_1 etc.

There is an option of .use_data_table which can greatly enhance the speed of the calculations performed if used while still returning a tibble. The calculations are performed after turning the input data into a data.table object, performing the necessary calculation and then converting back to a tibble object.

Value

A return of object of either sapply lapply or tibble based upon user input.

Author(s)

Steven P. Sanderson II, MPH

See Also

Other Statistic: ci_hi(), ci_lo(), tidy_kurtosis_vec(), tidy_range_statistic(), tidy_skewness_vec()

Examples

tn <- tidy_normal(.num_sims = 3)

p <- c(0.025, 0.25, 0.5, 0.75, 0.95)

tidy_stat_tbl(tn, y, quantile, "vector", probs = p, na.rm = TRUE)
tidy_stat_tbl(tn, y, quantile, "list", probs = p)
tidy_stat_tbl(tn, y, quantile, "tibble", probs = p)
tidy_stat_tbl(tn, y, quantile, .use_data_table = TRUE, probs = p, na.rm = TRUE)


TidyDensity documentation built on Nov. 2, 2023, 5:38 p.m.