






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!























In the previous chapter we looked at probability, with three major themes:
In this chapter, we look at the same themes for expectation and variance.
Imagine observing many thousands of independent random values from the random variable of interest. Take the average of these random values. The expectation is the value of this average as the sample size tends to infinity.
We will repeat the three themes of the previous chapter, but in a different order.
We will also study similar themes for variance.
3.1 Expectation
The mean, expected value, or expectation of a random variable X is writ- ten as E(X) or μX. If we observe N random values of X, then the mean of the N values will be approximately equal to E(X) for large N. The expectation is defined differently for continuous and discrete random variables.
Definition: Let X be a continuous random variable with p.d.f. fX (x). The ex- pected value of X is E(X) =
−∞
xfX (x) dx.
Definition: Let X be a discrete random variable with probability function fX (x). The expected value of X is E(X) =
x
xfX (x) =
x
xP(X = x).
Expectation of g(X) Let g(X) be a function of X. We can imagine a long-term average of g(X) just as we can imagine a long-term average of X. This average is written as E(g(X)). Imagine observing X many times (N times) to give results x 1 , x 2 ,... , xN. Apply the function g to each of these observations, to give g(x 1 ),... , g(xN ). The mean of g(x 1 ), g(x 2 ),... , g(xN ) approaches E(g(X)) as the number of observations N tends to infinity.
Definition: Let X be a continuous random variable, and let g be a function. The expected value of g(X) is E
g(X)
−∞
g(x)fX (x) dx.
Definition: Let X be a discrete random variable, and let g be a function. The expected value of g(X) is
E
g(X)
x
g(x)fX (x) =
x
g(x)P(X = x).
iii) Let X and Y be independent random variables, and g, h be functions. Then
E(XY ) = E(X)E(Y ) E
g(X)h(Y )
g(X)
h(Y )
Notes: 1. E(XY ) = E(X)E(Y ) is ONLY generally true if X and Y are
Probability as an Expectation
Let A be any event. We can write P(A) as an expectation, as follows. Define the indicator function:
Then IA is a random variable, and
r=
rP(IA = r)
= 0 × P(IA = 0) + 1 × P(IA = 1) = P(IA = 1) = P(A).
3.2 Variance, covariance, and correlation
Are the values of X clustered tightly around their mean, or can we commonly observe values of X a long way from the mean value? The variance measures how far the values of X are from their mean, on average.
Definition: Let X be any random variable. The variance of X is
(X − μX )^2
mean.
If X has high variance, we can observe values of X a long way from the mean.
If X has low variance, the values of X tend to be clustered tightly around the mean value.
Example: Let X be a continuous random variable with p.d.f.
fX (x) =
2 x−^2 for 1 < x < 2 , 0 otherwise. Find E(X) and Var(X).
−∞
x fX (x) dx =
1
x × 2 x−^2 dx =
1
2 x−^1 dx
2 log(x)
1 = 2 log(2) − 2 log(1)
= 2 log(2).
of Y , and small values of X tend to occur with large values of Y. For example, if X is age of a randomly selected person, and Y is heart rate, we would expect X and Y to be negatively correlated (older people have slower heart rates).
Properties of Variance
i) Let g be a function, and let a and b be constants. For any random variable X (discrete or continuous),
ag(X) + b
g(X)
ii) Let X and Y be independent random variables. Then
iii) If X and Y are NOT independent, then
Correlation (non-examinable) The correlation coefficient of X and Y is a measure of the linear association between X and Y. It is given by the covariance, scaled by the overall variability in X and Y. As a result, the correlation coefficient is always between −1 and +1, so it is easily compared for different quantities.
Definition: The correlation between X and Y , also called the correlation coefficient, is given by
corr(X, Y ) =
cov(X, Y ) √ Var(X)Var(Y )
The correlation measures linear association between X and Y. It takes values only between −1 and +1, and has the same sign as the covariance.
The correlation is ±1 if and only if there is a perfect linear relationship between X and Y , i.e. corr(X, Y ) = 1 ⇐⇒ Y = aX + b for some constants a and b.
The correlation is 0 if X and Y are independent, but a correlation of 0 does not imply that X and Y are independent.
3.3 Conditional Expectation and Conditional Variance
Throughout this section, we will assume for simplicity that X and Y are dis- crete random variables. However, exactly the same results hold for continuous random variables too.
Suppose that X and Y are discrete random variables, possibly dependent on each other. Suppose that we fix Y at the value y. This gives us a set of conditional probabilities P(X = x | Y = y) for all possible values x of X. This
Definition: Let X and Y be discrete random variables. The conditional probability function of X, given that Y = y, is:
P(X = x | Y = y) =
P(Y = y)
We write the conditional probability function as: fX | Y (x | y) = P(X = x | Y = y).
Note: The conditional probabilities fX | Y (x | y) sum to one, just like any other probability function: ∑
x
P(X = x | Y = y) =
x
P{Y =y}(X = x) = 1,
using the subscript notation P{Y =y} of Section 2.3.
However, we could also evaluate the function at a random value of Y :
Example: Suppose Y =
1 with probability 1/ 8 , 2 with probability 7/ 8 ,
and X | Y =
2 Y with probability 3/ 4 , 3 Y with probability 1/ 4.
Conditional expectation of X given Y = y is a number depending on y:
Conditional expectation of X given random Y is a random variable:
Conditional expectation is a very useful tool for finding the unconditional expectation of X (see below). Just like the Partition Theorem, it is useful because it is often easier to specify conditional probabilities than to specify overall probabilities.
Conditional variance
The conditional variance is similar to the conditional expectation.
Definition: Let X and Y be random variables. The conditional variance of X, given Y , is given by
(X − μX | Y )^2 | Y
Example: In the example above, we had: E(X | Y ) =
9 / 4 with probability 1/ 8 , 18 / 4 with probability 7/ 8. The total average is:
Proof of (i), (ii), (iii): (i) is a special case of (ii), so we just need to prove (ii). Begin at RHS:
RHS = EY
E(g(X) | Y )
x
g(x)P(X = x | Y )
y
x
g(x)P(X = x | Y = y)
P(Y = y)
y
x
g(x)P(X = x | Y = y)P(Y = y)
x
g(x)
y
P(X = x | Y = y)P(Y = y)
x
g(x)P(X = x) (partition rule)
= E(g(X)) = LHS.
(iii) Wish to prove Var(X) = EY [Var(X | Y )] + VarY [E(X | Y )]. Begin at RHS:
EY [Var(X | Y )] + VarY [E(X | Y )]
E(X) by part (i)
E(X^2 ) by part (i)
= Var(X) = LHS.
3.4 Examples of Conditional Expectation and Variance
Fraser runs a dolphin-watch business. Every day, he is unable to run the trip due to bad weather with probability p, independently of all other days. Fraser works every day except the bad-weather days, which he takes as holiday.
Let Y be the number of consecutive days Fraser has to work between bad- weather days. Let X be the total number of customers who go on Fraser’s trip in this period of Y days. Conditional on Y , the distribution of X is (X | Y ) ∼ Poisson(μY ).
(a) Name the distribution of Y , and state E(Y ) and Var(Y ). (b) Find the expectation and the variance of the number of customers Fraser sees between bad-weather days, E(X) and Var(X).
1 − p p
1 − p p^2
> # Find the sample mean of X (should be close to E(X)): > mean(x) [1] 100. > > # Find the sample variance of X (should be close to var(X)): > var(x) [1] 12624. > > # Check the formula for E(X): > 25 * (1 - 0.2) / 0. [1] 100 > > # Check the formula for var(X): > 25 * (1 - 0.2) * (0.2 + 25) / 0.2^ [1] 12600
The formulas we obtained by working give E(X) = 100 and Var(X) = 12600. The sample mean was x = 100.6606 (close to 100), and the sample variance was 12624.47 (close to 12600). Thus our working seems to have been correct.
Example: Think of a cash machine, which has to be loaded with enough money to cover the day’s business. The number of customers per day is a random number N. Customer i withdraws a random amount Xi. The total amount withdrawn during the day is a randomly stopped sum: TN = X 1 +... + XN.
Cash machine example The citizens of Remuera withdraw money from a cash machine according to the following probability function (X): Amount, x ($) 50 100 200 P(X = x) 0.3 0.5 0. The number of customers per day has the distribution N ∼ Poisson(λ).
Let TN = X 1 + X 2 +... + XN be the total amount of money withdrawn in a day, where each Xi has the probability function above, and X 1 , X 2 ,... are independent of each other and of N. TN is a randomly stopped sum, stopped by the random number of N customers. (a) Show that E(X) = 105, and Var(X) = 2725.
(b) Find E(TN ) and Var(TN ): the mean and variance of the amount of money withdrawn each day.
Solution
(a) Exercise.
Check in R (advanced)
> # Create a function tn.func to calculate a single value of T_N > # for a given value N=n: > tn.func <- function(n){ sum(sample(c(50, 100, 200), n, replace=T, prob=c(0.3, 0.5, 0.2))) }
> # Generate 10,000 random values of N, using lambda=50: > N <- rpois(10000, lambda=50) > # Generate 10,000 random values of T_N, conditional on N: > TN <- sapply(N, tn.func) > # Find the sample mean of T_N values, which should be close to > # 105 * 50 = 5250: > mean(TN) [1] 5253. > # Find the sample variance of T_N values, which should be close > # to 13750 * 50 = 687500: > var(TN) [1] 682469. All seems well. Note that the sample variance is often some distance from the true variance, even when the sample size is 10,000.
General result for randomly stopped sums:
Suppose X 1 , X 2 ,... each have the same mean μ and variance σ^2 , and X 1 , X 2 ,... , and N are mutually independent. Let TN = X 1 +... + XN be the randomly stopped sum. By following similar working to that above:
i=
Xi
= μ E(N )
Var(TN ) = Var
i=
Xi
= σ^2 E(N ) + μ^2 Var(N ).
3.5 First-Step Analysis for calculating expected reaching times
Remember from Section 2.6 that we use First-Step Analysis for finding the probability of eventually reaching a particular state in a stochastic process.
This is the expected number of steps that will be needed to reach a particular state from a specified start-point, or the expected length of time it will take to get there if we have a continuous time process.
Just as first-step analysis for probabilities uses conditional probability and the law of total probability (Partition Theorem), first-step analysis for expectations
First-step analysis for probabilities:
The first-step analysis procedure for probabilities can be summarized as follows:
First-step analysis for expected reaching times:
The expression for expected reaching times is very similar: