Learn R Programming

⚠️There's a newer version (0.2.2) of this package.Take me there.

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 0 0 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,147

Version

0.2.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Alex Hayes

Last Published

September 7th, 2022

Functions in distributions3 (0.2.1)

FisherF

Create an F distribution
Gamma

Create a Gamma distribution
GP

Create a Generalised Pareto (GP) distribution
HurdleNegativeBinomial

Create a hurdle negative binomial distribution
HurdlePoisson

Create a hurdle Poisson distribution
Weibull

Create a Weibull distribution
Uniform

Create a Continuous Uniform distribution
Logistic

Create a Logistic distribution
Multinomial

Create a Multinomial distribution
Categorical

Create a Categorical distribution
cdf.Beta

Evaluate the cumulative distribution function of a Beta distribution
Frechet

Create a Frechet distribution
cdf.Binomial

Evaluate the cumulative distribution function of a Binomial distribution
NegativeBinomial

Create a negative binomial distribution
Poisson

Create a Poisson distribution
GEV

Create a Generalised Extreme Value (GEV) distribution
Gumbel

Create a Gumbel distribution
Geometric

Create a Geometric distribution
RevWeibull

Create a reversed Weibull distribution
Bernoulli

Create a Bernoulli distribution
Beta

Create a Beta distribution
Normal

Create a Normal distribution
ZINegativeBinomial

Create a zero-inflated negative binomial distribution
StudentsT

Create a Student's T distribution
Tukey

Create a Tukey distribution
cdf.Categorical

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

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

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

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

Evaluate the cumulative distribution function of a Tukey distribution
stat_auc

Fill out area under the curve for a plotted PDF
cdf.Logistic

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

Evaluate the cumulative distribution function of a StudentsT distribution
dhnbinom

The hurdle negative binomial distribution
cdf.GP

Evaluate the cumulative distribution function of a GP distribution
ZTPoisson

Create a zero-truncated Poisson distribution
ZTNegativeBinomial

Create a zero-truncated negative binomial distribution
cdf.Cauchy

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

Evaluate the cumulative distribution function of a Gamma distribution
ZIPoisson

Create a zero-inflated Poisson distribution
cdf.Geometric

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

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

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

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

Evaluate the cumulative distribution function of a LogNormal distribution
cdf

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

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

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

Evaluate the cumulative distribution function of a zero-inflated Poisson distribution
cdf.Gumbel

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

Evaluate the cumulative distribution function of a Normal distribution
HyperGeometric

Create a HyperGeometric distribution
fit_mle.Poisson

Fit an Poisson distribution to data
LogNormal

Create a LogNormal distribution
pdf.Categorical

Evaluate the probability mass function of a Categorical discrete distribution
pdf.Binomial

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

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

Evaluate the probability mass function of a Bernoulli distribution
fit_mle

Fit a distribution to data
pdf.Beta

Evaluate the probability mass function of a Beta distribution
fit_mle.Binomial

Fit a Binomial distribution to data
apply_dpqr

Utilities for distributions3 objects
cdf.Poisson

Evaluate the cumulative distribution function of a Poisson distribution
dhpois

The hurdle Poisson distribution
fit_mle.Exponential

Fit an Exponential distribution to data
pdf.Erlang

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

Evaluate the probability density function of an Exponential distribution
is_discrete

Determine whether a distribution is discrete or continuous
distributions3-package

distributions3: Probability Distributions as S3 Objects
pdf.HurdleNegativeBinomial

Evaluate the probability mass function of a hurdle negative binomial distribution
fit_mle.Bernoulli

Fit a Bernoulli distribution to data
pdf.LogNormal

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

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

Fit a Geometric distribution to data
cdf.Bernoulli

Evaluate the cumulative distribution function of a Bernoulli distribution
pdf.FisherF

Evaluate the probability mass function of an F distribution
fit_mle.Gamma

Fit a Gamma distribution to data
pdf.Frechet

Evaluate the probability mass function of a Frechet distribution
cdf.ZTNegativeBinomial

Evaluate the cumulative distribution function of a zero-truncated negative binomial distribution
log_likelihood

Compute the (log-)likelihood of a probability distribution given data
is_distribution

