DiscreteDistribution-class: Class "DiscreteDistribution"

Description Objects from the Class Slots Extends Methods Internal subclass "AffLinDiscreteDistribution" Internal virtual superclass "AcDcLcDistribution" Note Author(s) See Also Examples

Description

The DiscreteDistribution-class is the mother-class of the class LatticeDistribution.

Objects from the Class

Objects can be created by calls to new("DiscreteDistribution", ...), but more easily is the use of the generating function "DiscreteDistribution". This generating function, from version 1.9 on, has been moved to this package from package distrEx.

Slots

img

Object of class "Reals": the space of the image of this distribution which has dimension 1 and the name "Real Space"

param

Object of class "Parameter": the parameter of this distribution, having only the slot name "Parameter of a discrete distribution"

r

Object of class "function": generates random numbers

d

Object of class "function": density/probability function

p

Object of class "function": cumulative distribution function

q

Object of class "function": quantile function

.withArith

logical: used internally to issue warnings as to interpretation of arithmetics

.withSim

logical: used internally to issue warnings as to accuracy

.logExact

logical: used internally to flag the case where there are explicit formulae for the log version of density, cdf, and quantile function

.lowerExact

logical: used internally to flag the case where there are explicit formulae for the lower tail version of cdf and quantile function

Symmetry

object of class "DistributionSymmetry"; used internally to avoid unnecessary calculations.

Extends

Class "UnivariateDistribution", directly.
Class "Distribution", by class "UnivariateDistribution".

Methods

initialize

signature(.Object = "DiscreteDistribution"): initialize method

coerce

signature(from = "DiscreteDistribution", to = "LatticeDistribution"): coerce method to class "LatticeDistribution" (checks if support is a lattice)

Math

signature(x = "DiscreteDistribution"): application of a mathematical function, e.g. sin or tan to this discrete distribution

  • abs: signature(x = "DiscreteDistribution"): exact image distribution of abs(x).

  • exp: signature(x = "DiscreteDistribution"): exact image distribution of exp(x).

  • sign: signature(x = "DiscreteDistribution"): exact image distribution of sign(x).

  • sqrt: signature(x = "DiscreteDistribution"): exact image distribution of sqrt(x).

  • log: signature(x = "DiscreteDistribution"): (with optional further argument base, defaulting to exp(1)) exact image distribution of log(x).

  • log10: signature(x = "DiscreteDistribution"): exact image distribution of log10(x).

  • gamma: signature(x = "DiscreteDistribution"): exact image distribution of gamma(x).

  • lgamma: signature(x = "DiscreteDistribution"): exact image distribution of lgamma(x).

  • digamma: signature(x = "DiscreteDistribution"): exact image distribution of digamma(x).

-

signature(e1 = "DiscreteDistribution"): application of ‘-’ to this discrete distribution

*

signature(e1 = "DiscreteDistribution", e2 = "numeric"): multiplication of this discrete distribution by an object of class ‘numeric’

/

signature(e1 = "DiscreteDistribution", e2 = "numeric"): division of this discrete distribution by an object of class ‘numeric’

+

signature(e1 = "DiscreteDistribution", e2 = "numeric"): addition of this discrete distribution to an object of class ‘numeric’

-

signature(e1 = "DiscreteDistribution", e2 = "numeric"): subtraction of an object of class ‘numeric’ from this discrete distribution

*

signature(e1 = "numeric", e2 = "DiscreteDistribution"): multiplication of this discrete distribution by an object of class ‘numeric’

+

signature(e1 = "numeric", e2 = "DiscreteDistribution"): addition of this discrete distribution to an object of class ‘numeric’

-

signature(e1 = "numeric", e2 = "DiscreteDistribution"): subtraction of this discrete distribution from an object of class ‘numeric’

+

signature(e1 = "DiscreteDistribution", e2 = "DiscreteDistribution"): Convolution of two discrete distributions. The slots p, d and q are approximated on a common grid.

-

signature(e1 = "DiscreteDistribution", e2 = "DiscreteDistribution"): Convolution of two discrete distributions. The slots p, d and q are approximated on a common grid.

support

signature(object = "DiscreteDistribution"): returns the support

p.l

signature(object = "DiscreteDistribution"): returns the left continuous cumulative distribution function, i.e.; p.l(t) = P(object < t)

q.r

signature(object = "DiscreteDistribution"): returns the right-continuous quantile function, i.e.; q.r(s)=sup{t|P(object>=t)<=s}

plot

signature(object = "DiscreteDistribution"): plots density, cumulative distribution and quantile function

Internal subclass "AffLinDiscreteDistribution"

To enhance accuracy of several functionals on distributions, mainly from package distrEx, from version 1.9 of this package on, there is an internally used (but exported) subclass "AffLinDiscreteDistribution" which has extra slots a, b (both of class "numeric"), and X0 (of class "DiscreteDistribution"), to capture the fact that the object has the same distribution as a * X0 + b. This is the class of the return value of methods

-

signature(e1 = "DiscreteDistribution")

*

signature(e1 = "DiscreteDistribution", e2 = "numeric")

/

signature(e1 = "DiscreteDistribution", e2 = "numeric")

+

signature(e1 = "DiscreteDistribution", e2 = "numeric")

-

signature(e1 = "DiscreteDistribution", e2 = "numeric")

*

signature(e1 = "numeric", e2 = "DiscreteDistribution")

