0% found this document useful (0 votes)
170 views15 pages

Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

This document discusses discrete random variables. It defines key terms like random variable, probability mass function (pmf), and cumulative distribution function (cdf). It provides examples of Bernoulli, binomial, and geometric distributions. It discusses how to describe the pmf and cdf using tables and formulas. It also explains how to construct new random variables from existing ones and how to compute expected value. Exercises are provided to help understand these concepts and apply them to problems involving rolling dice.

Uploaded by

Nikitas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views15 pages

Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

This document discusses discrete random variables. It defines key terms like random variable, probability mass function (pmf), and cumulative distribution function (cdf). It provides examples of Bernoulli, binomial, and geometric distributions. It discusses how to describe the pmf and cdf using tables and formulas. It also explains how to construct new random variables from existing ones and how to compute expected value. Exercises are provided to help understand these concepts and apply them to problems involving rolling dice.

Uploaded by

Nikitas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

 1 Discrete Random Variables


1.1 Learning Goals
1. Know the definition of a discrete random variable.
2. Know the Bernoulli, binomial, and geometric distributions and examples of what they model.
3. Be able to describe the probability mass function and cumulative distribution function using
tables and formulas.
4. Be able to construct new random variables from old ones.
5. Know how to compute expected value (mean).

1.2 Random Variables


This quiz is largely about testing your knowledge for some useful terminology, building on the
notions of sample space and probability function. The key words are

1. Random variable
2. Probability mass function (pmf)
3. Cumulative distribution function (cdf)

1.2.1 Recall
A discrete sample space Ω is a finite or listable set of outcomes {𝜔1 , 𝜔2 …}. The probability of
𝜔
an outcome is denoted 𝑃(𝜔). An event 𝐸 is a subset of Ω. The probability of an event 𝐸 is
𝑃(𝐸) = ∑𝜔∈𝐸 𝑃(𝜔).
1.2.2 Random variables as payoff functions
Exercise 1

Roll a die twice and record the outcomes as (i, j), where i is the result of the first roll and j the
result of the second.

a) What is the sample space?

b) What is the probability function 𝑃(𝑖,𝑗)?


In this game, you win 500 if the sum is 7 and lose 100 otherwise. We give this payoff function the
name X and describe it formally by

𝑋(𝑖,𝑗) = { 500  if 𝑖 + 𝑗 = 7


−100  if 𝑖 + 𝑗 ≠ 7 (1)
If we change the game by using the payoff function

𝑌(𝑖,𝑗) = 𝑖𝑗 − 10 (2)
c) which game is better?

localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-a… 1/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

These payoff functions are examples of random variables. A random variable assigns a number to
each outcome in a sample space . More formally:

Definition 1 Let Ω be a sample space. A discrete random variable is a function


𝑋:Ω→𝐑 (3)
that takes a discrete set of values. (Recall that 𝐑 stands for the real numbers.)

Why is X called a random variable? It's random because its value depends on a random outcome
of an experiment. And we treat X like we would a usual variable: we can add it to other random
variables, square it, and so on.

 1.3 Events and random variables


For any value 𝑎 we write 𝑋 = 𝑎 to mean the event consisting of all outcomes 𝜔 with 𝑋(𝜔) = 𝑎.
Exercise 2 In the previous exercise we rolled two dice and defined the payoff function X (which
is a random variable)

a) What is the event 𝑋 = 500?


b) what is the 𝑃(𝑋 = 500)?

c) What is the event 𝑋 = 1000 and its probability 𝑃(𝑋 = 1000) ?

1.4 Probability mass function and cumulative


distribution function
Definition 2

The probability mass function (pmf) of a discrete random variable is the function
𝑝(𝑎) = 𝑃(𝑋 = 𝑎) Note:

1. We always have 0 ≤ 𝑝(𝑎) ≤ 1


.
𝑎
2. We allow to be any number. If 𝑎 is a value that 𝑋 never takes, then 𝑝(𝑎) = 0.
Exercise 3 Let Ω
be our earlier sample space for rolling 2 dice. Define the random variable 𝑀
to be the maximum value of the two dice:

𝑀(𝑖,𝑗) = 𝑚𝑎𝑥(𝑖,𝑗) (4)