Is an object a distribution?
pdf.ZTPoisson

Evaluate the probability mass function of a zero-truncated Poisson distribution
cdf.ZTPoisson

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

Evaluate the probability mass function of a Gamma distribution
pdf

Evaluate the probability density of a probability distribution
pdf.Normal

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

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

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

Evaluate the probability mass function of an RevWeibull distribution
plot.distribution

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

Determine quantiles of a Bernoulli distribution
prodist

Extracting fitted or predicted probability distributions from models
pdf.NegativeBinomial

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

Evaluate the probability mass function of a Multinomial distribution
quantile.HurdleNegativeBinomial

Determine quantiles of a hurdle negative binomial distribution
quantile.Normal

Determine quantiles of a Normal distribution
quantile.Poisson

Determine quantiles of a Poisson distribution
quantile.HurdlePoisson

Determine quantiles of a hurdle Poisson distribution
quantile.Gumbel

Determine quantiles of a Gumbel distribution
quantile.Geometric

Determine quantiles of a Geometric distribution
pdf.ZIPoisson

Evaluate the probability mass function of a zero-inflated Poisson distribution
quantile.ZIPoisson

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

Draw a random sample from a GP distribution
quantile.ZTNegativeBinomial

Determine quantiles of a zero-truncated negative binomial distribution
pdf.ZTNegativeBinomial

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

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

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

Evaluate the probability mass function of a Weibull distribution
quantile.Cauchy

Determine quantiles of a Cauchy distribution
quantile.Categorical

Determine quantiles of a Categorical discrete distribution
random.Gamma

Draw a random sample from a Gamma distribution
quantile.Frechet

Determine quantiles of a Frechet distribution
quantile.GEV

Determine quantiles of a GEV distribution
quantile.Weibull

Determine quantiles of a Weibull distribution
cdf.Exponential

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

Evaluate the cumulative distribution function of an F distribution
random.HyperGeometric

Draw a random sample from a HyperGeometric distribution
pdf.Uniform

Evaluate the probability mass function of a continuous Uniform distribution
quantile.Erlang

Determine quantiles of an Erlang distribution
quantile.ChiSquare

Determine quantiles of a chi square distribution
quantile.HyperGeometric

Determine quantiles of a HyperGeometric distribution
cdf.HurdleNegativeBinomial

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

Evaluate the cumulative distribution function of a hurdle Poisson distribution
quantile.Logistic

Determine quantiles of a Logistic distribution
quantile.NegativeBinomial

Determine quantiles of a NegativeBinomial distribution
cdf.Weibull

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

Evaluate the cumulative distribution function of a continuous Uniform distribution
quantile.ZTPoisson

Determine quantiles of a zero-truncated Poisson distribution
random.Bernoulli

Draw a random sample from a Bernoulli distribution
quantile.Exponential

Determine quantiles of an Exponential distribution
random.Tukey

Draw a random sample from a Tukey distribution
random.LogNormal

Draw a random sample from a LogNormal 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
random.Uniform

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

Determine quantiles of a LogNormal distribution
random.Exponential

Draw a random sample from an Exponential distribution
random.FisherF

Draw a random sample from an F distribution
support.StudentsT

Return the support of the StudentsT distribution
support.Tukey

Return the support of the Tukey distribution
random.ZTPoisson

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

Draw a random sample from a StudentsT distribution
random.RevWeibull

Draw a random sample from an RevWeibull distribution
random.NegativeBinomial

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

Draw a random sample from a Gumbel distribution
random.Geometric

Draw a random sample from a Geometric distribution
random.ZINegativeBinomial

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

Draw a random sample from a Weibull distribution
random.Normal

Draw a random sample from a Normal distribution
quantile.ZINegativeBinomial

Determine quantiles of a zero-inflated negative binomial distribution
suff_stat.Poisson

Compute the sufficient statistics of an Poisson distribution from data
fit_mle.LogNormal

Fit a Log Normal distribution to data
fit_mle.Normal

Fit a Normal distribution to data
random.Beta

Draw a random sample from a Beta distribution
quantile.FisherF

Determine quantiles of an F distribution
suff_stat.Bernoulli