+

signature(e1 = "numeric", e2 = "DiscreteDistribution")

-

signature(e1 = "numeric", e2 = "DiscreteDistribution")

-

signature(e1 = "AffLinDiscreteDistribution")

*

signature(e1 = "AffLinDiscreteDistribution", e2 = "numeric")

/

signature(e1 = "AffLinDiscreteDistribution", e2 = "numeric")

+

signature(e1 = "AffLinDiscreteDistribution", e2 = "numeric")

-

signature(e1 = "AffLinDiscreteDistribution", e2 = "numeric")

*

signature(e1 = "numeric", e2 = "AffLinDiscreteDistribution")

+

signature(e1 = "numeric", e2 = "AffLinDiscreteDistribution")

-

signature(e1 = "numeric", e2 = "AffLinDiscreteDistribution")

There also is a class union of "AffLinAbscontDistribution", "AffLinDiscreteDistribution", "AffLinUnivarLebDecDistribution" and called "AffLinDistribution" which is used for functionals.

Internal virtual superclass "AcDcLcDistribution"

As many operations should be valid no matter whether the operands are of class "AbscontDistribution", "DiscreteDistribution", or "UnivarLebDecDistribution", there is a class union of these classes called "AcDcLcDistribution"; in partiucalar methods for "*", "/", "^" (see operators-methods) and methods Minimum, Maximum, Truncate, and Huberize, and convpow are defined for this class union.

Note

Working with a computer, we use a finite interval as support which carries at least mass 1-getdistrOption("TruncQuantile").

Also, we require that support points have distance at least getdistrOption("DistrResoltion"), if this condition fails, upon a suggestion by Jacob van Etten, [email protected], we use the global option getdistrOption("DistrCollapse") to decide whether we use collapsing or not. If we do so, we collapse support points if they are too close to each other, taking the (left most) median among them as new support point which accumulates all the mass of the collapsed points. With getdistrOption("DistrCollapse")==FALSE, we at least collapse points according to the result of unique(), and if after this collapsing, the minimal distance is less than getdistrOption("DistrResoltion"), we throw an error. By getdistrOption("DistrCollapse.Unique.Warn"), we control, whether we throw a warning upon collapsing or not.

Author(s)

Thomas Stabla [email protected],
Florian Camphausen [email protected],
Peter Ruckdeschel [email protected],
Matthias Kohl [email protected]

See Also

Parameter-class UnivariateDistribution-class LatticeDistribution-class AbscontDistribution-class Reals-class RtoDPQ.d

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# Dirac-measure at 0
D1 <- DiscreteDistribution(supp = 0)
support(D1)

# simple discrete distribution
D2 <- DiscreteDistribution(supp = c(1:5), prob = c(0.1, 0.2, 0.3, 0.2, 0.2))
plot(D2)
(pp <- p(D2)(support(D2)))
p(D2)(support(D2)-1e-5)
p(D2)(support(D2)+1e-5)
p.l(D2)(support(D2))
p.l(D2)(support(D2)-1e-5)
p.l(D2)(support(D2)+1e-5)
q(D2)(pp)
q(D2)(pp-1e-5)
q(D2)(pp+1e-5)
## in RStudio or Jupyter IRKernel, use q.l(.)(.) instead of q(.)(.)
q.r(D2)(pp)
q.r(D2)(pp-1e-5)
q.r(D2)(pp+1e-5)

Example output

Loading required package: startupmsg
:startupmsg>  Utilities for Start-Up Messages (version 0.9.5)
:startupmsg> 
:startupmsg>  For more information see ?"startupmsg",
:startupmsg>  NEWS("startupmsg")

Loading required package: sfsmisc
:distr>  Object Oriented Implementation of Distributions (version
:distr>  2.7.0)
:distr> 
:distr>  Attention: Arithmetics on distribution objects are
:distr>  understood as operations on corresponding random variables
:distr>  (r.v.s); see distrARITH().
:distr> 
:distr>  Some functions from package 'stats' are intentionally masked
:distr>  ---see distrMASK().
:distr> 
:distr>  Note that global options are controlled by distroptions()
:distr>  ---c.f. ?"distroptions".
:distr> 
:distr>  For more information see ?"distr", NEWS("distr"), as well as
:distr>    http://distr.r-forge.r-project.org/
:distr>  Package "distrDoc" provides a vignette to this package as
:distr>  well as to several extension packages; try
:distr>  vignette("distr").


Attaching package: 'distr'

The following objects are masked from 'package:stats':

    df, qqplot, sd

[1] 0
[1] 0.1 0.3 0.6 0.8 1.0
[1] 0.0 0.1 0.3 0.6 0.8
[1] 0.1 0.3 0.6 0.8 1.0
[1] 0.0 0.1 0.3 0.6 0.8
[1] 0.0 0.1 0.3 0.6 0.8
[1] 0.1 0.3 0.6 0.8 1.0
[1] 1 2 3 4 5
[1] 1 2 3 4 5
[1]   2   3   4   5 NaN
Warning message:
In q(D2)(pp + 1e-05) : q method of D2 produced NaN's 
[1] 2 3 4 5 5
[1] 1 2 3 4 5
[1]   2   3   4   5 NaN
Warning message:
In q.r(D2)(pp + 1e-05) : NaN's produced

distr documentation built on July 9, 2018, 3 a.m.