Expectation operator applied to x of type dist with respect to a function g. Optionally, constructs a confidence interval for the expectation estimate using the Central Limit Theorem.

# S3 method for class 'dist'
expectation(x, g = function(t) t, ..., control = list())

Arguments

x

A dist object.

g

Characteristic function of interest, defaults to identity.

...

Additional arguments to pass to g.

control

A list of control parameters: compute_stats - Logical, whether to compute CIs for the expectations, defaults to FALSE n - Integer, the number of samples to use for the MC estimate, defaults to 10000L alpha - Real, the significance level for the confidence interval, defaults to 0.05

Value

If compute_stats is FALSE, then the estimate of the expectation, otherwise a list with the following components: value - The estimate of the expectation ci - The confidence intervals for each component of the expectation n - The number of samples

Examples

# \donttest{
# MC expectation of X^2 where X ~ Exp(1)
set.seed(1)
ex <- exponential(1)
expectation(ex, g = function(t) t^2)
#> [1] 2
# }