Docsity

Random Variables: Functions that Map Outcomes to Numbers, Slides of Mathematics

Toggle sidebar
bg1
Random Variables
We’ve used probablity to model a variety of experiments, games, and tests. Through-
out, we have tried to compute probabilities of events. We asked, for example, what is the
probability of the event that you win the Monty Hall game? What is the probability of
the event that it rains, given that the weatherman carried his umbrella today? What is the
probability of the event that you have a rare disease, given that you tested positive?
But one can ask more general questions about an experiment. How hard will it rain?
How long will this illness last? How much will I lose playing 6.042 games all day? These
questions are fundamentally different and not easily phrased in terms of events. The
problem is that an event either does or does not happen: you win or lose, it rains or
doesn’t, you’re sick or not. But these new questions are about matters of degree: how
much, how hard, how long? To approach these questions, we need a new mathematical
tool.
1 Random Variables
Let’s begin with an example. Consider the experiment of tossing three independent, un-
biased coins. Let C be the number of heads that appear. Let M = 1 if the three coins
come up all heads or all tails, and let M = 0 otherwise. Now every outcome of the three
coin flips uniquely determines the values of C and M. For example, if we flip heads, tails,
heads, then C = 2 and M = 0. If we flip tails, tails, tails, then C = 0 and M = 1. In effect,
C counts the number of heads, and M indicates whether all the coins match.
Since each outcome uniquely determines C and M, we can regard them as functions
mapping outcomes to numbers. For this experiment, the sample space is:
S ={H HH, HHT, H T H, H T T, THH , T HT, TTH, T T T }
Now C is a function that maps each outcome in the sample space to a number as follows:
C(HHH) = 3 C(T HH ) = 2
C(HH T ) = 2 C(THT) = 1
C(HTH) = 2 C(TTH) = 1
C(HT T ) = 1 C(TTT) = 0
Similarly, M is a function mapping each outcome another way:
M(HHH) = 1 M(T HH ) = 0
M(HH T ) = 0 M(THT) = 0
M(HTH) = 0 M(TTH) = 0
M(HT T ) = 0 M(TTT) = 1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Random Variables: Functions that Map Outcomes to Numbers and more Slides Mathematics in PDF only on Docsity!

We’ve used probablity to model a variety of experiments, games, and tests. Through out, we have tried to compute probabilities of events. We asked, for example, what is the probability of the event that you win the Monty Hall game? What is the probability of the event that it rains, given that the weatherman carried his umbrella today? What is the probability of the event that you have a rare disease, given that you tested positive?

But one can ask more general questions about an experiment. How hard will it rain? How long will this illness last? How much will I lose playing 6.042 games all day? These questions are fundamentally different and not easily phrased in terms of events. The problem is that an event either does or does not happen: you win or lose, it rains or doesn’t, you’re sick or not. But these new questions are about matters of degree: how much, how hard, how long? To approach these questions, we need a new mathematical tool.

1 Random Variables

Let’s begin with an example. Consider the experiment of tossing three independent, un biased coins. Let C be the number of heads that appear. Let M = 1 if the three coins come up all heads or all tails, and let M = 0 otherwise. Now every outcome of the three coin flips uniquely determines the values of C and M. For example, if we flip heads, tails, heads, then C = 2 and M = 0. If we flip tails, tails, tails, then C = 0 and M = 1. In effect, C counts the number of heads, and M indicates whether all the coins match.

Since each outcome uniquely determines C and M , we can regard them as functions mapping outcomes to numbers. For this experiment, the sample space is:

S = {HHH, HHT, HT H, HT T, T HH, T HT, T T H, T T T }

Now C is a function that maps each outcome in the sample space to a number as follows:

C(HHH) = 3 C(T HH) = 2 C(HHT ) = 2 C(T HT ) = 1 C(HT H) = 2 C(T T H) = 1 C(HT T ) = 1 C(T T T ) = 0

Similarly, M is a function mapping each outcome another way:

M (HHH) = 1 M (T HH) = 0 M (HHT ) = 0 M (T HT ) = 0 M (HT H) = 0 M (T T H) = 0 M (HT T ) = 0 M (T T T ) = 1

