operators-methods {distr} | R Documentation |
Methods for operators +,-,*,/,... in Package distr
Description
Arithmetics and unary mathematical transformations for distributions
Arguments
e1 , e2 |
objects of class |
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 tosignature(e1 = "UnivariateDistribution", e2 = "numeric")
; exact-
signature(e1 = "UnivariateDistribution", e2= "ANY")
;exact-
signature(e1 = "UnivariateDistribution", e2 = "numeric")
is translated toe1 + (-e2)
; exact-
signature(e1 = "numeric", e2 = "UnivariateDistribution")
is translated to(-e1) + e2
; exact-
signature(e1 = "numeric", e2 = "Beta")
ifncp(e2)==0
ande1 == 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")
ifabs(e2)>0
result again of class"DExp"
; exact*
signature(e1 = "Exp", e2 = "numeric")
ife2>0
result again of class"Exp"
; exact*
signature(e1 = "ExpOrGammaOrChisq", e2 = "numeric")
ife1
is a Gamma distribution ande2>0
result of class"Gammad"
; exact*
signature(e1 = "Weibull", e2 = "numeric")
ife2>0
result of class"Weibull"
; exact*
signature(e1 = "Cauchy", e2 = "numeric")
ifabs(e2)>0
result again of class"Cauchy"
; exact*
signature(e1 = "Dirac", e2 = "numeric")
result again of class"Dirac"
; exact*
signature(e1 = "Norm", e2 = "numeric")
ifabs(e2)>0
result again of class"Norm"
; exact*
signature(e1 = "Unif", e2 = "numeric")
ifabs(e2)>0
result again of class"Unif"
; exact*
signature(e1 = "Logis", e2 = "numeric")
ife2>0
result again of class"Logis"
; exact*
signature(e1 = "Lnorm", e2 = "numeric")
ife2>0
result again of class"Lnorm"
; exact*
signature(e1 = "numeric", e2 = "UnivariateDistribution")
is translated tosignature(e1 = "UnivariateDistribution", e2 = "numeric")
; exact/
signature(e1 = "UnivariateDistribution", e2 = "numeric")
is translated toe1 * (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")
assumese1
,e2
independent; result again of class"AbscontDistribution"
; is generated by FFT+
signature(e1 = "AbscontDistribution", e2 = "DiscreteDistribution")
assumese1
,e2
independent; result again of class"AbscontDistribution"
; is generated by FFT+
signature(e1 = "DiscreteDistribution", e2 = "AbscontDistribution")
assumese1
,e2
independent; result again of class"AbscontDistribution"
; is generated by FFT+
signature(e1 = "LatticeDistribution", e2 = "LatticeDistribution")
assumese1
,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")
assumese1
,e2
independent; result again of class"DiscreteDistribution"
; is generated by explicite convolution+
signature(e1 = "LatticeDistribution", e2 = "DiscreteDistribution")
assumese1
,e2
independent; result again of class"DiscreteDistribution"
; is generated by explicite convolution+
signature(e1 = "UnivarLebDecDistribution", e2 = "UnivarLebDecDistribution")
assumese1
,e2
independent; result again of class"UnivarLebDecDistribution"
; is generated by separate explicite convolution of a.c. and discrete parts ofe1
ande2
and subsequent flattening withflat.LCD
; ifgetdistrOption("withSimplify")
isTRUE
, result is piped through a call tosimplifyD
+
signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution")
: both operands are coerced to class"UnivarLebDecDistribution"
and the corresponding method is used.+
signature(e1 = "Binom", e2 = "Binom")
assumese1
,e2
independent; ifprob(e1)==prob(e2)
, result again of class"Binom"
; uses the convolution formula for binomial distributions; exact+
signature(e1 = "Cauchy", e2 = "Cauchy")
assumese1
,e2
independent; result again of class"Cauchy"
; uses the convolution formula for Cauchy distributions; exact+
signature(e1 = "Chisq", e2 = "Chisq")
assumese1
,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")
assumese1
,e2
independent; ife1
,e2
are Gamma distributions, result is of class"Gammad"
; uses the convolution formula for Gamma distributions; exact+
signature(e1 = "Pois", e2 = "Pois")
assumese1
,e2
independent; result again of class"Pois"
; uses the convolution formula for Poisson distributions; exact+
signature(e1 = "Nbinom", e2 = "Nbinom")
assumese1
,e2
independent; ifprob(e1)==prob(e2)
, result again of class"Nbinom"
; uses the convolution formula for negative binomial distributions; exact+
signature(e1 = "Norm", e2 = "Norm")
assumese1
,e2
independent; result again of class"Norm"
; uses the convolution formula for normal distributions; exact+
signature(e1 = "UnivariateDistribution", e2 = "Dirac")
translated toe1 + location(e2)
; result again of class"Dirac"
; exact+
signature(e1 = "Dirac", e2 = "UnivariateDistribution")
translated toe2 + location(e1)
; result again of class"Dirac"
; exact+
signature(e1 = "Dirac", e2 = "DiscreteDistribution")
translated toe2 + 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 toe1 * location(e2)
; result again of class"Dirac"
; exact*
signature(e1 = "Dirac", e2 = "UnivariateDistribution")
translated toe2 * location(e1)
; result again of class"Dirac"
; exact*
signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution")
: by means ofdecomposePM
e1
ande2
are decomposed into positive and negative parts; of these, convolutions of the corresponding logarithms are computed separately and finallyexp
is applied to them, again separately; the resulting mixing components are then “flattened” to one object of classUnivarLebDecDistribution
byflat.LCD
which according togetdistrOption(withSimplify)
gets piped through a call tosimplifyD
./
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")
: ifd.discrete(e2)(0)*discreteWeight(e2)>0
throws an error (would give division by 0 with positive probability); else by means ofdecomposePM
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 classUnivarLebDecDistribution
byflat.LCD
and according togetdistrOption(withSimplify)
is piped through a call tosimplifyD
; exact../
signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution")
: translated toe1 * (1/e2)
.^
signature(e1 = "AcDcLcDistribution", e2 = "Integer")
: ife2=0
returnsDirac(1)
; ife2=1
returnse1
; ife2<0
translated to(1/e1)^(-e2)
; exact.^
signature(e1 = "AcDcLcDistribution", e2 = "numeric")
: ife2
is integer uses preceding item; else ife1< 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 classUnivarLebDecDistribution
byflat.LCD
and according togetdistrOption(withSimplify)
is piped through a call tosimplifyD
; exact.^
signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution")
: ife1
is negative with positive probability, throws an error ife2
is non-integer with positive probability; ife1
is 0 with positive probability throws an error ife2
is non-integer with positive probability. ife2
is integer with probability 1 usesDiscreteDistribution(supp=e1^(Dirac(x))
for eachx
insupport(e2)
, builds up a corresponding mixing distribution; the latter is “flattened” to one object of classUnivarLebDecDistribution
byflat.LCD
and according togetdistrOption(withSimplify)
is piped through a call tosimplifyD
. Else the result obtains similarly to"*"(signature(e1 = "AcDcLcDistribution", e2 = "AcDcLcDistribution"))
by the exp-log trick and is “flattened” to one object of classUnivarLebDecDistribution
byflat.LCD
and according togetdistrOption(withSimplify)
is piped through a call tosimplifyD
; exact.^
signature(e1 = "numeric", e2 = "AcDcLcDistribution")
: ife1
is negative, throws an error ife2
is non-integer with positive probability; ife1
is 0 throws an error ife2
is non-integer with positive probability. ife2
is integer with probability 1 usesDiscreteDistribution(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 classUnivarLebDecDistribution
byflat.LCD
and according togetdistrOption(withSimplify)
is piped through a call tosimplifyD
; 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
## takes a little time
N ^ P
1.2 ^ N
abs(N) ^ 1.3