Learn R Programming

distr (version 2.9.5)

distr-package: distr -- Object Oriented Implementation of Distributions

Description

distr provides a conceptual treatment of distributions by means of S4 classes. A mother class Distribution is introduced with slots for a parameter and ---most important--- for the four constitutive methods r, d, p, and q for simulation respectively for evaluation of density / c.d.f.\ and quantile function of the corresponding distribution. Most distributions of package stats (like normal, Poisson, etc.) are implemented as subclasses of either AbscontDistribution or DiscreteDistribution, which themselves are again subclasses of Distribution. Up to arguments referring to a parameter of the distribution (like mean for the normal distribution), these function slots have the same arguments as those of package stats, i.e.; for a distribution object X we may call these functions as

  • r(X)(n)

  • d(X)(x, log = FALSE)

  • p(X)(q, lower.tail = TRUE, log.p = FALSE)

  • q(X)(p, lower.tail = TRUE, log.p = FALSE)

For the arguments of these function slots see e.g. rnorm. Note that, as usual, slots d, p, and q are vectorized in their first argument, but are not on the subsequent ones. In the environments of RStudio, see https://posit.co and Jupyter IRKernel, see https://github.com/IRkernel/IRkernel, calls to q are caught away from standard R evaluation and are treated in a non-standard way. This non-standard evaluation in particular throws errors at calls to our accessor methods q to slot q of the respective distribution object. To amend this, we provide function q.l as alias to our accessors q, so that our packages also become available in these environments. Arithmetics and unary mathematical transformations for distributions are available: For Distribution objects X and Y expressions like 3*X+sin(exp(-Y/4+3)) have their natural interpretation as corresponding image distributions.

Arguments

Classes

Distribution classes have a slot param the class of which is is specialized for the particualar distributions. The parameter classes for the particular distributions have slots with names according to the corresponding [rdpq]<name> functions of package base. From version 1.9 on, AbscontDistribution and descendants have a slot gaps for gaps in the support. DiscreteDistribution and descendants have an additional slot support, which is again specialized to be a lattice for class LatticeDistribution.
For saved objects from earlier versions, we provide the methods isOldVersion, and conv2NewVersion to check whether the object was generated by an older version of this package and to convert such an object to the new format, respectively. This applies to objects of subclasses of AbscontDistribution lacking a gap-slot as well as to to objects of subclasses of LatticeDistribution lacking a lattice-slot.
To enhance accuracy, from version 1.9 on, we also provide subclasses AffLinAbscontDistribution, AffLinDiscreteDistribution, and AffLinLatticeDistribution, as well as the class union AffLinDistribution, so that in particular functionals like E from package distrEx can recur to exact formula more frequently: These classes have additional slots a, b, and X0 to reflect the fact, that a distribution object of theses classes has the same distribution as a*X0+b.
For all particular distributions, as well as for classes AbscontDistribution, DiscreteDistribution, LatticeDistribution, UnivarDistrList and DistrList generating functions are provided, e.g. X <- Norm(mean = 3, sd = 2). The same goes for the space classes. All slots should be inspected / modified by means of corresponding accessor- /replacement functions; e.g. mean(X) <- 3 Again to enhance accuracy, from version 2.0 on, we also provide subclasses UnivarMixingDistribution to support mixing distributions, UnivarLebDecDistribution, to support Lebesgue decomposed distributions (with a discrete and an a.c. part) as well as AffLinUnivarLebDecDistribution, for corresponding affine linear transformations. Class UnivarLebDecDistribution is closed under arithmetical operations + /, *, ^ for pairs of independent variables + +, - for pairs of independent variables + affine linear transformations + truncation, huberization, min/max which are all now available analytically.
(see Parameter classes).