The functions C and M are examples of random variables. In general, a random variable is a function whose domain is the sample space. (The codomain can be anything, but we’ll usually use a subset of the real numbers.) Notice that the name “random variable” is a misnomer; random variables are actually functions!

1.1 Indicator Random Variables

An indicator random variable (or simply an indicator or a Bernoulli random variable ) is a random variable that maps every outcome to either 0 or 1. The random variable M is an example. If all three coins match, then M = 1; otherwise, M = 0.

Indicator random variables are closely related to events. In particular, an indicator partitions the sample space into those outcomes mapped to 1 and those outcomes mapped to 0. For example, the indicator M partitions the sample space into two blocks as follows:

HHH�� T T T HHT HT H HT T (^) �� T HH T HT T T H� M = 1 M = 0

In the same way, an event partitions the sample space into those outcomes in the event and those outcomes not in the event. Therefore, each event is naturally associated with a certain indicator random variable and vice versa: an indicator for an event E is an indicator random variable that is 1 for all outcomes in E and 0 for all outcomes not in E. Thus, M is an indicator random variable for the event that all three coins match.

1.2 Random Variables and Events

There is a strong relationship between events and more general random variables as well. A random variable that takes on several values partitions the sample space into several blocks. For example, C partitions the sample space as follows:

T T T� �� � T T H� T HT�� HT T� T HH� HT H�� HHT� HHH� �� � C = 0 C = 1 C = 2 C = 3

Each block is a subset of the sample space and is therefore an event. Thus, we can regard an equation or inequality involving a random variable as an event. For example, the event that C = 2 consists of the outcomes T HH, HT H, and HHT. The event C ≤ 1 consists of the outcomes T T T , T T H, T HT , and HT T.

Naturally enough, we can talk about the probability of events defined by equations and inequalities involving random variables. For example:

Pr (M = 1) = Pr (T T T ) + Pr (HHH) 1 1 = + 8 8 1 = 4

for all x 1 in the codomain of R 1 and x 2 in the codomain of R 2. In words, the probability that R 1 takes on a particular value is unaffected by the value of R 2.

As an example, are C and M independent? Intuitively, the answer should be “no”. The number of heads, C, completely determines whether all three coins match; that is, whether M = 1. But to verify this intuition we must find some x 1 , x 2 ∈ R such that:

Pr (C = x 1 ∩ M = x 2 ) = Pr (C = x 1 ) · Pr (M = x 2 )

One appropriate choice of values is x 1 = 2 and x 2 = 1. In that case, we have:

3 1 Pr (C = 2 ∩ M = 1) = 0 but Pr (C = 2) · Pr (M = 1) = = 0 8

The notion of independence generalizes to a set of random variables as follows. Ran dom variables R 1 , R 2 ,... , Rn are mutually independent if

Pr (R 1 = x 1 ∩ R 2 = x 2 ∩ · · · ∩ Rn = xn) = Pr (R 1 = x 1 ) · Pr (R 2 = x 2 ) · · · Pr (Rn = xn)

for all x 1 ,... , xn in the codomains of R 1 ,... , Rn.

A consequence of this definition of mutual independence is that the probability of an assignment to a subset of the variables is equal to the product of the probabilites of the individual assignments. Thus, for example, if R 1 , R 2 ,... , R 100 are mutually independent random variables with codomain N, then it follows that:

Pr (R 1 = 9 ∩ R 7 = 84 ∩ R 23 = 13) = Pr (R 1 = 9) · Pr (R 7 = 84) · Pr (R 23 = 13)

(This follows by summing over all possible values of the other random variables; we omit the details.)

1.5 An Example with Dice

Suppose that we roll two fair, independent dice. The sample space for this experiment consists of all pairs (r 1 , r 2 ) where r 1 , r 2 ∈ { 1 , 2 , 3 , 4 , 5 , 6 }. Thus, for example, the outcome (3, 5) corresponds to rolling a 3 on the first die and a 5 on the second. The probability of each outcome in the sample space is 1 / 6 · 1 /6 = 1/ 36 since the dice are fair and indepen dent.

We can regard the numbers that come up on the individual dice as random variables D 1 and D 2. So D 1 (3, 5) = 3 and D 2 (3, 5) = 5. Then the expression D 1 + D 2 is another random variable; let’s call it T for “total”. More precisely, we’ve defined:

T (w) = D 1 (w) + D 2 (w) for every outcome w

Thus, T (3, 5) = D 1 (3, 5) + D 2 (3, 5) = 3 + 5 = 8. In general, any function of random variables is itself a random variable. For example,

D 1 + cos(D 2 ) is a strange, but well defined random variable.

Let’s also define an indicator random variable S for the event that the total of the two dice is seven: (^) � 1 if T (w) = 7 S(w) = 0 if T (w) =� 7

So S is equal to 1 when the sum is seven and is equal to 0 otherwise. For example, S(4, 3) = 1, but S(5, 3) = 0.

Now let’s consider a couple questions about independence. First, are D 1 and T inde pendent? Intuitively, the answer would seem to be “no” since the number that comes up on the first die strongly affects the total of the two dice. But to prove this, we must find integers x 1 and x 2 such that:

Pr (D 1 = x 1 ∩ T = x 2 ) = Pr (D 1 = x 1 ) · Pr (T = x 2 )

For example, we might choose x 1 = 2 and x 2 = 3. In this case, we have

Pr (T = 2 | D 1 = 3) = 0

since the total can not be only 2 when one die alone is 3. On the other hand, we have:

Pr (T = 2) · Pr (D 1 = 3) = Pr ({ 1 , 1 }) · Pr ({(3, 1), (3, 2),... , (3, 6)}) 1 6 = = 0 36

So, as we suspected, these random variables are not independent.

Are S and D 1 independent? Once again, intuition suggests that the answer is “no”. The number on the first die ought to affect whether or not the sum is equal to seven. But this time intuition turns out to be wrong! These two random variables actually are independent.

Proving that two random variables are independent takes some work. (Fortunately, this is an uncommon task; usually independence is a modeling assumption. Only rarely do random variables unexpectedly turn out to be independent.) In this case, we must show that Pr (S = x 1 ∩ D 1 = x 2 ) = Pr (S = x 1 ) · Pr (D 1 = x 2 ) (1)

for all x 1 ∈ { 0 , 1 } and all x 2 ∈ { 1 , 2 , 3 , 4 , 5 , 6 }. We can work through all these possibilities in two batches:

  • Suppose that x 1 = 1. Then for every value of x 2 we have: 1 Pr (S = 1) = Pr ((1, 6), (2, 5),... , (6, 1)) = 6 1 Pr (D 1 = x 2 ) = Pr ((x 2 , 1), (x 2 , 2),... , (x 2 , 6)) = 6 1 Pr (S = 1 ∩ D 1 = x 2 ) = Pr ((x 2 , 7 − x 2 )) = 36 Since 1 / 6 · 1 /6 = 1/ 36 , the independence condition is satisfied.

6 / 36 6 PDFR(x) 3 / 36

2 3 4 5 6 7 8 9 10 11 12 x ∈ V

The lump in the middle indicates that sums close to 7 are the most likely. The total area of all the rectangles is 1 since the dice must take on exactly one of the sums in V = { 2 , 3 ,... , 12 }.

A closelyrelated idea is the cumulative distribution function (cdf) for a random vari able R. This is a function CDFR : V → [0, 1] defined by:

CDFR(x) = Pr (R ≤ x)

As an example, the cumulative distribution function for the random variable T is shown below:

1 6

CDFR(x)

1 / 2

0 - 2 3 4 5 6 7 8 9 10 11 12 x ∈ V

The height of the ith bar in the cumulative distribution function is equal to the sum of the heights of the leftmost i bars in the probability density function. This follows from the definitions of pdf and cdf:

CDFR(x) = Pr (R ≤ x) = Pr (R = y) y≤x = PDFR(y) y≤x

In summary, PDFR(x) measures the probability that R = x and CDFR(x) measures the probability that R ≤ x. Both the PDFR and CDFR capture the same information

