E {distrEx}R Documentation

Generic Function for the Computation of (Conditional) Expectations

Description

Generic function for the computation of (conditional) expectations.

Usage

E(object, fun, cond, ...)

## S4 method for signature 'UnivariateDistribution,
##   missing, missing':
E(object, 
             low = NULL, upp = NULL, Nsim = getdistrExOption("MCIterations"), ...)

## S4 method for signature 'UnivariateDistribution,
##   function, missing':
E(object, fun, 
        useApply = TRUE, low = NULL, upp = NULL,  Nsim = getdistrExOption("MCIterations"), ...)

## S4 method for signature '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"), ...)

## S4 method for signature 'DiscreteDistribution, function,
##   missing':
E(object, fun, useApply = TRUE, 
             low = NULL, upp = NULL, ...)

## S4 method for signature 'AffLinDistribution, missing,
##   missing':
E(object, low = NULL, upp = NULL, ...)

## S4 method for signature 'AffLinUnivarLebDecDistribution,
##   missing, missing':
E(object, low = NULL, upp = NULL, ...)

## S4 method for signature 'MultivariateDistribution,
##   missing, missing':
E(object, 
             Nsim = getdistrExOption("MCIterations"), ...)
## S4 method for signature 'MultivariateDistribution,
##   function, missing':
E(object, fun, useApply = TRUE, 
             Nsim = getdistrExOption("MCIterations"), ...)

## S4 method for signature 'DiscreteMVDistribution,
##   missing, missing':
E(object, low = NULL, upp = NULL, ...)

## S4 method for signature 'DiscreteMVDistribution,
##   function, missing':
E(object, fun, 
             useApply = TRUE, ...)

## S4 method for signature '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"), ...)

## S4 method for signature 'DiscreteCondDistribution,
##   missing, numeric':
E(object, cond, useApply = TRUE,
             low = NULL, upp = NULL, ...)

## S4 method for signature 'UnivariateCondDistribution,
##   function, numeric':
E(object, fun, cond, 
              withCond = FALSE, useApply = TRUE, low = NULL, upp = NULL,
              Nsim = getdistrExOption("MCIterations"), ...)

## S4 method for signature '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")
             , ...)

## S4 method for signature 'DiscreteCondDistribution,
##   function, numeric':
E(object, fun, cond, 
             withCond = FALSE, useApply = TRUE, low = NULL, upp = NULL,...)

## S4 method for signature 'DiscreteCondDistribution,
##   function, numeric':
E(object, fun, cond, 
             withCond = FALSE, useApply = TRUE, low = NULL, upp = NULL,...)
             
## S4 method for signature 'UnivarLebDecDistribution,
##   missing, missing':
E(object, low = NULL, upp = NULL,  
             rel.tol= getdistrExOption("ErelativeTolerance"), 
             lowerTruncQuantile = getdistrExOption("ElowerTruncQuantile"), 
             upperTruncQuantile = getdistrExOption("EupperTruncQuantile"), 
             IQR.fac = getdistrExOption("IQR.fac"), ... )
## S4 method for signature '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"), ... )
## S4 method for signature '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"), ... )
## S4 method for signature '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"), ... )

## S4 method for signature '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"), ... )
## S4 method for signature 'CompoundDistribution, missing,
##   missing':
E(object, low = NULL, upp = NULL, ...)

## S4 method for signature 'Arcsine, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Beta, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Binom, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Cauchy, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Chisq, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Dirac, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'DExp, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Exp, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Fd, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Gammad, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Geom, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Gumbel, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Hyper, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Logis, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Lnorm, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Nbinom, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Norm, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Pareto, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Pois, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Unif, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Td, missing, missing':
E(object, low = NULL, upp = NULL, ...)
## S4 method for signature 'Weibull, missing, missing':
E(object, low = NULL, upp = NULL, ...)

Arguments

object object of class "Distribution"
fun if missing the (conditional) expectation is computed else the (conditional) expection of fun is computed.
cond if not missing the conditional expectation given cond is computed.
Nsim number of MC simulations used to determine the expectation.
rel.tol relative tolerance for distrExIntegrate.
low lower bound of integration range.
upp upper bound of integration range.
lowerTruncQuantile lower quantile for quantile based integration range.
upperTruncQuantile upper quantile for quantile based integration range.
IQR.fac factor for scale based integration range (i.e.; median of the distribution +-IQR.fac*IQR).
... additional arguments to fun
useApply logical: should sapply, respectively apply be used to evaluate fun.
withCond logical: is cond in the argument list of fun.

Details

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.

Value

The (conditional) expectation is computed.

Methods