[*]: there is a generating function with the same name
##########################
Distribution classes
##########################
slots: [<name>(<class>)]
img(rSpace), param(OptionalParameter),
r(function), d(OptionalFunction), p(OptionalFunction), q(OptionalFunction),
.withSim(logical), .withArith(logical), .logExact(logical), .lowerExact(logical),
Symmetry(DistributionSymmetry)
"Distribution"
|>"UnivariateDistribution"
|>|>"UnivarMixingDistribution"            [*]
|>|>|>"UnivarLebDecDistribution"          [*]
|>|>|>|>"AffLinUnivarLebDecDistribution"
|>|>|>"CompoundDistribution"              [*]
|>|>"AbscontDistribution"                 [*]
|>|>|>"AffLinAbscontDistribution"
|>|>|>"Arcsine"                           [*]
|>|>|>"Beta"                              [*]
|>|>|>"Cauchy"                            [*]
|>|>|>"ExpOrGammaOrChisq" (VIRTUAL)
|>|>|>|>"Exp"                             [*]
|>|>|>|>"Gammad"                          [*]
|>|>|>|>"Chisq"                           [*]
|>|>|>"Fd"                                [*]
|>|>|>"Lnorm"                             [*]
|>|>|>"Logis"                             [*]
|>|>|>"Norm"                              [*]
|>|>|>"Td"                                [*]
|>|>|>"Unif"                              [*]
|>|>|>"Weibull"                           [*]
|>|>|"DiscreteDistribution"               [*]
|>|>|>"AffLinDiscreteDistribution"
|>|>|>"LatticeDistribution"               [*]
|>|>|>|>"AffLinLatticeDistribution"
|>|>|>|>"Binom"                           [*]
|>|>|>|>"Dirac"                           [*]
|>|>|>|>"Hyper"                           [*]
|>|>|>|>"NBinom"                          [*]
|>|>|>|>|>"Geom"                          [*]
|>|>|>|>"Pois"                            [*]
"AffLinDistribution" = union ( "AffLinAbscontDistribution",
                               "AffLinDiscreteDistribution",
                               "AffLinUnivarLebDecDistribution" )
"DistrList"
|>"UnivarDistrList"                       [*]
"AcDcLc" = union ( "AbscontDistribution",
                   "DiscreteDistribution",
                   "UnivarLebDecDistribution" )
##########################
Parameter classes
##########################
"OptionalParameter"
|>"Parameter"
|>|>"BetaParameter"
|>|>"BinomParameter"
|>|>"CauchyParameter"
|>|>"ChisqParameter"
|>|>"DiracParameter"
|>|>"ExpParameter"
|>|>"FParameter"
|>|>"GammaParameter"
|>|>"GeomParameter"
|>|>"HyperParameter"
|>|>"LnormParameter"
|>|>"LogisParameter"
|>|>"NbinomParameter"
|>|>"NormParameter"
|>|>"UniNormParameter"
|>|>|>"PoisParameter"
|>|>"TParameter"
|>|>"UnifParameter"
|>|>"WeibullParameter"
##########################
Space classes
##########################
"rSpace"
|>"EuclideanSpace"
|>|>"Reals"
|>"Lattice"
|>"Naturals"
##########################
Symmetry classes
##########################
slots:
type(character), SymmCenter(ANY)
"Symmetry"
|>"NoSymmetry"          [*]
|>"EllipticalSymmetry"  [*]
|>|>"SphericalSymmetry" [*]
|>"DistributionSymmetry"
|>"FunctionSymmetry"
|>|>"NonSymmetric"      [*]
|>|>"EvenSymmetric"     [*]
|>|>"OddSymmetric"      [*]
list thereof
"DistrSymmList"         [*]
"FunSymmList"           [*]
##########################
Matrix classes
##########################
slots:
none
"PosSemDefSymmMatrix" [*] is subclass of class "matrix" of package "base".
|>"PosDefSymmMatrix"  [*]
##########################
Class unions
##########################
"OptionalNumeric" = union("numeric", "NULL")
"OptionalMatrix" = union("matrix","NULL")

Methods

The group Math of unary (see Math) as well as convolution are made available for distributions, see operators-methods ;in particular for convolution powers, we have method convpow. Besides, there are plot and print-methods for distributions. For the space classes, we have liesIn, for the DicreteDistribution class, we have liesInSupport, as well as a generating function. The "history" of distributions obtained by chaining operations may be shortened using simplifyr.

Functions


RtoDPQ                  Default procedure to fill slots d,p,q given r
                        for a.c. distributions
RtoDPQ.d                Default procedure to fill slots d,p,q given r
                        for discrete distributions
RtoDPQ.LC               Default procedure to fill slots d,p,q given r
                        for Lebesgue decomposed distributions