about the random variable R— you can derive one from the other— but sometimes one is more convenient. The key point here is that neither the probability density function nor the cumulative distribution function involves the sample space of an experiment. Thus, through these functions, we can study random variables without reference to a particular experiment.

For the remainder of today, we’ll look at three important distributions and some ap plications.

2.1 Bernoulli Distribution

Indicator random variables are perhaps the most common type because of their close association with events. The probability density function of an indicator random variable B is always

PDFB (0) = p PDFB (1) = 1 − p

where 0 ≤ p ≤ 1. The corresponding cumulative ditribution function is:

CDFB (0) = p CDFB (1) = 1

This is called the Bernoulli distribution. The number of heads flipped on a (possibly biased) coin has a Bernoulli distribution.

2.2 Uniform Distribution

A random variable that takes on each possible values with the same probability is called uniform. For example, the probability density function of a random variable U that is uniform on the set { 1 , 2 ,... , N } is:

1 PDFU (k) = N

And the cumulative distribution function is:

k CDFU (k) = N

Uniform distributions come up all the time. For example, the number rolled on a fair die is uniform on the set { 1 , 2 ,... , 6 }.

Your goal is to guess a number x between L and H. To avoid confusing equality cases, you select x at random from among the halfintegers:

1 1 1 1 , 1 , 2 ,... , n − 2 2 2 2

But what probability distribution should you use?

The uniform distribution turns out to be your best bet. An informal justification is that if I figured out that you were unlikely to pick some number— say 50 12 — then I’d always put 50 and 51 in the evelopes. Then you’d be unlikely to pick an x between L and H and would have less chance of winning.

After you’ve selected the number x, you peek into an envelope and see some number p. If p > x, then you guess that you’re looking at the larger number. If p < x, then you guess that the other number is larger.

All that remains is to determine the probability that this strategy succeeds. We can do this with the usual fourstep method and a tree diagram.

Step 1: Find the sample space. You either choose x too low (< L), too high (> H), or just right (L < x < H). Then you either peek at the lower number (p = L) or the higher number (p = H). This gives a total of six possible outcomes.

x just right

1/

1/

1/

1/ 1/

1/

L/n

(H−L)/n

(n−H)/n

choice of x

# peeked at result probability

win

win x too high

x too low

win

lose

win

lose

L/2n

L/2n

(H−L)/2n

(H−L)/2n

(n−H)/2n

(n−H)/2n

p=H

p=L

p=H

p=L

p=H

p=L

Step 2: Define events of interest. The four outcomes in the event that you win are marked in the tree diagram.

Step 3: Assign outcome probabilities. First, we assign edge probabilities. Your guess x is too low with probability L/n, too high with probability (n − H)/n, and just right with probability (H − L)/n. Next, you peek at either the lower or higher number with equal probability. Multiplying along roottoleaf paths gives the outcome probabilities.

Step 4: Compute event probabilities. The probability of the event that you win is the

sum of the probabilities of the four outcomes in that event:

L H − L n − H Pr (win) = +

H − L

2 n 2 n 2 n 2 n 1 H − L = + 2 2 n 1 1 ≥ + 2 2 n

The final inequality relies on the fact that the higher number H is at least 1 greater than the lower number L since they are required to be distinct.

Sure enough, you win with this strategy more than half the time, regardless of the numbers in the envelopes! For example, if I choose numbers in the range 0 , 1 ,... , 100 , then you win with probability at least 1 + 1 = 50.5%. Even better, if I’m allowed only 2 200 numbers in the range range 0 ,... , 10 , then your probability of winning rises to 55%! By Las Vegas standards, those are great odds!

2.4 Binomial Distribution

Of the more complex distributions, the binomial distribution is surely the most impor tant in computer science. The standard example of a random variable with a binomial distribution is the number of heads that come up in n independent flips of a coin; call this random variable H. If the coin is fair, then H has an unbiased binomial density function:

n PDFH (k) = 2 −n k

This follows because there are n sequences of n coin tosses with exactly k heads, and k each such sequence has probability 2 −n^.

