Skip to contents

This function calculates the mean/expected value of a discrete distribution with finite support given as a ddf object.

Usage

expected_value(dist)

# S4 method for class 'ddf'
mean(x)

Arguments

dist

A ddf object, the distribution.

x

ddf object, the distribution.

Value

A double.

Details

The expected value of a discrete random variable \(X\) with finite support \(\{x_1, \dots, x_n\}\) and corresponding probabilities \(p_1, \dots, p_n\) is defined as the weighted average of the \(x_k\) values with weights \(p_k\), $$E[X] := \sum_{k=1}^n x_k p_k.$$ As we only work with discrete distributions with finite support, we don't provide a more general definition using the tools from measure theory and instead content ourselves with the basic one above.

Note that there are two ways to use this function, one being expected_value() and the other one being the S4 generic method mean(). See also ‘Examples.’

See also

Examples

# Expected value when throwing a six-sided dice
expected_value(unif(6))
#> [1] 3.5
# Equivalent result using generic method
mean(unif(6))
#> [1] 3.5