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 1 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

distributions3 is not under active development, but is fairly stable and used by several academics for teaching intro stat courses. We are happy to review PRs contributing bug fixes. If you are interested in more actively maintaining and developing distributions3, please reach out on Github!

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, and is more actively developed that distributions3
  • 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.1.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Alex Hayes

Last Published

January 3rd, 2022

Functions in distributions3 (0.1.2)

Binomial

Create a Binomial distribution
Tukey

Create a Tukey distribution
cdf.Frechet

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

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

Evaluate the cumulative distribution function of a HyperGeometric distribution
Uniform

Create a Continuous Uniform distribution
cdf.GEV

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

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

Evaluate the cumulative distribution function of a continuous Uniform distribution
stat_auc

Fill out area under the curve for a plotted PDF
is_distribution

Is an object a distribution?
pdf.Erlang

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

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

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

Evaluate the probability mass function of a Multinomial distribution
pdf

Evaluate the probability density of a probability distribution
Cauchy

Create a Cauchy distribution
pdf.RevWeibull

Evaluate the probability mass function of an RevWeibull distribution
ChiSquare

Create a Chi-Square distribution
RevWeibull

Create a reversed Weibull distribution
StudentsT

Create a Student's T distribution
quantile.Binomial

Determine quantiles of a Binomial distribution
Frechet

Create a Frechet distribution
Multinomial

Create a Multinomial distribution
FisherF

Create an F distribution
quantile.Categorical

Determine quantiles of a Categorical discrete distribution
cdf.ChiSquare

Evaluate the cumulative distribution function of a chi square distribution
NegativeBinomial

Create a Negative Binomial distribution
Poisson

Create a Poisson distribution
Normal

Create a Normal distribution
cdf.Categorical

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

Evaluate the cumulative distribution function of a Cauchy distribution
quantile.Uniform

Determine quantiles of a continuous Uniform distribution
fit_mle.Binomial

Fit a Binomial distribution to data
cdf.Erlang

Evaluate the cumulative distribution function of an Erlang distribution
fit_mle.Exponential

Fit an Exponential distribution to data
Erlang

Create an Erlang distribution
cdf.GP

Evaluate the cumulative distribution function of a GP distribution
Gumbel

Create a Gumbel distribution
Exponential

Create an Exponential distribution
HyperGeometric

Create a HyperGeometric distribution
cdf.Geometric

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

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

Evaluate the cumulative distribution function of a Gamma 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
random.FisherF

Draw a random sample from an F distribution
random.StudentsT

Draw a random sample from a StudentsT distribution
suff_stat.Poisson

Compute the sufficient statistics of an Poisson distribution from data
quantile.Weibull

Determine quantiles of a Weibull distribution
suff_stat

Compute the sufficient statistics of a distribution from data
random.Frechet

Draw a random sample from a Frechet distribution
random.Uniform

Draw a random sample from a continuous Uniform distribution
support.ChiSquare

Return the support of the ChiSquare distribution
cdf.NegativeBinomial

Evaluate the cumulative distribution function of a negative binomial distribution
pdf.Binomial

Evaluate the probability mass function of a Binomial distribution
support.Logistic

Return the support of the Logistic distribution
support.NegativeBinomial

Return the support of the NegativeBinomial distribution
support.Erlang

Return the support of the Erlang distribution
cdf.StudentsT

Evaluate the cumulative distribution function of a StudentsT distribution
pdf.Categorical

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

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

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

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

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

Evaluate the probability mass function of a Logistic distribution
LogNormal

Create a LogNormal distribution
Logistic

Create a Logistic distribution
quantile.Bernoulli

Determine quantiles of a Bernoulli distribution
Weibull

Create a Weibull distribution
quantile.Beta

Determine quantiles of a Beta distribution
cdf.Tukey

Evaluate the cumulative distribution function of a Tukey distribution
quantile.Exponential

Determine quantiles of an Exponential distribution
quantile.Gamma

Determine quantiles of a Gamma distribution
quantile.Erlang

Determine quantiles of an Erlang distribution
cdf.Bernoulli

Evaluate the cumulative distribution function of a Bernoulli distribution
quantile.Geometric

Determine quantiles of a Geometric distribution
random.Geometric

Draw a random sample from a Geometric distribution
random.Cauchy

Draw a random sample from a Cauchy distribution
random.ChiSquare

Draw a random sample from a chi square distribution
random.Gamma

Draw a random sample from a Gamma distribution
cdf.Exponential

Evaluate the cumulative distribution function of an Exponential distribution
random.Normal

Draw a random sample from a Normal distribution
cdf.Poisson

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

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

Evaluate the cumulative distribution function of an F distribution
fit_mle.Gamma

Fit a Gamma distribution to data
pdf.Bernoulli

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

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

Evaluate the probability mass function of an F distribution
pdf.Poisson

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

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

Evaluate the probability mass function of a Frechet distribution
random.Poisson

