expectation {adoptr}R Documentation

Expected value of a function

Description

Computes 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 signature 'PointMassPrior,function'
expectation(dist, f, ...)

## S4 method for signature 'ContinuousPrior,function'
expectation(dist, f, ...)

Arguments

dist

a univariate distribution object

f

a univariate function, must be vectorized

...

further optional arguments

Value

numeric, expected value of f with respect to dist

Examples

expectation(PointMassPrior(c(0, .5), c(.3, .7)), identity)
# > .35

expectation(
    ContinuousPrior(function(x) dunif(x, .2, .4), c(.2, .4)),
    identity
)
# > 0.3


[Package adoptr version 1.0.1 Index]