Lecture 1: Introduction; Discrete Random Variables

DATA 352/551: Modeling and Simulation

🎲 Random Variables and Sample Spaces

Consider a random experiment like tossing a fair coin. This is a random experiment because the outcome is unknown. The sample space is the set, or collection, of all possible outcomes.

  • Sample space of tossing a fair coin:

A random variable (denoted, say, \(X\)) is a variable whose value depends on the unknown outcome. More formally, a random variable is a functional mapping from the outcome to the real line.

Show lecture notes

For one coin toss, the sample space is \(\{H, T\}\). The outcome is unknown before the experiment, while the sample space lists every outcome that could occur.

🎲 Random Variables and Sample Spaces

  • Suppose you toss a fair coin three times. Let \(X\) be the number of heads you get. What is the sample space? What is the range, or possible values, of $X?

  • Let \(Y\) be the number of tosses until you get the first head. What is the sample space? What is the range of \(Y\)?

Unless otherwise specified, we will use “sample space” to refer to the range of a random variable.

Discrete random variables: A random variable is called discrete if the sample space is finite, such as \(X\) above, or countably infinite, such as \(Y\) above.

Counterexample: the weight of a randomly selected person and the waiting time until the next bus. These are examples of continuous random variables.

Show lecture notes
  1. For three tosses, the outcome sample space is \(\{HHH, HHT, HTH, HTT, THH, THT, TTH, TTT\}\). Since \(X\) counts heads, its range is \(\{0, 1, 2, 3\}\).
  2. For \(Y\), the outcome sample space can be represented by \(\{H, TH, TTH, TTTH, \ldots\}\). The range of \(Y\) is \(\{1, 2, 3, \ldots\}\).

📊 Probability Mass Function

To fully define a random variable, we need to specify its distribution. In the discrete case, this is done by assigning a probability to each outcome in the sample space.

  • Let \(X\) be the outcome of rolling one fair die.
    • Sample space:
    • Corresponding probabilities:

The function \(P(x)\), for \(x = 1, \ldots, 6\), is called the probability mass function for the discrete random variable \(X\).

A valid probability mass function must satisfy these basic conditions:

  1. \(P(x) \ge 0\) for all \(x\) in the sample space (i.e., you cannot assign a negative probability).
  2. \(\sum_{x \in \text{sample space}} P(x) = 1\) (i.e., the total probability across all possible outcomes must equal 1).
Show lecture notes

The random variable \(X\) has a sample space \(\{1, 2, 3, 4, 5, 6\}\). Because the die is fair, each outcome has probability \(1/6\). Thus \(P(x) = 1/6\) for \(x = 1, \ldots, 6\).

🔁 Simulation

We simulate the process of rolling one fair die to verify the probabilities, using random.org/dice. What can we expect from the result?

  • Rolling once:
  • Rolling 10 times:
  • If your goal is to estimate \(P(X = 1)\), how would you do it based on the above simulation?
  • Rolling many, many times: 1,000? 10,000?

Simulation often requires repeating an experiment a large number of times. The result is more trustworthy and can better estimate the truth because the summary of the data, called a “statistic,” has less variation.

Show lecture notes
  • One roll gives one of the six faces, like 3.
  • Ten rolls give a set of random results, like 1, 3, 6, 2, 4, 5, 1, 6, 2, 3.
  • To estimate \(P(X = 1)\), use the observed proportion of rolls that resulted in 1 (\(2/10\) in the above example).
  • With 1,000 or 10,000 rolls, the observed proportion (denoted \(\hat{P}(X = 1)\)) is expected to be close to \(1/6\).

⚠️ Limitations of Simulation

Simulation has limitations when the sample space is very large or when an outcome in the sample space has a very low chance of occurring.

  • Imagine you have a possibly unfair die with 1,000 sides and you want to estimate the probability of rolling a one.
  • If you do not repeat the roll enough times, the outcome of one might not occur at all.
  • For a fair 1000-sided die, the probability of rolling a one is \(1/1{}000\). With \(n\) rolls, the probability of never seeing a one is \((999/1{}000)^n\).

Example 1

Let \(X\) be the number of heads in two coin tosses. The coins are assumed to be fair.

  • a. What is the sample space, or range, of \(X\)?
  • b. What is the probability mass function of \(X\)?
  • c. Verify that this probability mass function satisfies the two conditions.
  • d. Describe how you can use simulation to verify the probabilities empirically.
