Learn R Programming

distributions3

distributions3, inspired by the eponynmous Julia package, provides a generic function interface to probability distributions. distributions3 has two goals:

  1. Replace the rnorm(), pnorm(), etc, family of functions with S3 methods for distribution objects

  2. Be extremely well documented and friendly for students in intro stat classes.

The main generics are:

  • random(): Draw samples from a distribution.
  • pdf(): Evaluate the probability density (or mass) at a point.
  • cdf(): Evaluate the cumulative probability up to a point.
  • quantile(): Determine the quantile for a given probability. Inverse of cdf().

Installation

You can install distributions3 with:

install.packages("distributions3")

You can install the development version with:

install.packages("devtools")
devtools::install_github("alexpghayes/distributions3")

Basic Usage

The basic usage of distributions3 looks like:

library("distributions3")

X <- Bernoulli(0.1)

random(X, 10)
#>  [1] 0 0 0 0 0 0 1 1 0 0
pdf(X, 1)
#> [1] 0.1

cdf(X, 0)
#> [1] 0.9
quantile(X, 0.5)
#> [1] 0

Note that quantile() always returns lower tail probabilities. If you aren’t sure what this means, please read the last several paragraphs of vignette("one-sample-z-confidence-interval") and have a gander at the plot.

Contributing

If you are interested in contributing to distributions3, please reach out on Github! We are happy to review PRs contributing bug fixes.

Please note that distributions3 is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Related work

For a comprehensive overview of the many packages providing various distribution related functionality see the CRAN Task View.

  • distributional provides distribution objects as vectorized S3 objects
  • distr6 builds on distr, but uses R6 objects
  • distr is quite similar to distributions, but uses S4 objects and is less focused on documentation.
  • fitdistrplus provides extensive functionality for fitting various distributions but does not treat distributions themselves as objects

Copy Link

Version

Install

install.packages('distributions3')

Monthly Downloads

2,686

Version

0.2.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

September 16th, 2024

Functions in distributions3 (0.2.2)

Gumbel

Create a Gumbel distribution
GEV

Create a Generalised Extreme Value (GEV) distribution
HyperGeometric

Create a HyperGeometric distribution
HurdleNegativeBinomial

Create a hurdle negative binomial distribution
Frechet

Create a Frechet distribution
LogNormal

Create a LogNormal distribution
Geometric

Create a Geometric distribution
GP

Create a Generalised Pareto (GP) distribution
Gamma

Create a Gamma distribution
HurdlePoisson

Create a hurdle Poisson distribution
Tukey

Create a Tukey distribution
RevWeibull

Create a reversed Weibull distribution
Normal

Create a Normal distribution
NegativeBinomial

Create a negative binomial distribution
Multinomial

Create a Multinomial distribution
Logistic

Create a Logistic distribution
Uniform

Create a Continuous Uniform distribution
StudentsT

Create a Student's T distribution
Poisson

Create a Poisson distribution
PoissonBinomial

Create a Poisson binomial distribution
ZTPoisson

Create a zero-truncated Poisson distribution
Weibull

Create a Weibull distribution
cdf.Categorical

Evaluate the cumulative distribution function of a Categorical distribution
cdf.Beta

Evaluate the cumulative distribution function of a Beta distribution
apply_dpqr

Utilities for distributions3 objects
ZINegativeBinomial

Create a zero-inflated negative binomial distribution
ZIPoisson

Create a zero-inflated Poisson distribution
cdf.Bernoulli

Evaluate the cumulative distribution function of a Bernoulli distribution
cdf.Binomial

Evaluate the cumulative distribution function of a Binomial distribution
ZTNegativeBinomial

Create a zero-truncated negative binomial distribution
cdf.Cauchy

Evaluate the cumulative distribution function of a Cauchy distribution
cdf.GEV

Evaluate the cumulative distribution function of a GEV distribution
cdf.Erlang

Evaluate the cumulative distribution function of an Erlang distribution
cdf.Gamma

Evaluate the cumulative distribution function of a Gamma distribution
cdf.GP

Evaluate the cumulative distribution function of a GP distribution
cdf.FisherF

Evaluate the cumulative distribution function of an F distribution
cdf.Frechet

Evaluate the cumulative distribution function of a Frechet distribution
cdf.Geometric

Evaluate the cumulative distribution function of a Geometric distribution
cdf.HurdleNegativeBinomial

Evaluate the cumulative distribution function of a hurdle negative binomial distribution
cdf.PoissonBinomial

Evaluate the cumulative distribution function of a PoissonBinomial distribution
cdf.Poisson

Evaluate the cumulative distribution function of a Poisson distribution
cdf.HurdlePoisson

