# operators-methods

From distr v2.6
by Peter Ruckdeschel

##### Methods for operators +,-,*,/,... in Package distr

Arithmetics and unary mathematical transformations for distributions

- Keywords
- distribution, arith, math

##### Arguments

- e1,e2
- objects of class
`"UnivariateDistribution"`

(or subclasses) or`"numeric"`

##### Details

Arithmetics as well as all functions from group `Math`

, see `Math`

are provided for distributions; wherever possible exact expressions are used; else
random variables are generated according to this transformation and subsequently the remaining
slots filled by `RtoDPQ`

, `RtoDPQ.d`

##### Methods

`-`

`signature(e1 = "UnivariateDistribution", e2 = "missing")`

unary operator; result again of class`"UnivariateDistribution"`

; exact`-`

`signature(e1 = "Norm", e2 = "missing")`

unary operator; result again of`"Norm"`

; exact`+`

`signature(e1 = "UnivariateDistribution", e2 = "numeric")`

result again of class`"UnivariateDistribution"`

; exact`+`

`signature(e1 = "AbscontDistribution", e2 = "numeric")`

result of class`"AffLinAbscontDistribution"`

; exact`+`

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

result of class`"AffLinDiscreteDistribution"`

; exact`+`

`signature(e1 = "LatticeDistribution", e2 = "numeric")`

result of class`"AffLinLatticeDistribution"`

; exact`+`

`signature(e1 = "UnivarLebDecDistribution", e2 = "numeric")`

result of class`"AffLinUnivarLebDecDistribution"`

; exact`+`

`signature(e1 = "CompoundDistribution", e2 = "numeric")`

result of class`"AffLinUnivarLebDecDistribution"`

; exact`+`

`signature(e1 = "AffLinAbscontDistribution", e2 = "numeric")`

result again of class`"AffLinAbscontDistribution"`

; exact`+`

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

result again of class`"AffLinDiscreteDistribution"`

; exact`+`

`signature(e1 = "AffLinLatticeDistribution", e2 = "numeric")`

result again of class`"AffLinLatticeDistribution"`

; exact`+`

`signature(e1 = "AffLinUnivarLebDecDistribution", e2 = "numeric")`

result of class`"AffLinUnivarLebDecDistribution"`

; exact`+`

`signature(e1 = "Cauchy", e2 = "numeric")`

result again of class`"Cauchy"`

; exact`+`

`signature(e1 = "Dirac", e2 = "numeric")`

result again of class`"Dirac"`

; exact`+`

`signature(e1 = "Norm", e2 = "numeric")`

result again of class`"Norm"`

; exact`+`

`signature(e1 = "Unif", e2 = "numeric")`

result again of class`"Unif"`

; exact`+`

`signature(e1 = "Logis", e2 = "numeric")`

result again of class`"Logis"`

; exact`+`

`signature(e1 = "numeric", e2 = "UnivariateDistribution")`

is translated to`signature(e1 = "UnivariateDistribution", e2 = "numeric")`

; exact`-`

`signature(e1 = "UnivariateDistribution", e2= "ANY")`

;exact`-`

`signature(e1 = "UnivariateDistribution", e2 = "numeric")`

is translated to`e1 + (-e2)`

; exact`-`

`signature(e1 = "numeric", e2 = "UnivariateDistribution")`

is translated to`(-e1) + e2`

; exact`-`

`signature(e1 = "numeric", e2 = "Beta")`

if`ncp(e2)==0`

and`e1 == 1`

, an exact (central)`Beta(shape1 = shape2(e2), shape2 = shape1(e2))`

is returned, else the default method is used; exact`*`

`signature(e1 = "UnivariateDistribution", e2 = "numeric")`

result again of class`"UnivariateDistribution"`

; exact`*`

`signature(e1 = "AbscontDistribution", e2 = "numeric")`

result of class`"AffLinAbscontDistribution"`

; exact`*`

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

result of class`"AffLinDiscreteDistribution"`

; exact`*`

`signature(e1 = "LatticeDistribution", e2 = "numeric")`

result of class`"AffLinLatticeDistribution"`

; exact`*`