Show lecture notes
  1. The range is \(\{0, 1, 2\}\).
  2. The PMF is \(P(X = 0) = 1/4\), \(P(X = 1) = 1/2\), and \(P(X = 2) = 1/4\).
  3. All probabilities are nonnegative, and \(1/4 + 1/2 + 1/4 = 1\).
  4. Simulate two fair coin tosses many times, record the number of heads each time, and compare the observed proportions for 0, 1, and 2 heads with the theoretical probabilities (see the four-step thought process on the next slide).

🧭 “Four-Step” Thought Process of a Typical Simulation

Goal: Estimate \(P(X = 0)\) in the previous example, where \(X\) is the number of heads in two coin tosses.

  • Step i. For one simulation, what are you simulating? What is an example of a possible outcome?
  • Step ii. What random variable(s) are you recording?
  • Step iii. Repeat Steps i and ii many times. What would your recorded results look like?
  • Step iv. How do you perform the estimation based on your results?
Show lecture notes
  1. Simulate two fair coin tosses; for example, one outcome could be \(HT\).
  2. Record \(X\), the number of heads in those two tosses. Example: 1.
  3. Repeat the experiment many times; recorded result looks like: 1, 2, 0, 1, 2, …
  4. Estimate \(P(X = 0)\) by the proportion of 0’s in the recorded results.

Example 2

Try the “American voting coin” on random.org/coins: Bush versus Kerry. Let \(X\) be the number of “Bush” outcomes in 5 flips. What is the range of \(X\)? Use the four steps to describe how to estimate \(P(X \le 2)\).

Interpretation: The coin is likely biased. The probability of each side, Bush or Kerry, can represent the percentage of people who would vote for the candidate in a certain population. Suppose you ask five randomly selected people from that population. What is the chance that two or fewer of them would vote for Bush?

  • Step i. One simulation or outcome:
  • Step ii. What to record:
  • Step iii. Repeat many times:
  • Step iv. Summarize the results:
Show lecture notes
  1. Bush, Kerry, Bush, Bush, Kerry.
  2. \(X=3\) (the number of Bush outcomes). The range of \(X\) is \(\{0, 1, 2, 3, 4, 5\}\)
  3. Repeat the five-flip experiment many times. Record: \(3, 2, 1, 4, 0, ...\)
  4. Estimate \(P(X \le 2)\) by the proportion of simulated outcomes that are 0,1, or 2.

Example 3

(Example 1.3 from Introduction to Probability) Simulation is especially useful when probabilities are hard to calculate mathematically.

Suppose we roll a pair of fair dice. A gambler bets that, in 10 rolls, a pair of sixes will appear. What is the chance of winning? Use the four steps to describe how to estimate the chance of winning.

  • Step i. One simulation or outcome:
  • Step ii. What to record:
  • Step iii. Repeat many times:
  • Step iv. Summarize the results:
Show lecture notes
  1. 1-5, 2-4, 6-6, 5-3, 4-2, 6-6, 1-1, 3-3, 2-2, 5-5.
  2. “Win” (since 6-6 appeared at least once).
  3. “Win,” “Lose,” “Win,” …
  4. Estimate the chance of winning by the proportion of “Win” outcomes.

(Optional) the exact probability is \(1 - (35/36)^{10} \approx 0.245\).

Example 4

(Example 1.4 from Introduction to Probability) You play a game with me as follows. A fair coin is tossed. If a head appears, I give you a dollar. If a tail appears, you give me a dollar.

  • a. Suppose we play this game 10 times. Let \(X\) be your net winnings after 10 rounds. Use the four steps to describe how to estimate the distribution of \(X\).
  • b. Suppose you keep playing this game until you win $5. Let \(Y\) be the length of the game you have to play. Can you design a simulation to study the distribution of \(Y\)? Use the four steps to describe how to estimate the distribution of \(Y\).
Show lecture notes For part (a)
  1. One simulation: HHHHTTHTHH (10 tosses of a fair coin).
  2. To record: \(X=4\) (net winnings after 10 tosses). Range of \(X\): \(\{-10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10\}\).
  3. Repeat many times and record: \(4, -2, 0, 6, ...\)
  4. Estimate the distribution of \(X\) by the relative frequencies of the recorded values. Can visualize using a histogram, or calculate the mean/median/percentiles, etc.
For part (b)
  1. One simulation: HHTHTHH (stop when net winnings first reach 5).
  2. To record: \(Y=7\) (the number of tosses). Range of \(Y\): \(\{5, 6, 7, ...\}\).
  3. Repeat many times and record: \(7, 5, 9, ...\)
  4. Estimate the distribution of \(Y\) by the relative frequencies of the recorded values. Can visualize using a histogram, or calculate the mean/median/percentiles, etc.