Evaluate the cumulative distribution function of a hurdle Poisson distribution
cdf.ChiSquare

Evaluate the cumulative distribution function of a chi square distribution
cdf.Exponential

Evaluate the cumulative distribution function of an Exponential distribution
cdf.HyperGeometric

Evaluate the cumulative distribution function of a HyperGeometric distribution
cdf.Gumbel

Evaluate the cumulative distribution function of a Gumbel distribution
cdf.NegativeBinomial

Evaluate the cumulative distribution function of a negative binomial distribution
cdf.ZINegativeBinomial

Evaluate the cumulative distribution function of a zero-inflated negative binomial distribution
cdf

Evaluate the cumulative distribution function of a probability distribution
cdf.Normal

Evaluate the cumulative distribution function of a Normal distribution
cdf.ZTNegativeBinomial

Evaluate the cumulative distribution function of a zero-truncated negative binomial distribution
cdf.RevWeibull

Evaluate the cumulative distribution function of an RevWeibull distribution
cdf.LogNormal

Evaluate the cumulative distribution function of a LogNormal distribution
cdf.Logistic

Evaluate the cumulative distribution function of a Logistic distribution
fit_mle.Poisson

Fit an Poisson distribution to data
fit_mle

Fit a distribution to data
fit_mle.LogNormal

Fit a Log Normal distribution to data
cdf.ZIPoisson

Evaluate the cumulative distribution function of a zero-inflated Poisson distribution
fit_mle.Exponential

Fit an Exponential distribution to data
fit_mle.Binomial

Fit a Binomial distribution to data
fit_mle.Normal

Fit a Normal distribution to data
cdf.Uniform

Evaluate the cumulative distribution function of a continuous Uniform distribution
cdf.Weibull

Evaluate the cumulative distribution function of a Weibull distribution
pdf.Binomial

Evaluate the probability mass function of a Binomial distribution
is_distribution

Is an object a distribution?
pdf.Categorical

Evaluate the probability mass function of a Categorical discrete distribution
cdf.Tukey

Evaluate the cumulative distribution function of a Tukey distribution
fit_mle.Gamma

Fit a Gamma distribution to data
log_likelihood

Compute the (log-)likelihood of a probability distribution given data
pdf.Geometric

Evaluate the probability mass function of a Geometric distribution
pdf.Gamma

Evaluate the probability mass function of a Gamma distribution
fit_mle.Geometric

Fit a Geometric distribution to data
cdf.StudentsT

Evaluate the cumulative distribution function of a StudentsT distribution
cdf.ZTPoisson

Evaluate the cumulative distribution function of a zero-truncated Poisson distribution
pdf.Beta

Evaluate the probability mass function of a Beta distribution
dhpois

The hurdle Poisson distribution
pdf.Bernoulli

Evaluate the probability mass function of a Bernoulli distribution
is_discrete

Determine whether a distribution is discrete or continuous
pdf.GEV

Evaluate the probability mass function of a GEV distribution
pdf.Frechet

Evaluate the probability mass function of a Frechet distribution
pdf.Cauchy

Evaluate the probability mass function of a Cauchy distribution
pdf.FisherF

Evaluate the probability mass function of an F distribution
stat_auc

Fill out area under the curve for a plotted PDF
pdf.GP

Evaluate the probability mass function of a GP distribution
dhnbinom

The hurdle negative binomial distribution
fit_mle.Bernoulli

Fit a Bernoulli distribution to data
pdf.Erlang

Evaluate the probability mass function of an Erlang distribution
pdf.ChiSquare

Evaluate the probability mass function of a chi square distribution
pdf.HyperGeometric

Evaluate the probability mass function of a HyperGeometric distribution
pdf.HurdlePoisson

Evaluate the probability mass function of a hurdle Poisson distribution
distributions3-package

distributions3: Probability Distributions as S3 Objects
pdf.Multinomial

Evaluate the probability mass function of a Multinomial distribution
pdf.Exponential

Evaluate the probability density function of an Exponential distribution
pdf.Weibull

Evaluate the probability mass function of a Weibull distribution
pdf.Poisson

Evaluate the probability mass function of a Poisson distribution
pdf.NegativeBinomial

Evaluate the probability mass function of a NegativeBinomial distribution
pdf.Normal

Evaluate the probability mass function of a Normal distribution
pdf.Uniform

Evaluate the probability mass function of a continuous Uniform distribution
pdf.Logistic

Evaluate the probability mass function of a Logistic distribution
pdf.LogNormal

Evaluate the probability mass function of a LogNormal distribution
pdf.ZINegativeBinomial

Evaluate the probability mass function of a zero-inflated negative binomial distribution
pdf.ZIPoisson