.

For example, the roll (3,5) has maximum 5, i.e. M(3, 5) = 5.

a) What are the values of 𝑝(𝑎) for 𝑎 = 1,2,3,4,5,6


b) What is 𝑝(8)?
1.5 Events and inequalities
Inequalities with random variables describe events. For example 𝑋 ≤ 𝑎 is the set of all outcomes
𝜔 such that 𝑋(𝜔) ≤ 𝑎
.
localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-a… 2/15
10/14/2020
() Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

Exercise 4 If our sample space is the set of all pairs of (𝑖,𝑗) coming from rolling two dice and
𝑍(𝑖,𝑗) = 𝑖 + 𝑗 is the sum of the dice then
What is the set 𝑍 ≤ 4?

1.6 The cumulative distribution function (cdf)


Definition 3 The cumulative distribution function (cdf) of a random variable is the function 𝑋 𝐹
given by 𝐹(𝑎) = 𝑃(𝑋 ≤ 𝑎) . We will often shorten this to distribution function.

Note that the definition of 𝐹(𝑎) uses the symbol less than or equal. This will be important for
getting your calculations exactly right.

Example 1 Continuing with the previously defined random variable M, we have

 value  𝑎 : 1 1 3 4 5 6
 pmf  𝑝(𝑎) : 1/36 3/36 5/36 7/36 9/36 11/36
 cdf  𝐹(𝑎) : 1/36 4/36 9/36 16/36 25/36 36/36
𝐹(𝑎) is called the cumulative distribution function because 𝐹(𝑎) gives the total probability that
accumulates by adding up the probabilities 𝑝(𝑏) as 𝑏 runs from −𝑖𝑛𝑓𝑡𝑦 to 𝑎. For example, in the
table above, the entry 16/36 in column 4 for the cdf is the sum of the values of the pmf from
column 1 to column 4. In notation:

As events: 𝑀 ≤ 4 = {1,2,3,4} ; 𝐹(4) = 𝑃(𝑀 ≤ 4) = 1/36 + 3/36 + 5/36 + 7/36 = 16/36


Just like the probability mass function, 𝐹(𝑎) is defined for all values a. In the above example,
𝐹(8) = 1,𝐹(−2) = 0,𝐹(2.5) = 4/36, and 𝐹(𝜋) = 9/36

 1.7 Graphs of 𝑝(𝑎) and 𝐹(𝑎)


We can visualize the pmf and cdf with graphs. For example, let 𝑋 be the number of heads in 3
tosses of a fair coin:

 value 𝑎 : 0 1 2 3
pmf𝑝(𝑎) : 1/8 3/8 3/8 1/8
cdf𝐹(𝑎) : 1/8 4/8 7/8 1
The colored graphs show how the cumulative distribution function is built by accumulating
probability as a increases. The black and white graphs are the more standard presentations.

localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-a… 3/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

Exercise 5 Plot the pmf and cdf for the maximum of two dice exercise.

 1.8 Properties of the cdf 𝐹


The cdf 𝐹 of a random variable satisfies several properties:
1. 𝐹 is non-decreasing. That is, its graph never goes down, or symbolically if 𝑎 ≤ 𝑏 then
𝐹(𝑎) ≤ 𝐹(𝑏).
2. 0 ≤ 𝐹(𝑎) ≤ 1 .
3. lim𝑎→∞ 𝐹(𝑎) = 1, lim𝑎→−∞ 𝐹(𝑎) = 0

In words, (1) says the cumulative probability 𝐹(𝑎) increases or remains constant as 𝑎 increases,
but never decreases; (2) says the accumulated probability is always between 0 and 1; (3) says that
as a gets very large, it becomes more and more certain that 𝑋 ≤ 𝑎 and as a gets very negative it
becomes more and more certain that 𝑋 > 𝑎.

Exercise 6 Why does a cdf satisfy each of these properties?

 1.9 Specific Distributions

1.9.1 Bernoulli Distributions

localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-a… 4/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

