TidyDensity

CRAN_Status_Badge Lifecycle: stable PRs Welcome

The goal of {TidyDensity} is to make working with random numbers from different distributions easy. All tidy_ distribution functions provide the following components:

Installation

You can install the released version of {TidyDensity} from CRAN with:

install.packages("TidyDensity")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("spsanderson/TidyDensity")

Example

This is a basic example which shows you how to solve a common problem:

library(TidyDensity)
library(dplyr)
library(ggplot2)

tidy_normal()
#> # A tibble: 50 × 7
#>    sim_number     x      y    dx       dy      p      q
#>    <fct>      <int>  <dbl> <dbl>    <dbl>  <dbl>  <dbl>
#>  1 1              1  0.926 -3.70 0.000226 0.823   0.926
#>  2 1              2 -0.471 -3.55 0.000595 0.319  -0.471
#>  3 1              3 -0.438 -3.41 0.00141  0.331  -0.438
#>  4 1              4  1.65  -3.27 0.00304  0.950   1.65 
#>  5 1              5  0.396 -3.13 0.00595  0.654   0.396
#>  6 1              6 -1.45  -2.99 0.0106   0.0736 -1.45 
#>  7 1              7  0.247 -2.84 0.0174   0.597   0.247
#>  8 1              8  0.409 -2.70 0.0264   0.659   0.409
#>  9 1              9  0.799 -2.56 0.0372   0.788   0.799
#> 10 1             10  1.11  -2.42 0.0493   0.867   1.11 
#> # ℹ 40 more rows

An example plot of the tidy_normal data.

tn <- tidy_normal(.n = 100, .num_sims = 6)

tidy_autoplot(tn, .plot_type = "density")

tidy_autoplot(tn, .plot_type = "quantile")

tidy_autoplot(tn, .plot_type = "probability")

tidy_autoplot(tn, .plot_type = "qq")

We can also take a look at the plots when the number of simulations is greater than nine. This will automatically turn off the legend as it will become too noisy.

tn <- tidy_normal(.n = 100, .num_sims = 20)

tidy_autoplot(tn, .plot_type = "density")

tidy_autoplot(tn, .plot_type = "quantile")

tidy_autoplot(tn, .plot_type = "probability")

tidy_autoplot(tn, .plot_type = "qq")