decomposePM             decomposes a distribution into positive and negative
                        part and, if discrete, into part '0'
simplifyD               tries to reduce/simplify mixing distribution using
                        that certain weights are 0
flat.LCD                makes a single UnivarLebDecDistribution out of
                        a list of UnivarLebDecDistribution with corresp. weights
flat.mix                makes a single UnivarLebDecDistribution out of
                        a list of a UnivarMixingDistribution
distroptions            Functions to change the global variables of the
                        package 'distr'
standardMethods         Utility to automatically generate accessor and
                        replacement functions

Extension Packages in distrXXX family

Please note that there are extension packages of this packages available on CRAN,

distrDoc

a documentation package providing joint documentation for all packages of the distrXXX family of packages in the form of vignette 'distr'; try require(distrDoc); vignette("distr").

distrEx

provides functionals (like E, sd, mad) operating on distributions, as well as distances between distributions and basic support for multivariate and conditional distributions.

distrSim

for the standardized treatment of simulations, also under contaminations.

distrTEst

with classes and methods for evaluations of statistical procedures on simulations generated by distrSim.

distrTeach

embodies illustrations for basic stats courses using our distribution classes.

distrMod

provides classes for parametric models and hence covers, in an object orientated way, estimation in statistical models.

distrEllipse

provides classes for elliptically symmetric distributions.

Package versions

Note: The first two numbers of package versions do not necessarily reflect package-individual development, but rather are chosen for the distrXXX family as a whole in order to ease updating "depends" information.

Acknowledgement

We thank Martin Maechler, Josef Leydold, John Chambers, Duncan Murdoch, Gregory Warnes, Paul Gilbert, Kurt Hornik, Uwe Ligges, Torsten Hothorn, and Seth Falcon for their help in preparing this package.

Author

Peter Ruckdeschel peter.ruckdeschel@uni-oldenburg.de,
Thomas Stabla statho3@web.de,
Florian Camphausen fcampi@gmx.de,
Matthias Kohl Matthias.Kohl@stamats.de
Maintainer: Peter Ruckdeschel peter.ruckdeschel@uni-oldenburg.de

Start-up-Banner

You may suppress the start-up banner/message completely by setting options("StartupBanner"="off") somewhere before loading this package by library or require in your R-code / R-session. If option "StartupBanner" is not defined (default) or setting options("StartupBanner"=NULL) or options("StartupBanner"="complete") the complete start-up banner is displayed. For any other value of option "StartupBanner" (i.e., not in c(NULL,"off","complete")) only the version information is displayed. The same can be achieved by wrapping the library or require call into either suppressStartupMessages() or onlytypeStartupMessages(.,atypes="version"). As for general packageStartupMessage's, you may also suppress all the start-up banner by wrapping the library or require call into suppressPackageStartupMessages() from startupmsg-version 0.5 on.

Demos

Demos are available --- see demo(package="distr")

Details

Package:distr
Version:2.9.5
Date:2024-08-29
Depends:R(>= 3.4), methods, graphics, startupmsg, sfsmisc
Suggests:distrEx, svUnit (>= 0.7-11), knitr, distrMod, ROptEst
Imports:stats, grDevices, utils, MASS
LazyLoad:yes
License:LGPL-3
URL:https://distr.r-forge.r-project.org/
VCS/SVNRevision:1448

References

P. Ruckdeschel, M. Kohl, T. Stabla, F. Camphausen (2006): S4 Classes for Distributions, R News, 6(2), 2-6. https://CRAN.R-project.org/doc/Rnews/Rnews_2006-2.pdf P. Ruckdeschel and M. Kohl (2014): General purpose convolution algorithm for distributions in S4-Classes by means of FFT. J. Statist. Softw. 59(4): 1-25. a vignette for packages distr, distrSim, distrTEst, and distrEx is included into the mere documentation package distrDoc and may be called by require("distrDoc");vignette("distr") a homepage to this package is available under
https://distr.r-forge.r-project.org/

Examples

Run this code
X <- Unif(2,3)
Y <- Pois(lambda = 3)
Z <- X+Y  # generates Law of corresponding independent variables
p(Z)(0.2)
r(Z)(1000)
plot(Z+sin(Norm()))

Run the code above in your browser using DataLab