A function to return the stat function values of a given tidy_ distribution
output.
Arguments
- .data
The input data coming from a
tidy_distribution function.- .x
The default is
ybut can be one of the other columns from the input data.- .fns
The default is
IQR, but this can be anystatfunction likequantileormedianetc.- .return_type
The default is "vector" which returns an
sapplyobject.- .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_typeparameter 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
tibblein 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.
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)
#> sim_number_1 sim_number_2 sim_number_3
#> 2.5% -1.85745580 -1.98217759 -1.9219874
#> 25% -0.81031902 -0.54181470 -0.7553953
#> 50% -0.09807074 0.05888466 -0.1584200
#> 75% 0.53372944 0.73755129 0.7498126
#> 95% 1.21577097 1.59637792 1.4064778
tidy_stat_tbl(tn, y, quantile, "list", probs = p)
#> $sim_number_1
#> 2.5% 25% 50% 75% 95%
#> -1.85745580 -0.81031902 -0.09807074 0.53372944 1.21577097
#>
#> $sim_number_2
#> 2.5% 25% 50% 75% 95%
#> -1.98217759 -0.54181470 0.05888466 0.73755129 1.59637792
#>
#> $sim_number_3
#> 2.5% 25% 50% 75% 95%
#> -1.9219874 -0.7553953 -0.1584200 0.7498126 1.4064778
#>
tidy_stat_tbl(tn, y, quantile, "tibble", probs = p)
#> # A tibble: 15 × 3
#> sim_number name quantile
#> <fct> <chr> <dbl>
#> 1 1 2.5% -1.86
#> 2 1 25% -0.810
#> 3 1 50% -0.0981
#> 4 1 75% 0.534
#> 5 1 95% 1.22
#> 6 2 2.5% -1.98
#> 7 2 25% -0.542
#> 8 2 50% 0.0589
#> 9 2 75% 0.738
#> 10 2 95% 1.60
#> 11 3 2.5% -1.92
#> 12 3 25% -0.755
#> 13 3 50% -0.158
#> 14 3 75% 0.750
#> 15 3 95% 1.41
tidy_stat_tbl(tn, y, quantile, .use_data_table = TRUE, probs = p, na.rm = TRUE)
#> # A tibble: 15 × 3
#> sim_number name quantile
#> <fct> <fct> <dbl>
#> 1 1 2.5% -1.86
#> 2 1 25% -0.810
#> 3 1 50% -0.0981
#> 4 1 75% 0.534
#> 5 1 95% 1.22
#> 6 2 2.5% -1.98
#> 7 2 25% -0.542
#> 8 2 50% 0.0589
#> 9 2 75% 0.738
#> 10 2 95% 1.60
#> 11 3 2.5% -1.92
#> 12 3 25% -0.755
#> 13 3 50% -0.158
#> 14 3 75% 0.750
#> 15 3 95% 1.41