Model: The Bernoulli distribution models one trial in an experiment that can result in either
success or failure This is the most important distribution and it is also the simplest. A random
variable 𝑋
has a Bernoulli distribution with parameter if: 𝑝
𝑋 takes the values 0 and 1.
1.
𝑃(𝑋 = 1) = 𝑝 and 𝑃(𝑋 = 0) = 1 − 𝑝.
2.

We will write 𝑋 ∼ Bernoulli (𝑝) or Ber(𝑝) , which is read “X follows a Bernoulli distribution with
parameter p” or “X is drawn from a Bernoulli distribution with parameter p”.

A simple model for the Bernoulli distribution is to flip a coin with probability of heads, with 𝑝 𝑋=1
on heads and 𝑋=0 on tails. The general terminology is to say 𝑋
is 1 on success and 0 on
failure, with success and failure defined by the context.

Many decisions can be modeled as a binary choice, such as votes for or against a proposal. If 𝑝 is
the proportion of the voting population that favors the proposal, than the vote of a random
individual is modeled by a Bernoulli(p).

Here are the table and graphs of the pmf and cdf for the Bernoulli(1/2) distribution and below that
for the general Bernoulli(p) distribution.

 1.10 Binomial Distributions


The binomial distribution 𝐵𝑖𝑛𝑜𝑚𝑖𝑎𝑙(𝑛,𝑝), or 𝐵𝑖𝑛(𝑛,𝑝), models the number of successes in n
independent Bernoulli(p) trials.

A single Bernoulli trial is, say, one toss of a coin. A single binomial trial consists of n Bernoulli trials.
For coin flips the sample space for a Bernoulli trial is {𝐻,𝑇}
. The sample space for a binomial
trial is all sequences of heads and tails of length n. Likewise a Bernoulli random variable takes
values 0 and 1 and a binomial random variables takes values 0,1,2,…,𝑛
.

Remark 1 Binomial(1,p) is the same as Bernoulli(p).

Example 2

localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-a… 5/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

The number of heads in n flips of a coin with probability 𝑝 of heads follows a Binomial(n, p)
distribution.

We describe 𝑋 ∼ Binomial(𝑛,𝑝)
by giving its values and probabilities. For notation we will use
𝑘to mean an arbitrary number between 0 and n.

We remind you that 𝑛 choose 𝑘 = ( 𝑛𝑘 ) = 𝑛 𝐶𝑘 is the number of ways to choose 𝑘 things out
of a collection of 𝑛 things and it has the formula
𝑛 = 𝑛! (5)
( 𝑘 ) 𝑘!(𝑛 − 𝑘)!
Here is a table for the pmf of a Binomial(n,k) random variable

 values 𝑎 : 0 1 2 ⋯ 𝑘
