The goal of {TidyDensity}
is to make working with random
numbers from different distributions easy. All tidy_
distribution functions provide the following components:
r_
]d_
]q_
]p_
]You can install the released version of {TidyDensity}
from CRAN with:
install.packages("TidyDensity")
And the development version from GitHub with:
# install.packages("devtools")
::install_github("spsanderson/TidyDensity") devtools
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.209 -3.37 0.000254 0.583 0.209
#> 2 1 2 1.55 -3.22 0.000693 0.940 1.55
#> 3 1 3 -1.23 -3.08 0.00171 0.110 -1.23
#> 4 1 4 -1.04 -2.93 0.00385 0.150 -1.04
#> 5 1 5 -0.542 -2.78 0.00790 0.294 -0.542
#> 6 1 6 1.31 -2.64 0.0149 0.905 1.31
#> 7 1 7 1.05 -2.49 0.0258 0.853 1.05
#> 8 1 8 0.00903 -2.35 0.0417 0.504 0.00903
#> 9 1 9 -1.40 -2.20 0.0628 0.0809 -1.40
#> 10 1 10 1.99 -2.06 0.0889 0.977 1.99
#> # ℹ 40 more rows
An example plot of the tidy_normal
data.
<- tidy_normal(.n = 100, .num_sims = 6)
tn
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.
<- tidy_normal(.n = 100, .num_sims = 20)
tn
tidy_autoplot(tn, .plot_type = "density")
tidy_autoplot(tn, .plot_type = "quantile")
tidy_autoplot(tn, .plot_type = "probability")
tidy_autoplot(tn, .plot_type = "qq")