Compute the sufficient statistics for a Bernoulli distribution from data
pdf.Cauchy

Evaluate the probability mass function of a Cauchy distribution
support.Cauchy

Return the support of the Cauchy distribution
support.Frechet

Return the support of the Frechet distribution
support.Binomial

Return the support of the Binomial distribution
support.GEV

Return the support of a GEV distribution
support

Return the support of a distribution
suff_stat

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

Return the support of the Gumbel distribution
support.Geometric

Return the support of the Geometric distribution
support.ZINegativeBinomial

Return the support of the zero-inflated negative binomial distribution
support.Normal

Return the support of the Normal distribution
support.Poisson

Return the support of the Poisson distribution
pdf.ChiSquare

Evaluate the probability mass function of a chi square distribution
quantile.RevWeibull

Determine quantiles of a RevWeibull distribution
pdf.GP

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

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

Evaluate the probability mass function of a hurdle Poisson distribution
support.ZIPoisson

Return the support of the zero-inflated Poisson distribution
quantile.StudentsT

Determine quantiles of a StudentsT distribution
pdf.HyperGeometric

Evaluate the probability mass function of a HyperGeometric distribution
random.Categorical

Draw a random sample from a Categorical distribution
plot_cdf

Plot the CDF of a distribution
plot_pdf

Plot the PDF of a distribution
quantile.Beta

Determine quantiles of a Beta distribution
random.Cauchy

Draw a random sample from a Cauchy distribution
random.Binomial

Draw a random sample from a Binomial distribution
random.ZIPoisson

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

Return the support of the Beta distribution
support.GP

Return the support of the GP distribution
random

Draw a random sample from a probability distribution
support.Gamma

Return the support of the Gamma distribution
random.Poisson

Draw a random sample from a Poisson distribution
support.Bernoulli

Return the support of the Bernoulli distribution
random.ZTNegativeBinomial

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

Determine quantiles of a Binomial distribution
random.Frechet

Draw a random sample from a Frechet distribution
support.Weibull

Return the support of the Weibull distribution
support.HyperGeometric

Return the support of the HyperGeometric distribution
support.Uniform

Return the support of the Uniform distribution
support.LogNormal

Return the support of the LogNormal distribution
dztpois

The zero-truncated Poisson distribution
support.RevWeibull

Return the support of the RevWeibull distribution
random.Multinomial

Draw a random sample from a Multinomial distribution
suff_stat.Binomial

Compute the sufficient statistics for the Binomial distribution from data
random.GEV

Draw a random sample from a GEV distribution
random.Logistic

Draw a random sample from a Logistic distribution
quantile.Gamma

Determine quantiles of a Gamma distribution
quantile.GP

Determine quantiles of a GP distribution
suff_stat.LogNormal

Compute the sufficient statistics for a Log-normal distribution from data
suff_stat.Exponential

Compute the sufficient statistics of an Exponential distribution from data
suff_stat.Normal

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

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

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

Determine quantiles of a continuous Uniform distribution
quantile.Tukey

Determine quantiles of a Tukey distribution
random.ChiSquare

Draw a random sample from a chi square distribution
support.Exponential

Return the support of the Exponential distribution
random.Erlang

Draw a random sample from an Erlang distribution
support.ChiSquare

Return the support of the ChiSquare distribution
support.FisherF

Return the support of the FisherF distribution
support.Logistic

Return the support of the Logistic distribution
support.ZTNegativeBinomial

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

Return the support of the hurdle Poisson distribution
support.HurdleNegativeBinomial

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

Return the support of the Erlang distribution
support.ZTPoisson

Return the support of the zero-truncated Poisson distribution
support.NegativeBinomial

Return the support of the NegativeBinomial distribution
variance

Compute the moments of a probability distribution
dztnbinom

The zero-truncated negative binomial distribution
dzinbinom

The zero-inflated negative binomial distribution
dzipois

The zero-inflated Poisson distribution
Erlang

Create an Erlang distribution
Exponential

Create an Exponential distribution
ChiSquare

Create a Chi-Square distribution
Cauchy

Create a Cauchy distribution
FIFA2018

Goals scored in all 2018 FIFA World Cup matches
Binomial

Create a Binomial distribution