Class6 Prep A
Class6 Prep A
Class6 Prep A
b
a
xf(x) dx.
Lets see how this compares with the formula for a discrete random variable:
E(X) =
n
i=1
x
i
p(x
i
).
The discrete formula says to take a weighted sum of the values x
i
of X, where the weights are
the probabilities p(x
i
). Recall that f(x) is a probability density. Its units are prob/(unit of X).
So f(x) dx represents the probability that X is in an innitesimal range of width dx around
x. Thus we can interpret the formula for E(X) as a weighted integral of the values x of X,
where the weights are the probabilities f(x) dx.
As before, the expected value is also called the mean or average.
1
18.05 class 6, Expectation and Variance for Continuous Random Variables 2
3.1 Examples
Lets go through several example computations. Where the solution requires an integration
technique, we push the computation of the integral to the appendix.
Example 1. Let X uniform(0, 1). Find E(X).
answer: X has range [0, 1] and density f(x) = 1. Therefore,
E(X) =
1
0
xdx =
x
2
2
1
0
=
1
2
.
Not surprisingly the mean is at the midpoint of the range.
Example 2. Let X have range [0, 2] and density
3
8
x
2
. Find E(X).
answer:
E(X) =
2
0
xf(x) dx =
2
0
3
8
x
3
dx =
3x
4
32
2
0
=
3
2
.
Does it make sense that this mean is in the right half of the range?
answer: Yes. Since the probability density increases as x increases over the range, the
average value of x should be in the right half of the range.
x
f(x)
1 = 1.5
is pulled to the right of the midpoint 1 because there is more mass to the right.
Example 3. Let X exp(). Find E(X).
answer: The range of X is [0, ) and its pdf is f(x) = e
x
. So (details in appendix)
E(X) =
0
e
x
dx = e
x
e
x
0
=
1
.
x
f(x) = e
x
= 1/
Mean of an exponential random variable
Example 4. Let Z Norm(0, 1). Find E(Z).
answer: The range of Z is (, ) and its pdf is (z) =
1
2
e
z
2
/2
. So (details in
appendix)
E(Z) =
2
ze
z
2
/2
dz =
1
2
e
z
2
/2
= 0 .
18.05 class 6, Expectation and Variance for Continuous Random Variables 3
z
(z)
= 0
The standard normal distribution is symmetric and has mean 0.
3.2 Properties of E(X)
The properties of E(X) for continuous random variables are the same as for discrete ones:
1. If X and Y are random variables on a sample space then
E(X +Y ) = E(X) +E(Y )
2. If a and b are constants then E(aX +b) = aE(X) +b.
Example 5. In this example we verify that for X Norm(, ) we have E(X) = .
answer: Example (4) showed that for standard normal Z, E(Z) = 0. We could mimic the
calculation there to show E(X) = . Instead we will use the properties of E(X). In the
class 5 notes on manipulating random variables we showed that for normal X
Z =
X
Norm(0, 1).
Inverting this formula we have X = Z +. The linearity of expected value now gives
E(X) = E( Z +) = E(Z) + =
3.3 Expectation of Functions of X
This works exactly the same as the discrete case. if h(x) is a function then Y = h(X) is a
random variable and
E(Y ) = E(h(X)) =
h(x)f
X
(x) dx.
Example 6. Let X exp(). Find E(X
2
).
answer: Using integration by parts we have
E(X
2
) =
0
x
2
e
x
dx =
x
2
e
x
2x
e
x
2
e
x
0
=
2
2
.
4 Variance
Now that weve dened expectation for continuous random variables, the denition of vari-
ance is identical to that of discrete random variables.
Denition: Let X be a continuous random variable with mean . The variance of X is
Var(X) = E((X )
2
).
18.05 class 6, Expectation and Variance for Continuous Random Variables 4
4.1 Properties of Variance
These are exactly the same as in the discrete case.
1. If X and Y are independent then Var(X +Y ) = Var(X) + Var(Y ).
2. For constants a and b, Var(aX +b) = a
2
Var(X).
3. Theorem: Var(X) = E(X
2
) E(X)
2
= E(X
2
)
2
.
For Property 1, note carefully the requirement that X and Y are independent.
Property 3 gives a formula for Var(X) that is often easier to use in hand calculations. The
proofs of properties 2 and 3 are essentially identical to those in the discrete case. We will
not give them here.
Example 7. Let X uniform(0, 1). Find Var(X) and
X
.
answer: In Example 1 we found = 1/2. Next we compute
Var(X) = E((X )
2
) =
1
0
(x 1/2)
2
dx =
1
12
.
Example 8. Let X exp(). Find Var(X) and
X
.
answer: In Examples 3 and 6 we computed
E(X) =
0
xe
x
dx =
1
and E(X
2
) =
0
x
2
e
x
dx =
2
2
.
So by Property 3,
Var(X) = E(X
2
) E(X)
2
=
2
2
1
2
=
1
2
and
X
=
1
.
We could have skipped Property 3 and computed this directly from Var(X) =
0
(x 1/)
2
e
x
dx.
Example 9. Let Z Norm(0, 1). Show Var(Z) = 1.
Note: The notation for normal variables is X Norm(,
2
). This is certainly suggestive,
but as mathematicians we need to prove that E(X) = and Var(X) =
2
. Above we
showed E(X) = . This example shows that Var(Z) = 1, just as the notation suggests. In
the next example well show Var(X) =
2
.
answer: Since E(Z) = 0, we have
Var(Z) = E(Z
2
) =
1
z
2
e
z
2
/2
dz.
(using integration by parts with u = z, v
= ze
z
2
/2
u
= 1, v = e
z
2
/2
)
=
1
ze
z
2
/2
+
1
e
z
2
/2
dz.
The rst term equals 0 because the exponential goes to zero much faster than z grows at
both . The second term equals 1 because it represents the total probability integral of
the pdf (z) for Norm(0, 1). So Var(X) = 1.
18.05 class 6, Expectation and Variance for Continuous Random Variables 5
Example 10. Let X Norm(,
2
). Show Var(X) =
2
.
answer: This is an exercise in change of variables. Letting z = (x )/, we have
Var(X) = E((X )
2
) =
1
(x )
2
e
(x)
2
/2
2
dx
=
2
z
2
e
z
2
/2
dz =
2
.
The integral in the last line is the same one we computed for Var(Z).
5 Quantiles
Denition: The median of X is the value x for which P(X x) = P(X x). In other
words, X has equal probability of being above or below the median, and each probability
is therefore 1/2. Since the denition of the cdf is F(x) = P(X x), we can equivalently
dene the median as the value x satisfying F(x) = .5. i.e. F(x) = P(X x) = .5.
Think: What is the median of Z?
answer: By symmetry, the median is 0.
Example 11. Find the median of X exp().
answer: The cdf of X is F(x) = 1e
x
. So F(x) = .5 .5 = 1e
x
x = (ln 2)/ .
Think: In this case the median does not equal the mean of = 1/. Based on the graph
of the pdf of X can you argue why the median is to the left of the mean.
Denition: The p
th
quantile of X is the value q
p
such the F(q
p
) = P(X q
p
) = p. In
particular, in this notation the median is q
.5
.
With respect to the pdf f(x), the quantile q
p
is the value such that there is an area of p to
the left of q
p
and an area of 1 p to the right of q
p
. In the examples below, note how we
can represent the quantile graphically using area of the pdf or height of the cdf.
Example 12. Find the .6 quantile for X U(0, 1).
answer: The cdf for X is F(x) = x on the range [0,1]. So q
.6
= .6.
x
f(x)
q
.6
= .6
left tail area = prob = .6
x
F(x)
q
.6
= .6
F(q
.6
) = .6
1
q
.6
: left tail area = .6 F(q
.6
) = .6
Example 13. Find the .6 quantile of the standard normal distribution.
18.05 class 6, Expectation and Variance for Continuous Random Variables 6
answer: We dont have a formula for the cdf, so we use the R quantile function qnorm.
q
.6
= qnorm(.6, 0, 1) = .25335
z
(z)
q
.6
= .253
Area = prob. = .6
z
(z)
q
.6
= .253
F(q
.6
) = .6
1
q
.6
: left tail area = .6 F(q
.6
) = .6
Quantiles give a useful measure of location for a random variable. We will use them more
in coming lectures.
5.1 Percentiles, deciles, quartiles
For convenience, quantiles are often described in terms of percentiles, deciles or quartiles.
The 60
th
percentile is the same as the .6 quantile. For example you are in the 60
th
percentile
for height if you are taller than 60 percent of the population, i.e. the probability that you
are taller than a randomly chosen person is 60 percent.
Likewise, deciles represent steps of 1/10. The third decile is the .3 quantile. Quartiles are
in steps of 1/4. The third quartile is the .75 quantile and the 75
th
percentile.
6 Appendix: Integral Computation Details
Example 3: Let X exp(). Find E(X).
The range of X is [0, ) and its pdf is f(x) = e
x
. Therefore
E(X) =
0
xf(x) dx =
0
xe
x
dx
(using integration by parts with u = x, v
= e
x
u
= 1, v = e
x
)
= xe
x
0
+
0
e
x
dx
= 0
e
x
0
=
1
.
We used the fact that xe
x
and e
x
go to 0 as x .
Example 4: Let Z Norm(0, 1). Find E(Z).
The range of Z is (, ) and its pdf is (z) =
1
2
e
z
2
/2
. By symmetry the mean must
be 0. The only mathematically tricky part is to show that the integral converges, i.e. that
18.05 class 6, Expectation and Variance for Continuous Random Variables 7
the mean exists at all (some random variable do not have means, but we will not encounter
this very often.) For completeness we include the argument, though this is not something
we will ask you to do. We rst compute the integral from 0 to :
0
z(z) dz =
1
0
ze
z
2
/2
dz.
The u-substitution u = z
2
/2 gives du = z dz. So the integral becomes
1
0
ze
z
2
/2
dz. =
1
0
e
u
du = e
u
0
= 1
Similarly,
0
x
2
f(x) dx =
0
x
2
e
x
dx
(using integration by parts with u = x
2
, v
= e
x
u
= 2x, v = e
x
)
= x
2
e
x
0
+
0
2xe
x
dx
(the rst term is 0, for the second term use integration by parts: u = 2x, v
= e
x
= 2, v =
e
x
)
= 2x
e
x
0
+
0
e
x
dx
= 0 2
e
x
0
=
2
2
.