MyNixOS website logo
Description

Probability Distributions as S3 Objects.

Tools to create and manipulate probability distributions using S3. Generics pdf(), cdf(), quantile(), and random() provide replacements for base R's d/p/q/r style functions. Functions and arguments have been named carefully to minimize confusion for students in intro stats courses. The documentation for each distribution contains detailed mathematical notes.

distributions3

CRANstatus R-CMD-check Codecov testcoverage

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.
Metadata

Version

0.2.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows