Exploring the Peaks: A Dive into the Triangular Distribution in TidyDensity

code

tidydensity

Author

Steven P. Sanderson II, MPH

Published

January 10, 2024

Introduction

Welcome back, fellow data enthusiasts! Today, we embark on an exciting journey into the world of statistical distributions with a special focus on the latest addition to the TidyDensity package – the triangular distribution. Tightly packed and versatile, this distribution brings a unique flavor to your data simulations and analyses. In this blog post, we’ll delve into the functions provided, understand their arguments, and explore the wonders of the triangular distribution.

What’s So Special About Triangular Distributions?

Flexibility in uncertainty: They model situations where you have a minimum, maximum, and most likely value, but the exact distribution between those points is unknown.

Common in real-world scenarios: Project cost estimates, task completion times, expert opinions, and even natural phenomena often exhibit triangular patterns.

Simple to understand and visualize: Their straightforward shape makes them accessible for interpretation and communication.

The triangular distribution is a continuous probability distribution with lower limit a, upper limit b, and mode c, where a < b and a ≤ c ≤ b. The distribution resembles a tent shape.

The probability density function of the triangular distribution is:

f(x) = (2(x - a)) / ((b - a)(c - a)) for a ≤ x ≤ c (2(b - x)) / ((b - a)(b - c)) for c ≤ x ≤ b

The key parameters of the triangular distribution are:

a - the minimum value

b - the maximum value

c - the mode (most frequent value)

The triangular distribution is often used as a subjective description of a population for which there is only limited sample data. It is useful when a process has a natural minimum and maximum.

Triangular Functions

TidyDensity’s Triangular Distribution Functions: Let’s start by introducing the main functions for the triangular distribution:

tidy_triangular(): This function generates a triangular distribution with a specified number of simulations, minimum, maximum, and mode values.

.n: Specifies the number of x values for each simulation.

.min: Sets the minimum value of the triangular distribution.

.max: Determines the maximum value of the triangular distribution.

.mode: Specifies the mode (peak) value of the triangular distribution.

.num_sims: Controls the number of simulations to perform.

.return_tibble: A logical value indicating whether to return the result as a tibble.

util_triangular_param_estimate(): This function estimates the parameters of a triangular distribution from a tidy data frame.

.x: Requires a numeric vector, with all values satisfying 0 <= x <= 1.

.auto_gen_empirical: A boolean value (TRUE/FALSE) with a default set to TRUE. It automatically generates tidy_empirical() output for the .x parameter and utilizes tidy_combine_distributions().

util_triangular_stats_tbl(): This function creates a tidy data frame with statistics for a triangular distribution.

.data: The data being passed from a tidy_ distribution function.

triangle_plot(): This function creates a ggplot2 object for a triangular distribution.

.data: Tidy data from the tidy_triangular function.

.interactive: A logical value indicating whether to return an interactive plot using plotly. Default is FALSE.

Using tidy_triangular for Simulations

Suppose you want to simulate a triangular distribution with 100 x values, a minimum of 0, a maximum of 1, and a mode at 0.5. You’d use the following code:

This will generate an informative plot, and if you set .interactive to TRUE, you can explore the distribution interactively using plotly.

Conclusion

In this blog post, we’ve explored the powerful functionalities of the triangular distribution in TidyDensity. Whether you’re simulating data, estimating parameters, or creating insightful visualizations, these functions provide a robust toolkit for your statistical endeavors. Happy coding, and may your distributions always be tidy!