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 -2.05 -3.84 0.000204 0.5 -1.47
#> 2 1 2 -0.00158 -3.67 0.000549 0.508 -0.0728
#> 3 1 3 0.209 -3.51 0.00132 0.516 0.0305
#> 4 1 4 -0.282 -3.35 0.00286 0.524 -0.211
#> 5 1 5 -0.592 -3.19 0.00559 0.533 -0.370
#> 6 1 6 0.785 -3.02 0.00986 0.541 0.318
#> 7 1 7 -0.349 -2.86 0.0158 0.549 -0.245
#> 8 1 8 0.183 -2.70 0.0234 0.557 0.0177
#> 9 1 9 1.05 -2.54 0.0323 0.565 0.458
#> 10 1 10 0.753 -2.37 0.0423 0.573 0.301
#> # … with 40 more rows
#> # ℹ Use `print(n = ...)` to see 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")