`signature(e1 = "UnivarLebDecDistribution", e2 = "numeric")`

result of class`"AffLinUnivarLebDecDistribution"`

; exact`*`

`signature(e1 = "CompoundDistribution", e2 = "numeric")`

result of class`"AffLinUnivarLebDecDistribution"`

; exact`*`

`signature(e1 = "AffLinAbscontDistribution", e2 = "numeric")`

result again of class`"AffLinAbscontDistribution"`

; exact`*`

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

result again of class`"AffLinDiscreteDistribution"`

; exact`*`

`signature(e1 = "AffLinLatticeDistribution", e2 = "numeric")`

result again of class`"AffLinLatticeDistribution"`

; exact`*`

`signature(e1 = "AffLinUnivarLebDecDistribution", e2 = "numeric")`

result of class`"AffLinUnivarLebDecDistribution"`

; exact`*`

`signature(e1 = "DExp", e2 = "numeric")`

if`abs(e2)>0`

result again of class`"DExp"`

; exact`*`

`signature(e1 = "Exp", e2 = "numeric")`

if`e2>0`

result again of class`"Exp"`

; exact`*`

`signature(e1 = "ExpOrGammaOrChisq", e2 = "numeric")`

if`e1`

is a Gamma distribution and`e2>0`

result of class`"Gammad"`

; exact`*`

`signature(e1 = "Weibull", e2 = "numeric")`

if`e2>0`

result of class`"Weibull"`

; exact`*`

`signature(e1 = "Cauchy", e2 = "numeric")`

if`abs(e2)>0`

result again of class`"Cauchy"`

; exact`*`

`signature(e1 = "Dirac", e2 = "numeric")`

result again of class`"Dirac"`

; exact`*`

`signature(e1 = "Norm", e2 = "numeric")`

if`abs(e2)>0`

result again of class`"Norm"`

; exact`*`

`signature(e1 = "Unif", e2 = "numeric")`

if`abs(e2)>0`

result again of class`"Unif"`

; exact`*`

`signature(e1 = "Logis", e2 = "numeric")`

if`e2>0`

result again of class`"Logis"`

; exact`*`

`signature(e1 = "Lnorm", e2 = "numeric")`

if`e2>0`

result again of class`"Lnorm"`

; exact`*`

`signature(e1 = "numeric", e2 = "UnivariateDistribution")`

is translated to`signature(e1 = "UnivariateDistribution", e2 = "numeric")`

; exact`/`

`signature(e1 = "UnivariateDistribution", e2 = "numeric")`

is translated to`e1 * (1/e2)`

; exact`+`

`signature(e1 = "UnivariateDistribution", e2 = "UnivariateDistribution")`

result again of class`"UnivariateDistribution"`

; is generated by simulations`-`

`signature(e1 = "UnivariateDistribution", e2 = "UnivariateDistribution")`

is translated to`(-e1) + (-e2)`

; result again of class`"UnivariateDistribution"`

; is generated by simulations`-`

`signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution")`

: both operands are coerced to class`"UnivarLebDecDistribution"`

and the corresponding method is used.`+`

`signature(e1 = "AbscontDistribution", e2 = "AbscontDistribution")`

assumes`e1`

,`e2`

independent; result again of class`"AbscontDistribution"`

; is generated by FFT`+`

`signature(e1 = "AbscontDistribution", e2 = "DiscreteDistribution")`

assumes`e1`

,`e2`

independent; result again of class`"AbscontDistribution"`

; is generated by FFT`+`

`signature(e1 = "DiscreteDistribution", e2 = "AbscontDistribution")`

assumes`e1`

,`e2`

independent; result again of class`"AbscontDistribution"`

; is generated by FFT`+`

`signature(e1 = "LatticeDistribution", e2 = "LatticeDistribution")`

assumes`e1`

,`e2`

independent; if the larger lattice-width is an integer multiple of the smaller(in abs. value) one: result again of class`"LatticeDistribution"`

; is generated by D/FFT`+`

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

assumes`e1`

,`e2`

independent; result again of class`"DiscreteDistribution"`

; is generated by explicite convolution`+`

