Skip to contents

This function generates tidy data from the triangular distribution.

Usage

tidy_triangular(
  .n = 50,
  .min = 0,
  .max = 1,
  .mode = 1/2,
  .num_sims = 1,
  .return_tibble = TRUE
)

Arguments

.n

The number of x values for each simulation.

.min

The minimum value of the triangular distribution.

.max

The maximum value of the triangular distribution.

.mode

The mode (peak) value of the triangular distribution.

.num_sims

The number of simulations to perform.

.return_tibble

A logical value indicating whether to return the result as a tibble. Default is TRUE.

Value

A tibble of randomly generated data.

Details

The function takes parameters for the triangular distribution (minimum, maximum, mode), the number of x values (n), the number of simulations (num_sims), and an option to return the result as a tibble (return_tibble). It performs various checks on the input parameters to ensure validity. The result is a data frame or tibble with tidy data for further analysis.

Author

Steven P. Sanderson II, MPH

Examples

tidy_triangular(.return_tibble = TRUE)
#> # A tibble: 50 × 7
#>    sim_number     x     y       dx      dy     p     q
#>    <fct>      <int> <dbl>    <dbl>   <dbl> <dbl> <dbl>
#>  1 1              1 0.314 -0.200   0.00114 0.197 0.314
#>  2 1              2 0.508 -0.172   0.00302 0.515 0.508
#>  3 1              3 0.230 -0.144   0.00720 0.106 0.230
#>  4 1              4 0.630 -0.116   0.0155  0.727 0.630
#>  5 1              5 0.328 -0.0888  0.0301  0.215 0.328
#>  6 1              6 0.513 -0.0611  0.0531  0.527 0.513
#>  7 1              7 0.626 -0.0334  0.0861  0.721 0.626
#>  8 1              8 0.817 -0.00568 0.129   0.933 0.817
#>  9 1              9 0.235  0.0220  0.182   0.110 0.235
#> 10 1             10 0.520  0.0497  0.245   0.540 0.520
#> # ℹ 40 more rows