Docsity

Chapter 3: Expectation and Variance, Study notes of Law

Toggle sidebar
bg1
44
Chapter 3: Expectation and Variance
In the previous chapter we looked at probability, with three major themes:
1. Conditional probability: P(A|B).
2. First-step analysis for calculating eventual probabilities in a stochastic
process.
3. Calculating probabilities for continuous and discrete random variables.
In this chapter, we look at the same themes for expectation and variance.
The expectation of a random variable is the
long-term average of the random
variable.
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.
1. Calculating expectations for continuous and discrete random variables.
2. Conditional expectation: the expectation of a random variable X,condi-
tional on the value taken by another random variable Y. If the value of
Yaffects the value of X(i.e. Xand Yare dependent), the conditional
expectation of Xgiven the value of Ywill be different from the overall
expectation of X.
3. First-step analysis for calculating the expected amount of time needed to
reach a particular state in a process (e.g. the expected number of shots
before we win a game of tennis).
We will also study similar themes for variance.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Chapter 3: Expectation and Variance and more Study notes Law in PDF only on Docsity!

Chapter 3: Expectation and Variance

In the previous chapter we looked at probability, with three major themes:

  1. Conditional probability: P(A | B).
  2. First-step analysis for calculating eventual probabilities in a stochastic process.
  3. Calculating probabilities for continuous and discrete random variables.

In this chapter, we look at the same themes for expectation and variance.

The expectation of a random variable is the long-term average of the random

variable.

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.

  1. Calculating expectations for continuous and discrete random variables.
  2. Conditional expectation: the expectation of a random variable X, condi- tional on the value taken by another random variable Y. If the value of Y affects the value of X (i.e. X and Y are dependent), the conditional expectation of X given the value of Y will be different from the overall expectation of X.
  3. First-step analysis for calculating the expected amount of time needed to reach a particular state in a process (e.g. the expected number of shots before we win a game of tennis).

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 )

= E

g(X)

E

h(Y )

Notes: 1. E(XY ) = E(X)E(Y ) is ONLY generally true if X and Y are

INDEPENDENT.

  1. If X and Y are independent, then E(XY ) = E(X)E(Y ). However, the converse is not generally true: it is possible for E(XY ) = E(X)E(Y ) even though X and Y are dependent.

Probability as an Expectation

Let A be any event. We can write P(A) as an expectation, as follows. Define the indicator function:

IA =

1 if event A occurs,

0 otherwise.

Then IA is a random variable, and

E(IA) =

∑^1

r=

rP(IA = r)

= 0 × P(IA = 0) + 1 × P(IA = 1) = P(IA = 1) = P(A).

Thus P(A) = E(IA) for any event A.

3.2 Variance, covariance, and correlation

The variance of a random variable X is a measure of how spread out it is.

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

Var(X) = E

(X − μX )^2

= E(X^2 ) −

E(X)

The variance is the mean squared deviation of a random variable from its own

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).

E(X) =

−∞

x fX (x) dx =

1

x × 2 x−^2 dx =

1

2 x−^1 dx

[

2 log(x)

] 2

1 = 2 log(2) − 2 log(1)

= 2 log(2).

2. cov(X, Y ) will be negative if large values of X tend to occur with small values

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).

  1. If X and Y are independent, then there is no pattern between large values of X and large values of Y , so cov(X, Y ) = 0. However, cov(X, Y ) = 0 does NOT imply that X and Y are independent, unless X and Y are Normally distributed.

Properties of Variance

i) Let g be a function, and let a and b be constants. For any random variable X (discrete or continuous),

Var

ag(X) + b

= a^2 Var

g(X)

In particular, Var(aX + b) = a^2 Var(X).

ii) Let X and Y be independent random variables. Then

Var(X + Y ) = Var(X) + Var(Y ).

iii) If X and Y are NOT independent, then

Var(X + Y ) = Var(X) + Var(Y ) + 2 cov(X, Y ).

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

is called the conditional distribution of X , given that Y = y.

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(X = x AND 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 :

i) observe a random value of Y ;

ii) fix Y at that observed random value;

iii) evaluate E(X | Y = observed random value).

We obtain a random variable: E(X | Y ) = h(Y ).

The randomness comes from the randomness in Y , not in X.

Conditional expectation, E(X | Y ) , is a random variable

with randomness inherited from Y , not X.

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:

If Y = 1 , then: X | (Y = 1) =