`signature(e1 = "LatticeDistribution", e2 = "DiscreteDistribution")`

assumes`e1`

,`e2`

independent; result again of class`"DiscreteDistribution"`

; is generated by explicite convolution`+`

`signature(e1 = "UnivarLebDecDistribution", e2 = "UnivarLebDecDistribution")`

assumes`e1`

,`e2`

independent; result again of class`"UnivarLebDecDistribution"`

; is generated by separate explicite convolution of a.c. and discrete parts of`e1`

and`e2`

and subsequent flattening with`flat.LCD`

; if`getdistrOption("withSimplify")`

is`TRUE`

, result is piped through a call to`simplifyD`

`+`

`signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution")`

: both operands are coerced to class`"UnivarLebDecDistribution"`

and the corresponding method is used.`+`

`signature(e1 = "Binom", e2 = "Binom")`

assumes`e1`

,`e2`

independent; if`prob(e1)==prob(e2)`

, result again of class`"Binom"`

; uses the convolution formula for binomial distributions; exact`+`

`signature(e1 = "Cauchy", e2 = "Cauchy")`

assumes`e1`

,`e2`

independent; result again of class`"Cauchy"`

; uses the convolution formula for Cauchy distributions; exact`+`

`signature(e1 = "Chisq", e2 = "Chisq")`

assumes`e1`

,`e2`

independent; result again of class`"Chisq"`

; uses the convolution formula for Chisq distributions; exact`+`

`signature(e1 = "Dirac", e2 = "Dirac")`

result again of class`"Dirac"`

; exact`+`

`signature(e1 = "ExpOrGammaOrChisq", e2 = "ExpOrGammaOrChisq")`

assumes`e1`

,`e2`

independent; if`e1`

,`e2`

are Gamma distributions, result is of class`"Gammad"`

; uses the convolution formula for Gamma distributions; exact`+`

`signature(e1 = "Pois", e2 = "Pois")`

assumes`e1`

,`e2`

independent; result again of class`"Pois"`

; uses the convolution formula for Poisson distributions; exact`+`

`signature(e1 = "Nbinom", e2 = "Nbinom")`

assumes`e1`

,`e2`

independent; if`prob(e1)==prob(e2)`

, result again of class`"Nbinom"`

; uses the convolution formula for negative binomial distributions; exact`+`

`signature(e1 = "Norm", e2 = "Norm")`

assumes`e1`

,`e2`

independent; result again of class`"Norm"`

; uses the convolution formula for normal distributions; exact`+`

`signature(e1 = "UnivariateDistribution", e2 = "Dirac")`

translated to`e1 + location(e2)`

; result again of class`"Dirac"`

; exact`+`

`signature(e1 = "Dirac", e2 = "UnivariateDistribution")`

translated to`e2 + location(e1)`

; result again of class`"Dirac"`

; exact`+`

`signature(e1 = "Dirac", e2 = "DiscreteDistribution")`

translated to`e2 + location(e1)`

; result again of class`"Dirac"`

; exact`-`

`signature(e1 = "Dirac", e2 = "Dirac")`

result again of class`"Dirac"`

; exact`*`

`signature(e1 = "Dirac", e2 = "Dirac")`

result again of class`"Dirac"`

; exact`*`

`signature(e1 = "UnivariateDistribution", e2 = "Dirac")`

translated to`e1 * location(e2)`

; result again of class`"Dirac"`

; exact`*`

`signature(e1 = "Dirac", e2 = "UnivariateDistribution")`

translated to`e2 * location(e1)`

; result again of class`"Dirac"`

; exact`*`

`signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution")`

: by means of`decomposePM`

`e1`

and`e2`

are decomposed into positive and negative parts; of these, convolutions of the corresponding logarithms are computed separately and finally`exp`

is applied to them, again separately; the resulting mixing components are then ``flattened'' to one object of class`UnivarLebDecDistribution`

by`flat.LCD`

which according to`getdistrOption(withSimplify)`

gets piped through a call to`simplifyD`

.`/`

`signature(e1 = "Dirac", e2 = "Dirac")`

result again of class`"Dirac"`

