Skip to content
Probability Distributions as S3 Objects
R
Branch: master
Clone or download
Latest commit 33c0ca6 Sep 4, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
R We're on CRAN! Sep 3, 2019
man We're on CRAN! Sep 3, 2019
tests More renaming updates Aug 31, 2019
vignettes More renaming to distributions3 Aug 31, 2019
.Rbuildignore More renaming updates Aug 31, 2019
.gitignore IN WHICH DAVIS HOLDS ME AT GUNPOINT AND MAKES ME COMMIT USING RSTUDIO Jun 23, 2019
.travis.yml Remove amsfonts from .travis.yml, run travis::use_travis_deploy() Jun 23, 2019
DESCRIPTION Rename to distributions3 Aug 31, 2019
LICENSE Initial commit May 8, 2019
LICENSE.md Initial commit May 8, 2019
NAMESPACE Misc documentation Aug 30, 2019
NEWS.md
README.Rmd Update README Sep 3, 2019
README.md Update README Sep 3, 2019
_pkgdown.yml Improve pkgdown site Aug 30, 2019
codecov.yml Add code coverage badge Jun 19, 2019
cran-comments.md
distributions3.Rproj Rename to distributions3 Aug 31, 2019

README.md

distributions3

CRAN status Travis build status Codecov test coverage

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

I am very happy to review PRs and provide advice on how to add new functionality to the package. Documentation improvements are particularly appreciated!

To add a new distribution, the best way to get started is to look at R/Beta.R and tests/testthat/test-Beta.R, copy them, and modify them for whatever new distribution you’d like to add.

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.

  • distr is quite similar to distributions, but uses S4 objects and is less focused on documentation.
  • distr6 builds on distr, but uses R6 objects
  • fitdistrplus provides extensive functionality for fitting various distributions but does not treat distributions themselves as objects
You can’t perform that action at this time.