
Expected value of a function
Source:R/Prior.R, R/ContinuousPrior.R, R/PointMassPrior.R
expectation.RdComputes the expected value of a vectorized, univariate function f
with respect to a distribution dist.
I.e., E[f(X)].
Usage
expectation(dist, f, ...)
# S4 method for class 'ContinuousPrior,function'
expectation(dist, f, ...)
# S4 method for class 'PointMassPrior,function'
expectation(dist, f, ...)Arguments
- dist
a univariate
distributionobject- f
a univariate function, must be vectorized
- ...
further optional arguments
Examples
expectation(
ContinuousPrior(function(x) dunif(x, .2, .4), c(.2, .4)),
identity
)
#> [1] 0.3
# > 0.3
expectation(PointMassPrior(c(0, .5), c(.3, .7)), identity)
#> [1] 0.35
# > .35