knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

distionary

Lifecycle: experimental CRAN status Codecov test coverage R-CMD-check License: MIT R-CMD-check

distionary:

  1. makes standard probability distributions available, like Normal, Poisson, and empirical distributions -- and even your own distribution, and
  2. provides a framework for evaluating probability distributions.

The distionary package is more useful when augmented with the distplyr package, which provides a grammar for distribution manipulation.

Installation

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.

Example

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)

Code of Conduct

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.



vincenzocoia/distionary documentation built on March 5, 2024, 3:13 a.m.