Evaluate the probability mass function of a zero-inflated Poisson distribution
pdf.Gumbel

Evaluate the probability mass function of a Gumbel distribution
pdf.HurdleNegativeBinomial

Evaluate the probability mass function of a hurdle negative binomial distribution
quantile.Cauchy

Determine quantiles of a Cauchy distribution
quantile.ChiSquare

Determine quantiles of a chi square distribution
pdf.ZTNegativeBinomial

Evaluate the probability mass function of a zero-truncated negative binomial distribution
pdf.ZTPoisson

Evaluate the probability mass function of a zero-truncated Poisson distribution
plot_pdf

Plot the PDF of a distribution
quantile.Binomial

Determine quantiles of a Binomial distribution
quantile.Erlang

Determine quantiles of an Erlang distribution
quantile.Categorical

Determine quantiles of a Categorical discrete distribution
pdf.PoissonBinomial

Evaluate the probability mass function of a PoissonBinomial distribution
pdf.StudentsT

Evaluate the probability mass function of a StudentsT distribution
quantile.RevWeibull

Determine quantiles of a RevWeibull distribution
quantile.StudentsT

Determine quantiles of a StudentsT distribution
pdf.RevWeibull

Evaluate the probability mass function of an RevWeibull distribution
quantile.HurdleNegativeBinomial

Determine quantiles of a hurdle negative binomial distribution
pdf

Evaluate the probability density of a probability distribution
prodist

Extracting fitted or predicted probability distributions from models
quantile.Gumbel

Determine quantiles of a Gumbel distribution
quantile.GP

Determine quantiles of a GP distribution
quantile.Bernoulli

Determine quantiles of a Bernoulli distribution
quantile.GEV

Determine quantiles of a GEV distribution
quantile.HurdlePoisson

Determine quantiles of a hurdle Poisson distribution
quantile.NegativeBinomial

Determine quantiles of a NegativeBinomial distribution
quantile.Exponential

Determine quantiles of an Exponential distribution
plot_cdf

Plot the CDF of a distribution
plot.distribution

Plot the p.m.f, p.d.f or c.d.f. of a univariate distribution
quantile.Beta

Determine quantiles of a Beta distribution
quantile.FisherF

Determine quantiles of an F distribution
quantile.Normal

Determine quantiles of a Normal distribution
quantile.Gamma

Determine quantiles of a Gamma distribution
quantile.Geometric

Determine quantiles of a Geometric distribution
random.Bernoulli

Draw a random sample from a Bernoulli distribution
quantile.ZTPoisson

Determine quantiles of a zero-truncated Poisson distribution
quantile.HyperGeometric

Determine quantiles of a HyperGeometric distribution
quantile.Poisson

Determine quantiles of a Poisson distribution
random.GEV

Draw a random sample from a GEV distribution
quantile.PoissonBinomial

Determine quantiles of a PoissonBinomial distribution
random.Frechet

Draw a random sample from a Frechet distribution
quantile.Tukey

Determine quantiles of a Tukey distribution
random.HurdleNegativeBinomial

Draw a random sample from a hurdle negative binomial distribution
quantile.Frechet

Determine quantiles of a Frechet distribution
quantile.Uniform

Determine quantiles of a continuous Uniform distribution
random.ChiSquare

Draw a random sample from a chi square distribution
quantile.LogNormal

Determine quantiles of a LogNormal distribution
quantile.ZTNegativeBinomial

Determine quantiles of a zero-truncated negative binomial distribution
quantile.ZIPoisson

Determine quantiles of a zero-inflated Poisson distribution
random.GP

Draw a random sample from a GP distribution
random.Exponential

Draw a random sample from an Exponential distribution
random.Erlang

Draw a random sample from an Erlang distribution
quantile.Logistic

Determine quantiles of a Logistic distribution
quantile.Weibull

Determine quantiles of a Weibull distribution
quantile.ZINegativeBinomial

Determine quantiles of a zero-inflated negative binomial distribution
random.HurdlePoisson

Draw a random sample from a hurdle Poisson distribution
random.Gamma

Draw a random sample from a Gamma distribution
random.Categorical

Draw a random sample from a Categorical distribution
random.Cauchy

Draw a random sample from a Cauchy distribution
random.Gumbel

Draw a random sample from a Gumbel distribution
random.Geometric

Draw a random sample from a Geometric distribution
random.Poisson

Draw a random sample from a Poisson distribution
simulate.default

Simulate responses from fitted model objects
random.PoissonBinomial

Draw a random sample from a PoissonBinomial distribution
random.Weibull

Draw a random sample from a Weibull distribution
random.FisherF

Draw a random sample from an F distribution
random.Uniform

