Random variables, expectation and variance

(CSCI 2824, Spring 2015)

Topic covered:

  • random variables

  • expectation

  • variance

(Section 6.4 of the book)

Random variables

In an (random) experiment, where we have finitely many possible outcomes, often times it is natural to assign a value to each outcome.

Example 1

When tossing a die, naturally we can get a numerical outcome from {1,2,3,4,5,6}.

Example 2

In the case of flipping a coin, we can assign numerical values for the head and the tail. For instance, we can define a function X:{H,T}to {-1,1}:

    X(omega) = begin{cases} 1 & text{ if }omega=H,      -1 & text{ if }omega=Tend{cases}.

Let's imagine I have a bet with a friend on flipping a coin:

  • my friend would give me $1 if it is a head, and

  • I would give my friend $1 if it is a tail. So the amount of money I win from flipping a coin is either 1 or -1, precisely described by the function X.

Now we can talk about what a random variable is.

Random variables

In an experiment where the sample space Omega is finite (i.e., Omega is the set of all and finitely many possible outputs), a random variable is a function X:Omegato V, where V is a subset of mathbb{R}.

In mathematics, random variables are simply functions (when an experiment has only finitely many outcomes). In practice, we can think of random variables as measurements associating each possible outcome in an experiment with a numerical value.

We are being very careful here avoiding situations where there are infinitely many possible output. In particular, we are avoiding the likes of normal distribution and Poisson distribution, which are often encountered in real life. To fully understand the mathematics behind continuous probability distribution, one would need some basic notion of measure theory.

Expected value

Since we focus only on experiments with finitely many possible outcome, we can assume that every random variable can take on only finitely many possible values.

Expected value of random variables

Suppose we have a random variable X, whose output values lie in the finite set {x_1, x_2, ldots, x_n}. The expected value of X is defined as:

    mathbb{E}[X] triangleq    x_1mathrm{Prob}(X=x_1) + x_2 mathrm{Prob}(X=x_2) + cdots +    x_nmathrm{Prob}(X=x_n).

The expected value of a random variable is simply the average value of the random variable we would get from a random experiment.

Example 3

When we throw a die, we can get one of the six possible values {1,2,3,4,5,6}. What is the expected value of the outcome?

Answer

Each number can be obtained with equal probability frac{1}{6}. Hence the expected value of the outcome is

    1cdotfrac{1}{6}+    2cdotfrac{1}{6}+    3cdotfrac{1}{6}+    4cdotfrac{1}{6}+    5cdotfrac{1}{6}+    6cdotfrac{1}{6} = 3.5.

Example 4

Suppose I have a loaded coin, where

  • mathrm{Prob}(H) = frac23, and

  • mathrm{Prob}(T) = frac13.

I enter a bet with a friend (as in Example 2):

  • I would flip my loaded coin;

  • if it is a head, my friend gives me $1;

  • if it is a tail, I give my friend $1.

What is the expected value of my gain on flipping the coin one time only?

Answer
  • I would get 1 dollar (by getting a H) with probability frac23, and

  • I would get -1 dollar (by getting a T) with probability frac13,

  • so on average, I gain

    1cdotfrac23 + (-1)cdot frac13 = frac13.

Example 5

Following up on Example 4: suppose now that we flip the coin twice. What is the expected value of my gain?

Answer

Here are the four possible outcomes, along with my gain and the probability:

  • HH, $2, probability left(frac{2}{3}right)^2;

  • HT, $0, probability frac23cdotfrac13;

  • TH, $0, probability frac13cdotfrac23;

  • TT, -$2, probability left(frac13right)^2.

Hence the expected value is

 2left(frac{2}{3}right)^2 + 0 cdotfrac23cdotfrac13 + 0 cdot frac13cdotfrac23 -2 left(frac13right)^2 = frac{2}{3}.

As you would expect, I win more on average if we play the flipping coin bet twice instead of once!

The expected value is linear, in the following sense: if X and Y are two random variables defined on the same sample space and beta is a real-valued constant, then

    mathbb{E}[X+beta Y] = mathbb{E}[X]+betamathbb{E}[Y].

Variance

Given a random variable, we can talk about not only the average value (i.e. the expected value), but also how far in general we can expect to be away from the average value. You have probably heard of the term standard deviation in statistics (which is handy for determing your standing in terms of course grades, for example). Like standard deviation, the variance of a random variable measures the spread from the expected value.

Given a random variable X whose output value lies in {x_1,x_2,ldots,x_n}, the variance of X is defined as

 mathrm{Var}(X)  triangleq mathrm{E}[(X-mathrm{E}[x])^2] = sum_{i=1}^n (x_i-mathbb{E}[X])^2mathrm{Prob}(X=x_i).

Example 6

We consider again the scenario in Example 5. We can calculate the variance of my gain:

    left(frac23right)^2left(2-frac{2}{3}right)^2    + frac13cdotfrac23 left(-frac{2}{3}right)^2    + frac23cdotfrac13 left(-frac{2}{3}right)^2    + left(frac13right)^2 left(-2-frac{2}{3}right)^2 =    frac{16}{9}.

What this number says is basically that I do have a good chance of losing money!