Section 6

Simulation of Random Events

(a) Modify the code in Fig. 1.16 to estimate the probability that exactly one of the two devices functions properly. Then find the exact probability using the techniques from earlier sections of this chapter, and compare it to your estimated probability.

(b) Calculate the estimated standard error for the estimated probability in (a).

A M.

Numerade Educator

Imagine you have five independently operating components, each working properly with probability. $8 .$ Use simulation to estimate the probability that

(a) All five components work properly.

(b) At least one of the five components works properly. $[$ Hints for $(a)$ and $(b) :$ You can adapt the code from Example $1.40,$ but the and/or statements will become tedious. Consider using the max and min functions instead.

(c) Calculate the estimated standard errors for your answers in (a) and (b).

Robin C.

Numerade Educator

Consider the system depicted in Exercise $96 .$ Assume the seven components operate independently with the following probabilities of functioning properly: 9 for components 1 and $2 ; .8$ for each of components $3,4,5,6 ;$ and. 95 for component $7 .$ Write a program to estimate the reliability of the system (i.e., the probability the system functions properly).

A M.

Numerade Educator

You have an opportunity to answer six trivia questions about favorite sports team, and you will win a pair of tickets to their next game if you can correctly answer at least three of the questions. Write a simulation program to estimate the chance you win the tickets under each of the following assumptions.

(a) You have a $50-50$ chance of getting any question right, independent of all others.

(b) Being a true fan, you have a 75$\%$ chance of getting any question right, independent of all others.

(c) The first three questions are fairly easy, so you have a. 75 chance of getting each of those right. However, the last three questions are much harder, and you only have a .3 probability of correctly answering each of those.

Robin C.

Numerade Educator

In the game "Now or Then" on the television show The Price is Right, the contestant faces a wheel with six sectors. Each sector contains a grocery item and a price, and the contestant must decide whether the price is "now" (i.e., the item's price the day of the taping) or "then" (the price at some specified past date, such as September 2003 . The contestant wins a prize (bedroom furniture, a Caribbean cruise, etc.) if s/he guesses correctly on three adjacent sectors. That is, numbering the sectors $1-6$ clockwise, correct guesses on sectors $5,6,$ and 1 wins the prize but not on sectors $5,6,$ and $3,$ since the latter are not all adjacent. The contestant gets to guess on all six sectors, if need be.)

Write a simulation program to estimate the probability the contestant wins the prize, assuming her/his guesses are independent from item to item. Provide estimated probabilities under each of the following assumptions: (1) each guess is "wild" and thus has probability. 5 of being correct, and $(2)$ the contestant is a good shopper, with probability.8 of being correct on any item.

A M.

Numerade Educator

Refer to the game in Example $1.41 .$ Under the same settings as in that example, estimate the probability the player is ahead at any time during the 25 plays. IHint: This occurs if the player's dollar amount is positive at any of the 25 steps in the loop. So, you will need to keep track of every value of the dollar variable, not just the final result.]

Robin C.

Numerade Educator

Refer again to Example $1.41 .$ Estimate the probability that the player experiences a "swing" of at least $\$ 5$ during the game. That is, estimate the chance that the difference between the largest and smallest dollar amounts during the game is at least $5 .$ (This would happen, for instance, if the player was at one point ahead at $+\$ 2$ but later fell behind to $-\$ 3 . )$

A M.

Numerade Educator

Each of this book's authors has a fair coin. Carlton tosses his coin repeatedly until obtaining the sequence HTT. Devore tosses his coin until the sequence HTH is obtained.

(a) Write a program to simulate Carlton's coin tossing and, separately, Devore's. Your program should keep track of the number of tosses each author requires on each simulation run to achieve his target sequence.

(b) Estimate the probability that Devore obtains his sequence with fewer tosses than Carlton requires to obtain his sequence.

Robin C.

Numerade Educator

There's a 40 -question multiple-choice exam we sometimes administer in our lower-level statistics classes. The exam has a peculiar feature: 10 of the questions have two options, 13 have three options, 13 have four options, and the other 4 have five options. (FYI, this is completely real!) What is the probability that, purely by guessing, a student could get at least half of these questions correct? Write a simulation program to answer this question.

A M.

Numerade Educator

Major League Baseball teams play a 162 -game season, during which fans are often excited by long winning streaks and frustrated by long losing streaks. But how unusual are these streaks, really? How long a streak would you expect if the team's performance were independent from game to game?

Write a program that simulates a 162 -game season, i.e., a string of 162 wins and losses, with $P($ win $)=p$ for each game (the value of $p$ to be specified later). Use your program with at least $10,000$ runs to answer the following questions.

(a) Suppose you're rooting for a ".500" team-that is, $p=.5 .$ What is the probability of observing a streak of at least five wins in a 162 -game season? Estimate this probability with your program, and include a standard error.

(b) Suppose instead your team is quite good: a.600 team overall, so $p=.6 .$ Intuitively, should the probability of a winning streak of at least five games be higher or lower? Explain.

(c) Use your program with $p=.6$ to estimate the probability alluded to in (b). Is your answer higher or lower than $(a) ?$ Is that what you anticipated?

Robin C.

Numerade Educator

A derangement of the numbers 1 through $n$ is a permutation of all $n$ those numbers such that none of them is in the "right place." For example, 34251 is a derangement of 1 through $5,$ but 24351 is not because 3 is in the 3 rd position. We will use simulation to estimate the number of derangements of the numbers 1 through 12 .

(a) Write a program that generates random permutations of the integers $1,2, \ldots, 12 .$ Your program should determine whether or not each permutation is a derangement.

(b) Based on your program, estimate $P(D),$ where $D=\{a$ permutation of $1-12$ is a derangement $\}$

(c) From Sect. $1.3,$ we know the number of permutations of $n$ items. (How many is that for $n=12 ?$ Use this information and your answer to part (b) to estimate the number of derangements of the numbers 1 through $12 .$

$[$ Hint for part $(a) :$ Use random sampling without replacement as in Example $1.42 .$ Alternatively, the randperm command in Matlab can also be employed.]

A M.

Numerade Educator

The book's Introduction discussed the famous Birthday Problem, which was solved in Example 1.22 of Sect. $1.3 .$ Now suppose you have 500 Facebook friends. Make the same assumptions here as in the Birthday Problem.

(a) Write a program to estimate the probability that, on at least 1 daring the year, Facebook tells you three (or more) of your friends share that birthday. Based on your answer, should you be surprised by this occurrence?

(b) Write a program to estimate the probability that, on at least 1 day during the year, Facebook tells you five (or more) of your friends share that birthday. Based on your, answer, should you be surprised by this occurrence?

[Hint: Generate 500 birthdays with replacement, then determine whether any birthday occurs three or more times (five or more for part (b)). The table function in $R$ or tabulate in Matlab may prove useful. $]$

Robin C.

Numerade Educator

Consider the following game: you begin with $\$ 20 .$ You fair coin, winning $\$ 10$ if the coin lands heads and losing $\$ 10$ if the coin lands. Play continues until you either go broke or have $\$ 100$ (i.e., a net profit of $\$ 80 ) .$ Write a simulation program to estimate:

(a) The probability you win the game.

(b) The probability the game ends within ten coin flips.

$[$ Note: This is a special case of the Gambler's Ruin problem, which we'll explore in much greater depth in Exercise 145 and again in Chap. $6 . ]$

A M.

Numerade Educator

Consider the Coupon Collector's Problem described in the Introduction: 10 different coupons are distributed into cereal boxes, one per box, so that any randomly selected box is equally likely to have any of the 10 coupons inside. Write a program to simulate the process of buying cereal boxes until all 10 distinct coupons have been collected. For each run, keep track of how many cereal boxes you purchased to collect the complete set of coupons. Then use your program to answer the following questions.

(a) What is the probability you collect all 10 coupons with just 10 cereal boxes?

(b) Use counting techniques to determine the exact probability in (a). [Hint: Relate this to the Birthday Problem.]

(c) What is the probability you require more than 20 boxes to collect all 10 coupons?

(d) Using techniques from Chap. $4,$ it can be shown that it takes about 29.3 boxes, on the average, to collect all 10 coupons. What's the probability of collecting all 10 coupons in fewer than average boxes (i.e., less than 29.3 ?

Robin C.

Numerade Educator

In the Introduction we mentioned a famous puzzle from the early days of probability, investigated by Pascal and Fermat. Which of the following events is more likely: to roll at least one in four rolls of a fair die, or to roll at least one in 24 rolls of two fair dice?

(a) Write a program to simulate a set of four die rolls times, and use the results to estimate $P($ at least one $\mathbb{I}$ in 4 rolls).

(b) Now adapt your program to simulate rolling a pair of dice 24 times. Repeat this simulation many times, and use your results to estimate $P($ at least one in 24 rolls $)$

A M.

Numerade Educator

The Problem of the Points. Pascal and Fermat also explored a question concerning how to divide the stakes in a game that has been interrupted. Suppose two players, Blaise and Pierre, are playing a game where the winner is the first to achieve a certain number of points. The game gets interrupted at a moment when Blaise needs $n$ more points to win and Pierre needs $m$ more to win. How should the game's prize money be divvied up? Fermat argued that Blaise should receive a proportion of the total stake equal to the chance he would have won if the game hadn't been interrupted (and Pierre receives the remainder).

Assume the game is played in rounds, the winner of each round gets 1 point, rounds are independent, and the two players are equally likely to win any particular round.

(a) Write a program to simulate the rounds of the game that would have happened after play was interrupted. A single simulation run should terminate as soon as Blaise has $n$ wins or Pierre has $m$ wins (equivalently, Blaise has $m$ losses). Use your program to estimate $P$ (Blaise gets 10 wins before 15 losses), which is the proportion of the total stake Blaise should receive if $n=10$ and $m=15 .$

(b) Use your same program to estimate the relevant probability when $n=m=10 .$ Logically what should the answer be? Is your estimated probability close to that?

(c) Finally, let's assume Pierre is actually the better player: $P$ (Blaise wins a round) $=.4 .4$ . Again with $n=10$ and $m=15,$ what proportion of the stake should be awarded to Blaise?

Check back soon!

Twenty faculty members in a certain department have just participated in a department chair election. Suppose that candidate A has received 12 of the votes and candidate $B$ the other 8 votes. If the ballots are opened one by one in random order and the candidate selected on each ballot is recorded, use simulation to estimate the probability that candidate A remains ahead of candidate $B$ throughout the vote count (which happens if, for example, the result is AA. . AB. . B but not if the result is AABABB...)

A M.

Numerade Educator

Show that the (estimated) standard error for $\hat{P}(A)$ is at most 1$/ \sqrt{4 n}$

Mihir G.

Numerade Educator

Simulation can be used to estimate numerical constants, such as $\pi .$ Here's one approach: consider the part of a disk of radius 1 that lies in the first quadrant (a quarter-circle). Imagine two random numbers, $x$ and $y,$ both between 0 and $1 .$ The pair $(x, y)$ lies somewhere in the first quadrant; let $A$ denote the event that $(x, y)$ falls inside the quarter-circle.

(a) Write a program that simulates pairs $(x, y)$ in order to estimate $P(A),$ the probability that a randomly selected pair of points in the square $[0,1] \times[0,1] \times[0,1]$ lies in the quarter-circle of

radius $1 .$

(b) Using techniques from Chap. $4,$ it can be shown that the exact probability of $A$ is $\pi / 4$ (which makes sense, because that's the ratio of the quarter-circle's area to the square's area). Use

that fact to come up with an estimate of $\pi$ from your simulation. How close is your estimate to 3.14159$\ldots .$

A M.

Numerade Educator

Consider the quadratic equation $a x^{2}+b x+c=0 .$ Suppose that $a, b,$ are random numbers between 0 and 1 (like those produced by an RNG). Estimate the probability that the roots of this quadratic equation are real. [Hint: Think about the discriminant. This probability can be computed exactly using methods from Chap. $4,$ but a triple integral is required.