Draw a random sample from a continuous Uniform distribution
random.LogNormal

Draw a random sample from a LogNormal distribution
random.HyperGeometric

Draw a random sample from a HyperGeometric distribution
suff_stat.Binomial

Compute the sufficient statistics for the Binomial distribution from data
random

Draw a random sample from a probability distribution
suff_stat.Bernoulli

Compute the sufficient statistics for a Bernoulli distribution from data
random.NegativeBinomial

Draw a random sample from a negative binomial distribution
random.Normal

Draw a random sample from a Normal distribution
random.Beta

Draw a random sample from a Beta distribution
random.Binomial

Draw a random sample from a Binomial distribution
random.RevWeibull

Draw a random sample from an RevWeibull distribution
random.StudentsT

Draw a random sample from a StudentsT distribution
random.Tukey

Draw a random sample from a Tukey distribution
suff_stat.LogNormal

Compute the sufficient statistics for a Log-normal distribution from data
support.Bernoulli

Return the support of the Bernoulli distribution
suff_stat.Normal

Compute the sufficient statistics for a Normal distribution from data
random.ZTNegativeBinomial

Draw a random sample from a zero-truncated negative binomial distribution
random.Logistic

Draw a random sample from a Logistic distribution
support.ChiSquare

Return the support of the ChiSquare distribution
random.ZTPoisson

Draw a random sample from a zero-truncated Poisson distribution
random.Multinomial

Draw a random sample from a Multinomial distribution
random.ZINegativeBinomial

Draw a random sample from a zero-inflated negative binomial distribution
support.Beta

Return the support of the Beta distribution
suff_stat.Poisson

Compute the sufficient statistics of an Poisson distribution from data
support.HurdleNegativeBinomial

Return the support of the hurdle negative binomial distribution
support.HurdlePoisson

Return the support of the hurdle Poisson distribution
suff_stat

Compute the sufficient statistics of a distribution from data
support.StudentsT

Return the support of the StudentsT distribution
support.Erlang

Return the support of the Erlang distribution
support.Binomial

Return the support of the Binomial distribution
support.RevWeibull

Return the support of the RevWeibull distribution
suff_stat.Exponential

Compute the sufficient statistics of an Exponential distribution from data
support.Cauchy

Return the support of the Cauchy distribution
support.ZIPoisson

Return the support of the zero-inflated Poisson distribution
support.Uniform

Return the support of the Uniform distribution
support.Tukey

Return the support of the Tukey distribution
dzipois

The zero-inflated Poisson distribution
support.ZTNegativeBinomial

Return the support of the zero-truncated negative binomial distribution
support.GEV

Return the support of a GEV distribution
support.Frechet

Return the support of the Frechet distribution
support.Exponential

Return the support of the Exponential distribution
support.FisherF

Return the support of the FisherF distribution
support.Normal

Return the support of the Normal distribution
support.Poisson

Return the support of the Poisson distribution
dztnbinom

The zero-truncated negative binomial distribution
random.ZIPoisson

Draw a random sample from a zero-inflated Poisson distribution
dztpois

The zero-truncated Poisson distribution
support.Gamma

Return the support of the Gamma distribution
support.GP

Return the support of the GP distribution
suff_stat.Gamma

Compute the sufficient statistics for a Gamma distribution from data
suff_stat.Geometric

Compute the sufficient statistics for the Geometric distribution from data
support.HyperGeometric

Return the support of the HyperGeometric distribution
support.LogNormal

Return the support of the LogNormal distribution
support.Gumbel

Return the support of the Gumbel distribution
support.Geometric

Return the support of the Geometric distribution
support

Return the support of a distribution
support.PoissonBinomial

Return the support of the PoissonBinomial distribution
dzinbinom

The zero-inflated negative binomial distribution
support.Logistic

Return the support of the Logistic distribution
vec_proxy.distribution

Methods for including distributions as vctrs in tibbles
support.NegativeBinomial

Return the support of the NegativeBinomial distribution
support.ZTPoisson

Return the support of the zero-truncated Poisson distribution
variance

Compute the moments of a probability distribution
support.Weibull

Return the support of the Weibull distribution
support.ZINegativeBinomial

Return the support of the zero-inflated negative binomial distribution
Erlang

Create an Erlang distribution
Exponential

Create an Exponential distribution
ChiSquare

Create a Chi-Square distribution
Categorical

Create a Categorical distribution
Binomial

Create a Binomial distribution
FIFA2018

Goals scored in all 2018 FIFA World Cup matches
Beta

Create a Beta distribution
Cauchy

Create a Cauchy distribution
FisherF

Create an F distribution
Bernoulli

Create a Bernoulli distribution