8.3. Expectations of Functions#
Once we have a random variable, we often want to work with functions of it. For example, if a random variables is an estimator, we usually want to see how far it is from the value it is trying to estimate. For example, we might want to see how far a random variable
This section is about finding the expectation of a function of a random variable whose distribution you know. Throughout, we will assume that all the expectations that we are discussing are well defined.
In what follows, let
8.3.1. Linear Function Rule#
Let
This kind of transformation happens for example when you change units of measurement.
If you switch from Celsius to Fahreneheit, then
and .If you switch from inches to centimeters, then
and .
We can find
For example,
The expectation of a linear transformation of
Quick Check
Let
Find
Answer
But expectation behaves differently under non-linear transformation.
See More
8.3.2. Non-linear Function Rule#
Now let
This allows us to write
On the range of
On the domain
On the range of
As before, it is a straightforward matter of grouping to show that all the forms are equivalent.
The first form looks the simplest, but there’s a catch: you need to first find
The third form is the one to use. It uses the known distribution of
Take a generic value
of .Apply
to ; this is a generic value of .Weight
by , which is known.Do this for all
and add. The sum is .
The crucial thing to note about this method is that we didn’t have to first find the distribution of
See More
Let’s see how our method works in some examples.
8.3.3. #
Let
x = np.arange(1, 6)
probs = make_array(0.15, 0.25, 0.3, 0.2, 0.1)
dist = Table().values(x).probabilities(probs)
dist = dist.relabel('Value', 'x').relabel('Probability', 'P(X=x)')
dist
x | P(X=x) |
---|---|
1 | 0.15 |
2 | 0.25 |
3 | 0.3 |
4 | 0.2 |
5 | 0.1 |
Let
To calculate
dist_with_Y = dist.with_column('g(x)', np.abs(dist.column('x')-3)).move_to_end('P(X=x)')
dist_with_Y
x | g(x) | P(X=x) |
---|---|---|
1 | 2 | 0.15 |
2 | 1 | 0.25 |
3 | 0 | 0.3 |
4 | 1 | 0.2 |
5 | 2 | 0.1 |
To get g(x)
and P(X=x)
columns, and add. The calculation shows that
ev_Y = sum(dist_with_Y.column('g(x)') * dist_with_Y.column('P(X=x)'))
ev_Y
0.94999999999999996
8.3.4. #
Let
dist
x | P(X=x) |
---|---|
1 | 0.15 |
2 | 0.25 |
3 | 0.3 |
4 | 0.2 |
5 | 0.1 |
To find
ev_Y = 1*0.15 + 2*0.25 + 3*0.3 + 3*0.2 + 3*0.1
ev_Y
2.45
8.3.5. for a Poisson Variable #
Let
In the next section we will use this to find
Since