knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
distionary:
The distionary package is more useful when augmented with the distplyr package, which provides a grammar for distribution manipulation.
distionary is not on CRAN yet. You can download the development version from GitHub with:
# install.packages("devtools") devtools::install_github("vincenzocoia/distionary")
Or, install distplyr, and distionary will come along with it.
library(distionary)
We can make distributions from standard families, like beta and Poisson:
(d_beta <- dst_beta(2, 4)) (d_pois <- dst_pois(1.2))
We can also make empirical distributions from data:
x <- c(4.1, 2.3, 3.4, 5.5, 1.0, 6.8) (d_emp <- dst_empirical(x))
We can evaluate different distributional forms, such as the density or pmf:
eval_density(d_beta, at = c(0.1, 0.2)) eval_pmf(d_pois, at = c(1, 1.5, 3))
Or, we can enframe the results in a tibble:
enframe_cdf(d_beta, d_pois, d_emp, at = c(0.1, 0.6, 1.5, 3))
Evaluate properties of the distributions:
mean(d_beta) skewness(d_pois) range(d_emp)
You can make your own distributions, too. Want to make a distribution whose density decays linearly from 0 to a
? Just ensure the p
/d
/q
functions are available:
# dlinear <- function(x, a) (a - x) / (a^2 / 2) # plinear <- function(x, a) x * (a - x / 2) / (a^2 / 2) # qlinear <- function(p, a) a * (1 - sqrt(1 - p)) # (my_dst <- dst_parametric("linear", a = 3, .variable = "continuous"))
Hazard function:
# plot(my_dst, "hazard", from = 0, to = 3)
Mean:
# mean(my_dst)
Please note that the distionary project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.