Here is a plot of the unbiased probability density function PDFH (k) corresponding to n = 20 coins flips. The most likely outcome is k = 10 heads, and the probability falls off rapidly for larger and smaller values of k. These falloff regions to the left and right of the main hump are usually called the tails of the distribution.

0 0 5 10 15 20

2.4.2 Approximating the Binomial Density Function

There is an approximate closedform formula for the general binomial density function, though it is a bit unwieldy. First, we need an approximation for a key term in the exact formula, n k.^ For^ convenience,^ let’s^ replace^ k^ by^ αn^ where^ α^ is^ a^ number^ between^0 and

  1. Then, from Stirling’s formula, we find that:

n 2 nH(α) αn

2 πα(1 − α)n

where H(α) is the famous entropy function :

1 1 H(α) = α log 2 + (1 − α) log 2 α 1 − α

This upper bound on n is very tight and serves as an excellent approximation. αn Now let’s plug this formula into the general binomial density function. The probability of flipping αn heads in n tosses of a coin that comes up heads with probability p is:

2 nH(α)^ αn PDFJ (αn) ≤ � · p (1 − p)(1−α)n (2) 2 πα(1 − α)n

This formula is ugly as a bowling shoe, but quite useful. For example, suppose we flip a fair coin n times. What is the probability of getting exactly 12 n heads? Plugging α = 1/ 2 and p = 1/ 2 into this formula gives:

2 nH(1/2) PDFJ (αn) ≤ � 2 −n 2 π(1/2)(1 − (1/2))n

πn

Thus, for example, if we flip a fair coin 100 times, the probability of getting exactly 50 heads is about 1 /

50 π ≈ 0. 079 or around 8%.

2.5 Approximating the Cumulative Binomial Distribution Function

Suppose a coin comes up heads with probability p. As before, let the random variable J be the number of heads that come up on n independent flips. Then the probability of getting at most k heads is given by the cumulative binomial distribution function:

CDFJ (k) = Pr (J ≤ k) k = PDFJ (i) i= �^ k^ � �n = pi (1 − p)n−i i=0^ i

Evaluating this expression directly would be a lot of work for large k and n, so now an approximation would be really helpful. Once again, we can let k = αn; that is, instead of thinking of the absolute number of heads (k), we consider the fraction of flips that are heads (α). The following approximation holds provided α < p:

1 − α CDFJ (αn) ≤ PDFJ (αn) 1 − α/p

1 − α 2 nH(α) αn ≤ · p (1 − p)(1−α)n 1 − α/p

2 πα(1 − α)n

In the first step, we upper bound the summmation with a geometric sum and apply the formula for the sum of a geometric series. (The details are dull and omitted.) Then we insert the approximate formula (2) for PDFJ (αn) from the preceding section.

You have to press a lot of buttons on a calculator to evaluate this formula for a specific choice of α, p, and n. (Even computing H(α) is a fair amount of work!) But for large n, evaluating the cumulative distribution function exactly requires vastly more work! So don’t look gift blessings in the mouth before they hatch. Or something.

As an example, the probability of fliping at most 25 heads in 100 tosses of a fair coin is obtained by setting α = 1/ 4 , p = 1/ 2 and n = 100:

1 − (1/4) 3 CDFJ (n/4) ≤ 1 − (1/4)/(1/2)

· PDFJ (n/4) ≤ 2

· 1. 913 · 10 −^7

This says that flipping 25 or fewer heads is extremely unlikely, which is consistent with our earlier claim that the tails of the binomial distribution are very small. In fact, notice that the probability of flipping 25 or fewer heads is only 50% more than the probability of

Probability slips into a poll since the pollster samples the opinions of a people selected uniformly and independently at random. The results are qualified by saying something like this:

“One can say with 95% confidence that the maximum margin of sampling error is ± 3 percentage points.”

This means that either the number reported in the poll is within 3% of the actual fraction p or else an unlucky 1in20 event happened during the polling process; specifically, the pollster’s random sample was not representative of the population at large. This is not the same thing as saying that there is a 95% chance that the poll is correct; it either is or it isn’t, just as N is either prime or composite regardless of the RabinMiller test results.