Learn R Programming

algebraic.dist (version 0.9.1)

expectation.empirical_dist: Method for obtaining the expectation of empirical_dist object x under function g.

Description

Method for obtaining the expectation of empirical_dist object x under function g.

Usage

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

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

Arguments

x

The distribution object.

g

The function to take the expectation of.

...

Additional arguments to pass into function g.

control

a list of control parameters: compute_stats - Whether to compute CIs for the expectations, defaults to FALSE n - The number of samples to use for the MC estimate, defaults to 10000 alpha - The significance level for the confidence interval, defaults to 0.05

Examples

Run this code
ed <- empirical_dist(c(1, 2, 3, 4, 5))
expectation(ed)                     # E[X] = 3
expectation(ed, function(x) x^2)    # E[X^2] = 11

Run the code above in your browser using DataLab