object = "UnivariateDistribution", fun = "missing", cond = "missing":
expectation of univariate distributions using crude Monte-Carlo integration.
object = "AbscontDistribution", fun = "missing", cond = "missing":
expectation of absolutely continuous univariate distributions using distrExIntegrate.
object = "DiscreteDistribution", fun = "missing", cond = "missing":
expectation of discrete univariate distributions using support and sum.
object = "MultivariateDistribution", fun = "missing", cond = "missing":
expectation of multivariate distributions using crude Monte-Carlo integration.
object = "DiscreteMVDistribution", fun = "missing", cond = "missing":
expectation of discrete multivariate distributions. The computation is based on support and sum.
object = "UnivariateDistribution", fun = "missing", cond = "missing":
expectation of univariate Lebesgue decomposed distributions by separate calculations for discrete and absolutely continuous part.
object = "AffLinDistribution", fun = "missing", cond = "missing":
expectation of an affine linear transformation aX+b as a E[X]+b for X either "DiscreteDistribution" or "AbscontDistribution".
object = "AffLinUnivarLebDecDistribution", fun = "missing", cond = "missing":
expectation of an affine linear transformation aX+b as a E[X]+b for X either "UnivarLebDecDistribution".
object = "UnivariateDistribution", fun = "function", cond = "missing":
expectation of fun under univariate distributions using crude Monte-Carlo integration.
object = "UnivariateDistribution", fun = "function", cond = "missing":
expectation of fun under univariate Lebesgue decomposed distributions by separate calculations for discrete and absolutely continuous part.
object = "AbscontDistribution", fun = "function", cond = "missing":
expectation of fun under absolutely continuous univariate distributions using distrExIntegrate.
object = "DiscreteDistribution", fun = "function", cond = "missing":
expectation of fun under discrete univariate distributions using support and sum.
object = "MultivariateDistribution", fun = "function", cond = "missing":
expectation of multivariate distributions using crude Monte-Carlo integration.
object = "DiscreteMVDistribution", fun = "function", cond = "missing":
expectation of fun under discrete multivariate distributions. The computation is based on support and sum.

object = "UnivariateCondDistribution", fun = "missing", cond = "numeric":
conditional expectation for univariate conditional distributions given cond. The integral is computed using crude Monte-Carlo integration.
object = "AbscontCondDistribution", fun = "missing", cond = "numeric":
conditional expectation for absolutely continuous, univariate conditional distributions given cond. The computation is based on distrExIntegrate.
object = "DiscreteCondDistribution", fun = "missing", cond = "numeric":
conditional expectation for discrete, univariate conditional distributions given cond. The computation is based on support and sum.
object = "UnivariateCondDistribution", fun = "function", cond = "numeric":
conditional expectation of fun under univariate conditional distributions given cond. The integral is computed using crude Monte-Carlo integration.
object = "AbscontCondDistribution", fun = "function", cond = "numeric":
conditional expectation of fun under absolutely continuous, univariate conditional distributions given cond. The computation is based on distrExIntegrate.
object = "DiscreteCondDistribution", fun = "function", cond = "numeric":
conditional expectation of fun under discrete, univariate conditional distributions given cond. The computation is based on support and sum.
object = "UnivarLebDecDistribution", fun = "missing", cond = "missing":
expectation by separate evaluation of expectation of discrete and abs. continuous part and subsequent weighting.
object = "UnivarLebDecDistribution", fun = "function", cond = "missing":
expectation by separate evaluation of expectation of discrete and abs. continuous part and subsequent weighting.
object = "UnivarLebDecDistribution", fun = "missing", cond = "ANY":
expectation by separate evaluation of expectation of discrete and abs. continuous part and subsequent weighting.
object = "UnivarLebDecDistribution", fun = "function", cond = "ANY":
expectation by separate evaluation of expectation of discrete and abs. continuous part and subsequent weighting.
object = "AcDcLcDistribution", fun = "ANY", cond = "ANY":
expectation by first coercing to class "UnivarLebDecDistribution" and using the corresponding method.
object = "CompoundDistribution", fun = "missing", cond = "missing":
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".
object = "Arcsine", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Beta", fun = "missing", cond = "missing":
for noncentrality 0 exact evaluation using explicit expressions.
object = "Binom", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Cauchy", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Chisq", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Dirac", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "DExp", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Exp", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Fd", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Gammad", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Gumbel", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Geom", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Hyper", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Logis", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Lnorm", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Nbinom", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Norm", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Pareto", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Pois", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Unif", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Td", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.
object = "Weibull", fun = "missing", cond = "missing":
exact evaluation using explicit expressions.

Author(s)

Matthias Kohl Matthias.Kohl@stamats.de and Peter Ruckdeschel peter.ruckdeschel@uni-bayreuth.de

See Also

distrExIntegrate, m1df, m2df, Distribution-class

Examples

# 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)

[Package distrEx version 2.1 Index]