2 with probability 3 / 4

3 with probability 1 / 4

so E(X | Y = 1) = 2 × 34 + 3 × 14 = 94.

If Y = 2 , then: X | (Y = 2) =

4 with probability 3 / 4

6 with probability 1 / 4

so E(X | Y = 2) = 4 × 34 + 6 × 14 = 184.

Thus E(X | Y = y) =

9 / 4 if y = 1

18 / 4 if y = 2.

So E(X | Y = y) is a number depending on y , or a function of y.

Conditional expectation of X given random Y is a random variable:

From above, E(X | Y ) =

9 / 4 if Y = 1 ( probability 1 /8),

18 / 4 if Y = 2 ( probability 7 /8).

So E(X | Y ) =

9 / 4 with probability 1 / 8 ,

18 / 4 with probability 7 / 8.

Thus E(X | Y ) is a random variable.

The randomness in E(X | Y ) is inherited from Y , not from X.

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.

  • Var(X | Y = y) is the variance of X, when Y is fixed at the value Y = y.
  • Var(X | Y ) is a random variable, giving the variance of X when Y is fixed at a value to be selected randomly.

Definition: Let X and Y be random variables. The conditional variance of X, given Y , is given by

Var(X | Y ) = E(X^2 | Y ) −

E(X | Y )

= E

(X − μX | Y )^2 | Y

Like expectation, Var(X | Y = y) is a number depending on y (a function of y ),

while Var(X | Y ) is a random variable with randomness inherited from 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:

E(X) = EY

E(X | Y )

×

×

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 )

]

= EY

[

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 )]

= EY

E(X^2 | Y ) − (E(X | Y ))^2

EY

[E(X | Y )]^2

[

E ︸ Y (E(︷︷X | Y ))︸

E(X) by part (i)

] 2

= EY {E(X^2 | Y )}

E(X^2 ) by part (i)

−EY {[E(X | Y )]^2 } + EY {[E(X | Y )]^2 } − (EX)^2

= E(X^2 ) − (EX)^2

= Var(X) = LHS. 

3.4 Examples of Conditional Expectation and Variance

  1. Swimming with dolphins

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).

(a) Let ‘success’ be ‘bad-weather day’ and ‘failure’ be ‘work-day’.

Then P( success) = P( bad-weather) = p.

Y is the number of failures before the first success.

So

Y ∼ Geometric(p).

Thus

E(Y ) =

1 − p p

Var(Y ) =

1 − p p^2

(b) We know (X | Y ) ∼ Poisson(μY ) : so

E(X | Y ) = Var(X | Y ) = μY.

> # 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.

  1. Randomly stopped sum This model arises very commonly in stochastic processes. A random number N of events occur, and each event i has associated with it some cost, penalty, or reward Xi. The question is to find the mean and variance of the total cost / reward: TN = X 1 + X 2 +... + XN. The difficulty is that the number N of terms in the sum is itself random.

TN is called a randomly stopped sum: it is a sum of Xi ’s, randomly stopped at

the random number of N terms.

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.

(b) Let TN =

∑N

i=1 Xi^. If we knew how many terms were in the sum, we could easily

find E(TN ) and Var(TN ) as the mean and variance of a sum of independent r.v.s.

So ‘pretend’ we know how many terms are in the sum: i.e. condition on N.

E(TN | N ) = E(X 1 + X 2 +... + XN | N )

= E(X 1 + X 2 +... + XN )

(because all Xi s are independent of N )

= E(X 1 ) + E(X 2 ) +... + E(XN )

where N is now considered constant;

(we do NOT need independence of Xi ’s for this)

= N × E(X) (because all Xi ’s have same mean, E(X) )

= 105 N.

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:

E(TN ) = E

{ N

i=

Xi

= μ E(N )

Var(TN ) = Var

{ N

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.

First-step analysis for probabilities uses conditional probability and the Partition

Theorem (Law of Total Probability).

In the same way, we can use first-step analysis for finding the expected reaching

time for a state.

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

uses conditional expectation and the law of total expectation.

First-step analysis for probabilities:

The first-step analysis procedure for probabilities can be summarized as follows:

P( eventual goal) =

first-step

options

P( eventual goal | option)P( option).

This is because the first-step options form a partition of the sample space.

First-step analysis for expected reaching times:

The expression for expected reaching times is very similar:

E( reaching time) =

first-step

options

E( reaching time | option)P( option).