Generic function for the computation of (conditional) expectations.
E(object, fun, cond, ...)# S4 method for UnivariateDistribution,missing,missing
E(object,
low = NULL, upp = NULL, Nsim = getdistrExOption("MCIterations"), ...)
# S4 method for UnivariateDistribution,function,missing
E(object, fun,
useApply = TRUE, low = NULL, upp = NULL,
Nsim = getdistrExOption("MCIterations"), ...)
# S4 method for AbscontDistribution,missing,missing
E(object, low = NULL, upp = NULL,
rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE)
# S4 method for AbscontDistribution,function,missing
E(object, fun, useApply = TRUE,
low = NULL, upp = NULL,
rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE)
# S4 method for UnivarMixingDistribution,missing,missing
E(object, low = NULL,
upp = NULL, rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE)
# S4 method for UnivarMixingDistribution,function,missing
E(object, fun,
useApply = TRUE, low = NULL, upp = NULL,
rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE)
# S4 method for UnivarMixingDistribution,missing,ANY
E(object, cond, low = NULL,
upp = NULL, rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE)
# S4 method for UnivarMixingDistribution,function,ANY
E(object, fun, cond,
useApply = TRUE, low = NULL, upp = NULL,
rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE)
# S4 method for DiscreteDistribution,function,missing
E(object, fun, useApply = TRUE,
low = NULL, upp = NULL, ...)
# S4 method for AffLinDistribution,missing,missing
E(object, low = NULL, upp = NULL,
..., diagnostic = FALSE)
# S4 method for AffLinUnivarLebDecDistribution,missing,missing
E(object, low = NULL,
upp = NULL, ..., diagnostic = FALSE)
# S4 method for MultivariateDistribution,missing,missing
E(object,
Nsim = getdistrExOption("MCIterations"), ...)
# S4 method for MultivariateDistribution,function,missing
E(object, fun,
useApply = TRUE, Nsim = getdistrExOption("MCIterations"), ...)
# S4 method for DiscreteMVDistribution,missing,missing
E(object, low = NULL,
upp = NULL, ...)
# S4 method for DiscreteMVDistribution,function,missing
E(object, fun,
useApply = TRUE, ...)
# S4 method for AbscontCondDistribution,missing,numeric
E(object, cond,
useApply = TRUE, low = NULL, upp = NULL,
rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE)
# S4 method for DiscreteCondDistribution,missing,numeric
E(object, cond,
useApply = TRUE, low = NULL, upp = NULL, ...)
# S4 method for UnivariateCondDistribution,function,numeric
E(object, fun, cond,
withCond = FALSE, useApply = TRUE, low = NULL, upp = NULL,
Nsim = getdistrExOption("MCIterations"), ...)
# S4 method for AbscontCondDistribution,function,numeric
E(object, fun, cond,
withCond = FALSE, useApply = TRUE, low = NULL, upp = NULL,
rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac")
, ..., diagnostic = FALSE)
# S4 method for DiscreteCondDistribution,function,numeric
E(object, fun, cond,
withCond = FALSE, useApply = TRUE, low = NULL, upp = NULL,...)
# S4 method for UnivarLebDecDistribution,missing,missing
E(object, low = NULL,
upp = NULL, rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE )
# S4 method for UnivarLebDecDistribution,function,missing
E(object, fun,
useApply = TRUE, low = NULL, upp = NULL,
rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE )
# S4 method for UnivarLebDecDistribution,missing,ANY
E(object, cond, low = NULL,
upp = NULL, rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE )
# S4 method for UnivarLebDecDistribution,function,ANY
E(object, fun, cond,
useApply = TRUE, low = NULL, upp = NULL,
rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE )
# S4 method for AcDcLcDistribution,ANY,ANY
E(object, fun, cond, low = NULL,
upp = NULL, rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = getdistrExOption("IQR.fac"), ..., diagnostic = FALSE)
# S4 method for CompoundDistribution,missing,missing
E(object, low = NULL,
upp = NULL, ..., diagnostic = FALSE)
# S4 method for Arcsine,missing,missing
E(object, low = NULL, upp = NULL, ..., diagnostic = FALSE)
# S4 method for Beta,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...,
diagnostic = FALSE)
# S4 method for Binom,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...)
# S4 method for Cauchy,missing,missing
E(object, low = NULL, upp = NULL, ..., diagnostic = FALSE)
# S4 method for Cauchy,function,missing
E(object, fun, low = NULL, upp = NULL,
rel.tol = getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = max(1e4,getdistrExOption("IQR.fac")),
..., diagnostic = FALSE)
# S4 method for Chisq,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...)
# S4 method for Dirac,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...)
# S4 method for DExp,missing,missing
E(object, low = NULL, upp = NULL, ..., diagnostic = FALSE)
# S4 method for Exp,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...)
# S4 method for Fd,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...,
diagnostic = FALSE)
# S4 method for Gammad,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...,
diagnostic = FALSE)
# S4 method for Gammad,function,missing
E(object, fun, low = NULL, upp = NULL,
rel.tol = getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = max(1e4,getdistrExOption("IQR.fac")), ..., diagnostic = FALSE)
# S4 method for Geom,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...)
# S4 method for Hyper,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...)
# S4 method for Logis,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...,
diagnostic = FALSE)
# S4 method for Lnorm,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...,
diagnostic = FALSE)
# S4 method for Nbinom,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...)
# S4 method for Norm,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...)
# S4 method for Pois,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...)
# S4 method for Unif,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...,
diagnostic = FALSE)
# S4 method for Td,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...,
diagnostic = FALSE)
# S4 method for Weibull,missing,missing
E(object, low = NULL, upp = NULL,
propagate.names=getdistrExOption("propagate.names.functionals"), ...,
diagnostic = FALSE)
# S4 method for Weibull,function,missing
E(object, fun, low = NULL, upp = NULL,
rel.tol = getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = max(1e4,getdistrExOption("IQR.fac")), ..., diagnostic = FALSE)
.qtlIntegrate(object, fun, low = NULL, upp = NULL,
rel.tol= getdistrExOption("ErelativeTolerance"),
lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"),
upperTruncQuantile = getdistrExOption("EupperTruncQuantile"),
IQR.fac = max(1e4,getdistrExOption("IQR.fac")), ...,
.withLeftTail = FALSE, .withRightTail = FALSE, diagnostic = FALSE)
The (conditional) expectation is computed.
object of class "Distribution"
if missing the (conditional) expectation is computed
else the (conditional) expection of fun
is computed.
if not missing the conditional expectation
given cond
is computed.
number of MC simulations used to determine the expectation.
relative tolerance for distrExIntegrate
.
lower bound of integration range.
upper bound of integration range.
lower quantile for quantile based integration range.
upper quantile for quantile based integration range.
factor for scale based integration range (i.e.;
median of the distribution \(\pm\)IQR.fac
\(\times\)IQR).
additional arguments to fun
logical: should sapply
, respectively apply
be used to evaluate fun
.
logical: is cond
in the argument list of fun
.
logical: should left tail (falling into quantile range [0,0.02]) be computed separately to enhance accuracy?
logical: should right tail (falling into quantile range [0.98,1]) be computed separately to enhance accuracy?
logical; if TRUE
, the return value obtains
an attribute "diagnostic"
with diagnostic information on the
integration, i.e., a list with entries method
("integrate"
or "GLIntegrate"
), call
, result
(the complete return
value of the method), args
(the args with which the
method was called), and time
(the time to compute the integral).
logical: should names obtained from parameter
coordinates be propagated to return values of specific S4 methods
for functionals; defaults to the value of the respective
distrExoption
propagate.names.functionals
.
expectation of univariate distributions using crude Monte-Carlo integration.
expectation of absolutely continuous univariate distributions
using distrExIntegrate
.
expectation of discrete univariate distributions using support
and sum
.
expectation of multivariate distributions using crude Monte-Carlo integration.
expectation of discrete multivariate distributions. The computation is based
on support
and sum
.
expectation of univariate Lebesgue decomposed distributions by separate calculations for discrete and absolutely continuous part.
expectation of an affine linear transformation \(aX+b\) as
\(a E[X]+b\) for X
either "DiscreteDistribution"
or "AbscontDistribution"
.
expectation of an affine linear transformation \(aX+b\) as
\(a E[X]+b\) for X
either "UnivarLebDecDistribution"
.
expectation of fun
under univariate distributions using
crude Monte-Carlo integration.
expectation of fun
under univariate Lebesgue decomposed distributions
by separate calculations for discrete and absolutely continuous part.
expectation of fun
under absolutely continuous
univariate distributions using distrExIntegrate
.
expectation of fun
under discrete univariate
distributions using support
and sum
.
expectation of multivariate distributions using crude Monte-Carlo integration.
expectation of fun
under discrete multivariate
distributions. The computation is based on support
and sum
.
conditional expectation for univariate conditional distributions given cond
.
The integral is computed using crude Monte-Carlo integration.
conditional expectation for absolutely continuous, univariate
conditional distributions given cond
. The computation
is based on distrExIntegrate
.
conditional expectation for discrete, univariate conditional
distributions given cond
. The computation is based
on support
and sum
.
conditional expectation of fun
under univariate conditional distributions
given cond
. The integral is computed using crude Monte-Carlo integration.
conditional expectation of fun
under absolutely continuous,
univariate conditional distributions given cond
. The
computation is based on distrExIntegrate
.
conditional expectation of fun
under discrete, univariate
conditional distributions given cond
. The computation is
based on support
and sum
.
expectation by separate evaluation of expectation of discrete and abs. continuous part and subsequent weighting.
expectation by separate evaluation of expectation of discrete and abs. continuous part and subsequent weighting.
expectation by separate evaluation of expectation of discrete and abs. continuous part and subsequent weighting.
expectation by separate evaluation of expectation of discrete and abs. continuous part and subsequent weighting.
expectation is computed component-wise with subsequent weighting acc.
to mixCoeff
.
expectation is computed component-wise with subsequent weighting acc.
to mixCoeff
.
expectation is computed component-wise with subsequent weighting acc.
to mixCoeff
.
expectation is computed component-wise with subsequent weighting acc.
to mixCoeff
.
expectation by first coercing to class "UnivarLebDecDistribution"
and using the corresponding method.
if we are in i.i.d. situation (i.e., slot SummandsDistr
is of
class UnivariateDistribution
) the formula
\(E[N]E[S]\) for \(N\) the frequency distribution and
\(S\) the summand distribution; else we coerce to
"UnivarLebDecDistribution"
.
exact evaluation using explicit expressions.
for noncentrality 0 exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
use integration over the quantile range for numerical integration
via helper function .qtlIntegrate
.
exact evaluation using explicit expressions.
% \item{object = "Gumbel", fun = "missing", cond = "missing":}{ % exact evaluation using explicit expressions.} % \item{object = "GPareto", fun = "missing", cond = "missing":}{ % exact evaluation using explicit expressions.} % \item{object = "GPareto", fun = "function", cond = "missing":}{ % use substitution method (y := log(x)) for numerical integration.}
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
% \item{object = "Pareto", fun = "missing", cond = "missing":}{ % exact evaluation using explicit expressions.}
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
exact evaluation using explicit expressions.
use integration over the quantile range for numerical integration
via helper function .qtlIntegrate
.
Matthias Kohl Matthias.Kohl@stamats.de and Peter Ruckdeschel peter.ruckdeschel@uni-oldenburg.de
The precision of the computations can be controlled via
certain global options; cf. distrExOptions
.
Also note that arguments low
and upp
should be given as
named arguments in order to prevent them to be matched by arguments
fun
or cond
. Also the result, when arguments
low
or upp
is given, is the unconditional value of the
expectation; no conditioning with respect to low <= object <= upp
is done.
For the Cauchy, the Gamma and Weibull distribution for integration with
missing argument cond
but given argument fun
, we use
integration on [0,1] (i.e, via the respective probability transformation).
This done via helper
function .qtlIntegrate
, where both arguments .withLeftTail
and .withRightTail
are TRUE
for the Cauchy and Gamma distributions,
and only .withRightTail
ist TRUE
for the Weibull distribution.
Diagnostics on the involved integrations are available if argument
diagnostic
is TRUE
. Then there is attribute diagnostic
attached to the return value, which may be inspected
and accessed through showDiagnostic
and
getDiagnostic
.
distrExIntegrate
, m1df
, m2df
,
Distribution-class
# mean of Exp(1) distribution
E <- Exp()
E(E) ## uses explicit terms
E(as(E,"AbscontDistribution")) ## uses numerical integration
E(as(E,"UnivariateDistribution")) ## uses simulations
E(E, fun = function(x){2*x^2}) ## uses simulations
# the same operator for discrete distributions:
P <- Pois(lambda=2)
E(P) ## uses explicit terms
E(as(P,"DiscreteDistribution")) ## uses sums
E(as(P,"UnivariateDistribution")) ## uses simulations
E(P, fun = function(x){2*x^2}) ## uses simulations
# second moment of N(1,4)
E(Norm(mean=1, sd=2), fun = function(x){x^2})
E(Norm(mean=1, sd=2), fun = function(x){x^2}, useApply = FALSE)
# conditional distribution of a linear model
D1 <- LMCondDistribution(theta = 1)
E(D1, cond = 1)
E(Norm(mean=1))
E(D1, function(x){x^2}, cond = 1)
E(Norm(mean=1), fun = function(x){x^2})
E(D1, function(x, cond){cond*x^2}, cond = 2, withCond = TRUE, useApply = FALSE)
E(Norm(mean=2), function(x){2*x^2})
E(as(Norm(mean=2),"AbscontDistribution"))
### somewhat less accurate:
E(as(Norm(mean=2),"AbscontDistribution"),
lowerTruncQuantil=1e-4,upperTruncQuantil=1e-4, IQR.fac= 4)
### even less accurate:
E(as(Norm(mean=2),"AbscontDistribution"),
lowerTruncQuantil=1e-2,upperTruncQuantil=1e-2, IQR.fac= 4)
### no good idea, but just as an example:
E(as(Norm(mean=2),"AbscontDistribution"),
lowerTruncQuantil=1e-2,upperTruncQuantil=1e-2, IQR.fac= .1)
### truncation of integration range; see also m1df...
E(Norm(mean=2), low=2,upp=4)
E(Cauchy())
E(Cauchy(),upp=3,low=-2)
# some Lebesgue decomposed distribution
mymix <- UnivarLebDecDistribution(acPart = Norm(), discretePart = Binom(4,.4),
acWeight = 0.4)
E(mymix)
Run the code above in your browser using DataLab