E
From distrEx v0.4-2
by Matthias Kohl
Generic Function for the Computation of (Conditional) Expectations
Generic function for the computation of (conditional) expectations.
- Keywords
- methods, distribution
Usage
E(object, fun, cond, ...)
## S3 method for class 'UnivariateDistribution,function,missing':
E(object, fun, cond, useApply = TRUE, ...)
## S3 method for class 'AbscontDistribution,function,missing':
E(object, fun, cond, useApply = TRUE, ...)
## S3 method for class 'DiscreteDistribution,function,missing':
E(object, fun, cond, useApply = TRUE, ...)
## S3 method for class 'MultivariateDistribution,function,missing':
E(object, fun, cond, useApply = TRUE, ...)
## S3 method for class 'DiscreteMVDistribution,function,missing':
E(object, fun, cond, useApply = TRUE, ...)
## S3 method for class 'AbscontCondDistribution,missing,numeric':
E(object, cond, useApply = TRUE)
## S3 method for class 'DiscreteCondDistribution,missing,numeric':
E(object, cond, useApply = TRUE)
## S3 method for class 'UnivariateCondDistribution,function,numeric':
E(object, fun, cond, withCond = FALSE, useApply = TRUE, ...)
## S3 method for class 'AbscontCondDistribution,function,numeric':
E(object, fun, cond, withCond = FALSE, useApply = TRUE, ...)
## S3 method for class 'DiscreteCondDistribution,function,numeric':
E(object, fun, cond, withCond = FALSE, useApply = TRUE, ...)
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. - ...
- additional arguments to
fun
- useApply
- logical: should
sapply
, respectivelyapply
be used to evaluatefund
. - withCond
- logical: is
cond
in the argument list offun
.
Details
The precision of the computations can be controlled via
certain global options; cf. distrExOptions
.
Value
- The (conditional) expectation is computed.
concept
- expectation
- conditional expectation
- integration
See Also
Examples
# mean of Exp(1) distribution
E(Exp())
# 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})
Community examples
Looks like there are no examples yet.