pmf𝑝(𝑎) : (1 − 𝑝)𝑛 ( 𝑛1 ) 𝑝1 (1 − 𝑝)𝑛−1 ( 𝑛2 ) 𝑝2 (1 − 𝑝)𝑛−2 ⋯ ( 𝑘𝑛 ) 𝑝𝑘 (1 −

Exercise 7 What is the pobability of 3 or more heads in 5 tosses of a fair coin?

1.11 Explanation of the binomial probabilities


𝑛 = 5 and 𝑘 = 2 (the argument for arbitrary n and k is identical.) So
For concreteness, let
𝑋 ∼ binomial(5,𝑝) and we want to compute 𝑝(2). The long way to compute 𝑝(2) is to list all the
ways to get exactly 2 heads in 5 coin flips and add up their probabilities. The list has 10 entries:

HHTTT, HTHTT, HTTHT, HTTTH, THHTT, THTHT, THTTH, TTHHT, TTHTH, TTTHH

Each entry has the same probability of occurring, namely

𝑝2 (1 − 𝑝)3 (7)
.

𝑝
This is because each of the two heads has probability and each of the 3 tails has probability
1−𝑝 . Because the individual tosses are independent, we can multiply probabilities. Therefore, the
total probability of exactly 2 heads is the sum of 10 identical probabilities, i.e.
𝑝(2) = 10𝑝2 (1 − 𝑝)3 .

This guides us to the shorter way to do the computation. We have to count the number of
sequences with exactly 2 heads. To do this we need to choose 2 of the tosses to be heads and the
remaining 3 to be tails. The number of such sequences is the number of ways to choose 2 out of 5
5
things, that is
( 2 ). Since each such sequence has the same probability, 𝑝2 (1 − 𝑝)3 , we get the
probability of exactly 2 heads 𝑝(2) =
5
( 2 ) 𝑝2 (1 − 𝑝)3 .
localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-a… 6/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

Here are some binomial probability mass function (here, frequency is the same as probability).

In [12]:  #First, we have to create a vector of quantiles as input for the dbinom R

x_dbinom <- seq(0, 10, by = 1) # Specify x-values fo

#Then, we can apply the dbinom function to this vector as shown below.
#Note that I have specified the size to be equal to 10 (i.e. the number of
#probability for each binomial draw to be equal to 0.5 (i.e. 50%).

y_dbinom <- dbinom(x_dbinom, size = 10, prob = 0.5) # Apply dbinom functi

#If we want to illustrate the output of the dbinom function in a graphic,

plot(y_dbinom, xlab="X", ylab = "Frequency")

localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-a… 7/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

In [13]:  #First, we have to create a vector of quantiles as input for the dbinom R

x_dbinom <- seq(0, 10, by = 1) # Specify x-values fo

#Then, we can apply the dbinom function to this vector as shown below.
#Note that I have specified the size to be equal to 10 (i.e. the number of
#probability for each binomial draw to be equal to 0.1

y_dbinom <- dbinom(x_dbinom, size = 10, prob = 0.1) # Apply dbinom functi

#If we want to illustrate the output of the dbinom function in a graphic,

plot(y_dbinom,xlab="X", ylab = "Frequency")

localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-a… 8/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

In [14]:  #First, we have to create a vector of quantiles as input for the dbinom R

x_dbinom <- seq(0, 20, by = 1) # Specify x-values for binom function

y_dbinom <- dbinom(x_dbinom, size = 20, prob = 0.1) # Apply dbinom functi

#If we want to illustrate the output of the dbinom function in a graphic,

plot(y_dbinom,xlab="X", ylab = "Frequency") # Plot dbinom values

localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-a… 9/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

In [15]:  #First, we have to create a vector of quantiles as input for the dbinom R

x_dbinom <- seq(0, 40, by = 1) # Specify x-values for binom function

y_dbinom <- dbinom(x_dbinom, size = 40, prob = 0.1) # Apply dbinom functi

#If we want to illustrate the output of the dbinom function in a graphic,

plot(y_dbinom,xlab="X", ylab = "Frequency")

 1.12 Geometric Distributions


localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-… 10/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

A geometric distribution models the number of tails before the first head in a sequen
Definition 4 flips (Bernoulli trials).

Example 3 (a) Flip a coin repeatedly. Let 𝑋 be the number of tails before the first heads. So, 𝑋
can equal 0, i.e. the first flip is heads,1,2,…. In principle, it take any nonnegative integer value.
(b) Give a flip of tails the value 0, and heads the value 1. In this case, 𝑋 is the number of 0's
before the first 1.

(c) Give a flip of tails the value 1, and heads the value 0. In this case, 𝑋 is the number of 1's
before the first 0.

(d) Call a flip of tails a success and heads a failure. So, 𝑋 is the number of successes before the
first failure.

(e) Call a flip of tails a failure and heads a success. So, 𝑋 is the number of failures before the
first success.

You create many different scenarios of this type of distribution. The most neutral language is the
number of tails before the first head.

Definition 5 Formal definition. The random variable 𝑋 follows a geometric distribution with
parameter if 𝑝
𝑋 0,1,2,3,…
takes the values
𝑝(𝑘) = 𝑃(𝑋 = 𝑘) = (1 − 𝑝)𝑘𝑝 .
its pmf is given by

We denote this by 𝑋 ∼ geometric (𝑝) or geo(𝑝). In table form we have:

 value  𝑎 : 0 1 2 3 … 𝑘 …
pmf 𝑝(𝑎) : 𝑝 (1 − 𝑝)𝑝 (1 − 𝑝) 𝑝 (1 − 𝑝)3 𝑝 … (1 − 𝑝)𝑘𝑝 …
2
Table: 𝑋 ∼ geometric (𝑝): X = the number of 0s before the first 1.

The geometric distribution is an example of a discrete distribution that takes an infinite number of
possible values. Things can get confusing when we work with successes and failure since we
might want to model the number of successes before the first failure or we might want the number
of failures before the first success. To keep straight things straight you can translate to the neutral
language of the number of tails before the first heads.

Example 4 pmf and cdf for the geometric(1/3) distribution

localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-… 11/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

In [22]:  #illustrate the density of the geometric distribution in a plot.


# Specify x-values for dgeom function
x_pgeom <- seq(2, 10, by = 1)

# Apply dgeom function


y_pgeom <- pgeom(x_pgeom, prob = 1/3)

# Plot dgeom values


plot(y_pgeom)

localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-… 12/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

In [23]:  # shows how to draw a plot of the geometric


#cumulative distribution function (CDF).
# Specify x-values for dgeom function
x_dgeom <- seq(0, 20, by = 1)

# Apply dgeom function


y_dgeom <- dgeom(x_dgeom, prob = 1/3)

# Plot dgeom values


plot(y_dgeom)

Exercise 8 Computing geometric probabilities. Suppose that the inhabitants of an island plan
their families by having babies until the first girl is born. Assume the probability of having a girl
with each pregnancy is 0.5 independent of other pregnancies, that all babies survive and there
are no multiple births. What is the probability that a family has k boys?

1.13 Uniform Distribution


localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-… 13/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

The uniform distribution models any situation where all the outcomes are equally likely.

𝑋 ∼  uniform (𝑁) (8)
𝑋 takes values 1,2,3,…,𝑁 , each with probability 1/𝑁 . We have already seen this distribution
many times when modeling the fair coins (𝑁 = 2), dice (𝑁 = 6), birthdays (𝑁 = 365 ), and

poker hands (𝑁 =
52 ).
(5)
1.14 Arithmetic with Random Variables
We can do arithmetic with random variables. For example, we can add subtract, multiply or square
them.

There is a simple, but extremely important idea for counting. It says that if we have a sequence of
numbers that are either 0 or 1 then the sum of the sequence is the number of 1s.

Example 5 Consider the sequence with five 1s. It is easy to see that the sum of this sequence is
5 the number of 1s.

We illustrates this idea by counting the number of heads in n tosses of a coin.

Example 6

𝑛
Toss a fair coin times. Let 𝑋𝑗
be 1 if the jth toss is heads and 0 if it's tails. So, is a 𝑋𝑗
Bernoulli(1/2) random variable. Let 𝑋
be the total number of heads in the n tosses. Assuming the
tosses are independence, we know 𝑋 ∼ binomial(𝑛,1/2)
. We can also write

𝑋 = 𝑋1 + 𝑋2 + 𝑋3 + … + 𝑋𝑛
Again, this is because the terms in the sum on the right are all either 0 or 1. So, the sum is exactly
the number of 𝑋𝑗
that are 1, i.e. the number of heads.

The important thing to see in the example above is that we've written the more complicated
binomial random variable 𝑋
as the sum of extremely simple random variables . This will allow 𝑋𝑗
us to manipulate X algebraically.

Exercise 9 Suppose X and Y are independent and 𝑋 ∼ binomial(𝑛,1/2) and


𝑌 ∼ binomial(𝑚,1/2). What kind of distribution does X + Y follow? Explain.
Exercise 10 Suppose X and Y are independent random variables with the following tables.

 Values of 𝑋 𝑥 : 1 2 3 4
 pmf  𝑝𝑋 (𝑥) : 1/10 2/10 3/10 4/10 (9)
 Values of 𝑌 𝑦 : 1 2 3 4 5
 pmf  𝑝𝑌 (𝑦) : 1/15 2/15 3/15 4/15 5/15
Check that the total probability for each random variable is 1. Make a table for the random
variable 𝑋+𝑌 .

localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-… 14/15
10/14/2020 Learning Quiz 3 - Discrete Random Variables - Jupyter Notebook

In [ ]: 

localhost:8888/notebooks/Dropbox/statistics 2020 fall/learning quizzes/learning quiz 3/Learning Quiz 3 - Discrete Random Variables .ipynb#Events-… 15/15

You might also like