; exact`/`

`signature(e1 = "numeric", e2 = "Dirac")`

result again of class`"Dirac"`

; exact`/`

`signature(e1 = "numeric", e2 = "AcDcLcDistribution")`

: if`d.discrete(e2)(0)*discreteWeight(e2)>0`

throws an error (would give division by 0 with positive probability); else by means of`decomposePM`

`e2`

is decomposed into positive and negative parts; then, similarly the result obtains as for`"*"(signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution"))`

by the exp-log trick and is ``flattened'' to one object of class`UnivarLebDecDistribution`

by`flat.LCD`

and according to`getdistrOption(withSimplify)`

is piped through a call to`simplifyD`

; exact..`/`

`signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution")`

: translated to`e1 * (1/e2)`

.`^`

`signature(e1 = "AcDcLcDistribution", e2 = "Integer")`

: if`e2=0`

returns`Dirac(1)`

; if`e2=1`

returns`e1`

; if`e2<0< code=""> translated to`

`(1/e1)^(-e2)`

; exact.`^`

`signature(e1 = "AcDcLcDistribution", e2 = "numeric")`

: if`e2`

is integer uses preceding item; else if`e1< 0`

with positive probability, throughs an error; else the result obtains similarly to`"*"(signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution"))`

by the exp-log trick and is ``flattened'' to one object of class`UnivarLebDecDistribution`

by`flat.LCD`

and according to`getdistrOption(withSimplify)`

is piped through a call to`simplifyD`

; exact.`^`

`signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution")`

: if`e1`

is negative with positive probability, throws an error if`e2`

is non-integer with positive probability; if`e1`

is 0 with positive probability throws an error if`e2`

is non-integer with positive probability. if`e2`

is integer with probability 1 uses`DiscreteDistribution(supp=e1^(Dirac(x))`

for each`x`

in`support(e2)`

, builds up a corresponding mixing distribution; the latter is ``flattened'' to one object of class`UnivarLebDecDistribution`

by`flat.LCD`

and according to`getdistrOption(withSimplify)`

is piped through a call to`simplifyD`

. Else the result obtains similarly to`"*"(signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution"))`

by the exp-log trick and is ``flattened'' to one object of class`UnivarLebDecDistribution`

by`flat.LCD`

and according to`getdistrOption(withSimplify)`

is piped through a call to`simplifyD`

; exact.`^`

`signature(e1 = "numeric", e2 = "AcDcLcDistribution")`

: if`e1`

is negative, throws an error if`e2`

is non-integer with positive probability; if`e1`

is 0 throws an error if`e2`

is non-integer with positive probability. if`e2`

is integer with probability 1 uses`DiscreteDistribution(supp=e1^support(e2), prob=discrete.d(supp))`

else the result obtains similarly to`"*"(signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution"))`

by the exp-log trick and is ``flattened'' to one object of class`UnivarLebDecDistribution`

by`flat.LCD`

and according to`getdistrOption(withSimplify)`

is piped through a call to`simplifyD`

; exact.

##### References

Ruckdeschel, P., Kohl, M.(2014):
General purpose convolution algorithm for distributions
in S4-Classes by means of FFT. *J. Statist. Softw.*
**59**(4): 1-25.

##### See Also

`UnivariateDistribution-class`

`AbscontDistribution-class`

`DiscreteDistribution-class`

`LatticeDistribution-class`

`Norm-class`

`Binom-class`

`Pois-class`

`Dirac-class`

`Cauchy-class`

`Gammad-class`

`Logis-class`

`Lnorm-class`

`Exp-class`

`Weibull-class`

`Nbinom-class`

##### Examples

```
N <- Norm(0,3)
P <- Pois(4)
a <- 3
N + a
N + P
N - a
a * N
a * P
N / a + sin( a * P - N)
N * P
N / N
## Not run:
# ## takes a little time
# N ^ P
# ## End(Not run)
1.2 ^ N
abs(N) ^ 1.3
```

*Documentation reproduced from package distr, version 2.6, License: LGPL-3*

### Community examples

Looks like there are no examples yet.