Draw a random sample from a Poisson distribution
support.Gamma

Return the support of the Gamma distribution
quantile.Gumbel

Determine quantiles of a Gumbel distribution
quantile.GEV

Determine quantiles of a GEV distribution
pdf.Uniform

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

Determine quantiles of a GP distribution
fit_mle.Geometric

Fit a Geometric distribution to data
support.Geometric

Return the support of the Geometric distribution
support.Normal

Return the support of the Normal distribution
fit_mle.LogNormal

Fit a Log Normal distribution to data
support.Poisson

Return the support of the Poisson distribution
fit_mle.Normal

Fit a Normal distribution to data
plot.distribution

Plot the p.m.f, p.d.f or c.d.f. of a univariate distribution
pdf.Weibull

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

Determine quantiles of a HyperGeometric distribution
quantile.Tukey

Determine quantiles of a Tukey distribution
pdf.Gumbel

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

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

Draw a random sample from an Exponential distribution
random.Logistic

Draw a random sample from a Logistic distribution
support.Beta

Return the support of the Beta distribution
random.LogNormal

Draw a random sample from a LogNormal distribution
support.Bernoulli

Return the support of the Bernoulli distribution
random.Weibull

Draw a random sample from a Weibull distribution
random.Erlang

Draw a random sample from an Erlang distribution
quantile.NegativeBinomial

Determine quantiles of a NegativeBinomial distribution
random.Binomial

Draw a random sample from a Binomial distribution
random.GEV

Draw a random sample from a GEV distribution
random.Categorical

Draw a random sample from a Categorical distribution
quantile.Normal

Determine quantiles of a Normal distribution
pdf.HyperGeometric

Evaluate the probability mass function of a HyperGeometric distribution
quantile.LogNormal

Determine quantiles of a LogNormal distribution
quantile.FisherF

Determine quantiles of an F distribution
quantile.Frechet

Determine quantiles of a Frechet distribution
quantile.Logistic

Determine quantiles of a Logistic distribution
suff_stat.LogNormal

Compute the sufficient statistics for a Log-normal distribution from data
random.GP

Draw a random sample from a GP distribution
support.Uniform

Return the support of the Uniform distribution
support.Tukey

Return the support of the Tukey distribution
random.Bernoulli

Draw a random sample from a Bernoulli distribution
support.Binomial

Return the support of the Binomial distribution
suff_stat.Normal

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

Draw a random sample from a HyperGeometric distribution
random.Beta

Draw a random sample from a Beta distribution
random.Gumbel

Draw a random sample from a Gumbel distribution
Beta

Create a Beta distribution
Bernoulli

Create a Bernoulli distribution
Gamma

Create a Gamma distribution
random.Multinomial

Draw a random sample from a Multinomial distribution
cdf.Beta

Evaluate the cumulative distribution function of a Beta distribution
Geometric

Create a Geometric distribution
cdf

Evaluate the probability density of a probability distribution
cdf.Binomial

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

Evaluate the cumulative distribution function of an RevWeibull distribution
fit_mle.Bernoulli

Fit a Bernoulli distribution to data
distributions3-package

distributions3: Probability Distributions as S3 Objects
likelihood

Compute the likelihood of a probability distribution given data
pdf.GEV

Evaluate the probability mass function of a GEV distribution
log_likelihood

Compute the log-likelihood of a probability distribution given data
plot_cdf

Plot the CDF of a distribution
pdf.Gamma

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

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

Evaluate the probability mass function of a Geometric distribution
plot_pdf

Plot the PDF of a distribution
random.NegativeBinomial

Draw a random sample from a negative binomial distribution
support.Cauchy

Return the support of the Cauchy distribution
suff_stat.Geometric

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

Compute the sufficient statistics for a Gamma distribution from data
support

Return the support of a distribution
support.Weibull

Return the support of the Weibull distribution
support.StudentsT

Return the support of the StudentsT distribution
variance

Compute the moments of a probability distribution
quantile.Cauchy

Determine quantiles of a Cauchy distribution
quantile.ChiSquare

Determine quantiles of a chi square distribution
quantile.Poisson

Determine quantiles of a Poisson distribution
quantile.RevWeibull

Determine quantiles of a RevWeibull distribution
random.RevWeibull

Draw a random sample from an RevWeibull distribution
random

Draw a random sample from a probability distribution
suff_stat.Exponential

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

Return the support of the Exponential distribution
suff_stat.Binomial

Compute the sufficient statistics for the Binomial distribution from data
support.FisherF

Return the support of the FisherF distribution
support.LogNormal

Return the support of the LogNormal distribution
support.HyperGeometric

Return the support of the HyperGeometric distribution
Categorical

Create a Categorical distribution
GEV

Create a Generalised Extreme Value (GEV) distribution
GP

Create a Generalised Pareto (GP) distribution
quantile.StudentsT

Determine quantiles of a StudentsT distribution