Simulations. 1 The Concept

Similar documents
Math 1313 Section 6.2 Definition of Probability

4.3 Rules of Probability

Intermediate Math Circles November 1, 2017 Probability I


4.1 Sample Spaces and Events

Unit 9: Probability Assignments

Section 6.1 #16. Question: What is the probability that a five-card poker hand contains a flush, that is, five cards of the same suit?

LISTING THE WAYS. getting a total of 7 spots? possible ways for 2 dice to fall: then you win. But if you roll. 1 q 1 w 1 e 1 r 1 t 1 y

2.5 Sample Spaces Having Equally Likely Outcomes

Date. Probability. Chapter

Here are two situations involving chance:

If a fair coin is tossed 10 times, what will we see? 24.61% 20.51% 20.51% 11.72% 11.72% 4.39% 4.39% 0.98% 0.98% 0.098% 0.098%

CSC/MTH 231 Discrete Structures II Spring, Homework 5

3 The multiplication rule/miscellaneous counting problems

STATION 1: ROULETTE. Name of Guesser Tally of Wins Tally of Losses # of Wins #1 #2

COMPOUND EVENTS. Judo Math Inc.

Probability. The Bag Model

The point value of each problem is in the left-hand margin. You must show your work to receive any credit, except on problems 1 & 2. Work neatly.

November 11, Chapter 8: Probability: The Mathematics of Chance

Key Concepts. Theoretical Probability. Terminology. Lesson 11-1

Most of the time we deal with theoretical probability. Experimental probability uses actual data that has been collected.

The Teachers Circle Mar. 20, 2012 HOW TO GAMBLE IF YOU MUST (I ll bet you $5 that if you give me $10, I ll give you $20.)

Example 1. An urn contains 100 marbles: 60 blue marbles and 40 red marbles. A marble is drawn from the urn, what is the probability that the marble

Chapter 1: Sets and Probability

Such a description is the basis for a probability model. Here is the basic vocabulary we use.

If a fair coin is tossed 10 times, what will we see? 24.61% 20.51% 20.51% 11.72% 11.72% 4.39% 4.39% 0.98% 0.98% 0.098% 0.098%

Grade 8 Math Assignment: Probability

Week 1: Probability models and counting

Important Distributions 7/17/2006

Contemporary Mathematics Math 1030 Sample Exam I Chapters Time Limit: 90 Minutes No Scratch Paper Calculator Allowed: Scientific

Ex 1: A coin is flipped. Heads, you win $1. Tails, you lose $1. What is the expected value of this game?

Making Predictions with Theoretical Probability

Making Predictions with Theoretical Probability. ESSENTIAL QUESTION How do you make predictions using theoretical probability?

Chapter 8: Probability: The Mathematics of Chance

This Probability Packet Belongs to:

Math 147 Lecture Notes: Lecture 21

Test 2 SOLUTIONS (Chapters 5 7)

3 The multiplication rule/miscellaneous counting problems

Waiting Times. Lesson1. Unit UNIT 7 PATTERNS IN CHANCE

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

1. An office building contains 27 floors and has 37 offices on each floor. How many offices are in the building?

MATH STUDENT BOOK. 7th Grade Unit 6

Discrete Random Variables Day 1

(a) Suppose you flip a coin and roll a die. Are the events obtain a head and roll a 5 dependent or independent events?

STAT 311 (Spring 2016) Worksheet W8W: Bernoulli, Binomial due: 3/21

More Probability: Poker Hands and some issues in Counting

MATH 215 DISCRETE MATHEMATICS INSTRUCTOR: P. WENG

7.1 Chance Surprises, 7.2 Predicting the Future in an Uncertain World, 7.4 Down for the Count

Finite Mathematics MAT 141: Chapter 8 Notes

Chapter 1. Probability

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Math 4610, Problems to be Worked in Class

Classical vs. Empirical Probability Activity

Part 1: I can express probability as a fraction, decimal, and percent

Midterm 2 Practice Problems

Chapter 2. Permutations and Combinations

Probability. March 06, J. Boulton MDM 4U1. P(A) = n(a) n(s) Introductory Probability

Name: Class: Date: 6. An event occurs, on average, every 6 out of 17 times during a simulation. The experimental probability of this event is 11

GAMBLING ( ) Name: Partners: everyone else in the class

The topic for the third and final major portion of the course is Probability. We will aim to make sense of statements such as the following:

Use a tree diagram to find the number of possible outcomes. 2. How many outcomes are there altogether? 2.

Normal Distribution Lecture Notes Continued

Suppose Y is a random variable with probability distribution function f(y). The mathematical expectation, or expected value, E(Y) is defined as:

out one marble and then a second marble without replacing the first. What is the probability that both marbles will be white?

A Probability Work Sheet

Dependence. Math Circle. October 15, 2016

1 2-step and other basic conditional probability problems

6. a) Determine the probability distribution. b) Determine the expected sum of two dice. c) Repeat parts a) and b) for the sum of

Diamond ( ) (Black coloured) (Black coloured) (Red coloured) ILLUSTRATIVE EXAMPLES

1. A factory makes calculators. Over a long period, 2 % of them are found to be faulty. A random sample of 100 calculators is tested.

Chapter 1. Probability

Probability. Ms. Weinstein Probability & Statistics

Probability: introduction

Probability & Expectation. Professor Kevin Gold

STAT 430/510 Probability Lecture 3: Space and Event; Sample Spaces with Equally Likely Outcomes

Roll & Make. Represent It a Different Way. Show Your Number as a Number Bond. Show Your Number on a Number Line. Show Your Number as a Strip Diagram

Mathematical Foundations HW 5 By 11:59pm, 12 Dec, 2015

Before giving a formal definition of probability, we explain some terms related to probability.

Probability. The MEnTe Program Math Enrichment through Technology. Title V East Los Angeles College

Alg 2/Trig Honors Qtr 3 Review

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Note 13

Chapter 4: Probability

Conditional Probability Worksheet

Probability Paradoxes

The next several lectures will be concerned with probability theory. We will aim to make sense of statements such as the following:

Review Questions on Ch4 and Ch5

Module 5: Probability and Randomness Practice exercises

, x {1, 2, k}, where k > 0. (a) Write down P(X = 2). (1) (b) Show that k = 3. (4) Find E(X). (2) (Total 7 marks)

1 2-step and other basic conditional probability problems

Independence Is The Word

Conditional Probability Worksheet

Chapter 4: Probability and Counting Rules

Grade 7/8 Math Circles February 25/26, Probability

b) Find the exact probability of seeing both heads and tails in three tosses of a fair coin. (Theoretical Probability)

Math 12 Academic Assignment 9: Probability Outcomes: B8, G1, G2, G3, G4, G7, G8

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Poker: Probabilities of the Various Hands

1. How to identify the sample space of a probability experiment and how to identify simple events

Probability: Anticipating Patterns

NUMB3RS Activity: A Bit of Basic Blackjack. Episode: Double Down

Transcription:

Simulations In this lab you ll learn how to create simulations to provide approximate answers to probability questions. We ll make use of a particular kind of structure, called a box model, that can be used to simulate a wide range of probability problems. 1 The Concept Probabilities are long-run frequencies. When we say something like The Probability that event A will occur is 38%, what we mean is that there is an experiment, and one of the possible outcomes of this experiment is the event A. If we were to repeat this experiment infinitely many times, the event A would occur in 38% of them. For example, when we say that the probability of getting heads when we flip a coin is 50%, we mean that if we were to flip the coin infinitely many times, half of the flips would land heads. No one has the patience to flip a coin infinitely many times, even if they could live long enough. The best we can hope for is to see the outcome of a large number of flips. Fortunately, computers make it possible to repeat an experiment very many times very quickly. So rather than flip a real coin 1000 times, which takes quite a bit of effort, we can program a computer to do the same in the blink of an eye. Or faster. So suppose we program a computer to do virtual coin flips. Suppose everyone in the room flips a virtual coin 1000 times. (Not difficult to imagine, since this is exactly what you ll be doing in this lab.) Will everyone get the same number of heads? Almost certainly not. (But it s possible! How would you calculate the probability of this happening?) If everyone gets a different amount, how can we use our simulation to figure out a probability? The answer is that the best we can do is get an approximation. Probabilities determined from simulations or from actual experiments are 1

called experimental probabilities or synonymously, empirical probabilities. An experimental probability differs from person to person. And from attempt to attempt. The important thing to keep in mind, though, is that the more trials you did, the more likely you are to get an experimental probability that s close to the theoretical probability. To sum things up, your experimental probability is an approximation to the theoretical probability. And the larger the sample size, the better the approximation. In other words, if everyone in the room flips a real coin 20 times, the percentage of heads will vary quite a bit, and might stray quite a ways (relatively speaking) from 50%. But if everyone flips a real coin 1000 times, everyone s percentage of heads will be closer to 50%. To do our simulations, we need a simulation machine. Our machine is called a box model. It is a mental abstraction, but it is also a routine programmed into Stata. This routine allows you to program the computer and order it to carry out certain types of simulations. 2 What s a box model? A box model is a box with slips of paper in it, like you might see at a raffle. The slips of paper have numbers on them. We reach into the box, pull out a slip and record the number. We could repeat this many times to get an idea of the approximate probability of seeing certain values. Let s make a box model for estimating the probability of getting a 6 on the roll of a fair die. The first step is to decide what values go on the tickets. We need to make sure that all possible outcome are represented. Therefore, we will need one ticket with a 1, one with a 2, another with a 3, and so on up to 6. The second step is to decide how many of each ticket. For a fair die, each outcome is equally likely, so each value in the box should have equal representation. Therefore, we should have the same number of each ticket. The simplest way to do this is to have each value appear only once. But if we wanted to we could have 100 of each value. Once the box model is created, we re ready to use it. For this thought experiment, imagine mixing up the tickets, and then reaching into the box 2

to draw one out. If it s a 6, we make a note of this. If not, we do nothing. No matter what, we put the ticket back, shuffle the box, and repeat. We repeat this many times, maybe 1000. When we re done, our experimental probability is the number of 6 s divided by the number of trials. Notice that there s another way of drawing out tickets. We might, if we wanted to, draw a ticket out, record it s number, and then throw it away. This is called sampling without replacement. It is useful for experiments in which outcomes can only occur once. 3 Using Stata to make and run box models We are not going to use a real box model. Instead, we use a virtual box model. A model box model, if you will. Our virtual box model exists within some Stata code. Don t worry; you don t have to write any code. You just have to execute the program that will then guide you to build a box model. The program that does this is not part of the usual Stata, and so if your computer does not already have this installed, you need to install it. If you are doing this in the Statistics lab, then probably this has already been installed. Type. bxmodel Does anything happen? If you get an error ( unrecognized command ), then you need to follow the instructions below to install it. Otherwise, you can skip this section. In the command window, type. net from http://www.ats.ucla.edu/stat/stata/ado/teach Then type. net install bxmodel Full directions for using the box model are available at. http://www.ats.ucla.edu/stat/stata/ado/teach/bxmodel.htm 3

Using this program requires three steps. Create a box with values and frequencies Choose the type of sampling and number of repetitions: with replacement, without, birthday problem Analyze the output To create the box, you need to use the editor to create a data set with two columns. The first column represents a variable that you must name value, and the second column represents a variable that you must name n. In the first column, put the values you want to appear on the tickets. In the second column, but the number of tickets with that value on them that you wish to have in the box. To simulate the roll of a fair die, put the numbers 1 through 6 in the value column, and each value should appear only once, so put a 1 beside each value in the n column. Click on Preserve. Then close the editor. Finally, choose Save as and save under a memorable name. For example, fairdie.dta. Now you re ready to run the boxmodel. In the command window type. bxmodel. A dialogue box will appear. Step 1 Load the box by typing in the filename ( fairdie.dta ). Step 2 How many tickets will you draw out of the box? If we want to simulate a single roll of the die, we would type 1 in the number field. Step3 Type of box model? You have 3 choices. Drawing with replacement would simulate rolling a fair die. Drawing without replacement would simulate situations in which tickets can only be drawn once (such as dealing a deck of cards). The birthday problem is a special type of structure that we ll discuss later. For this practice run, check with replacement. 4

Step4 Number of repetitions: how many times do you want to repeat the experiment? You should do it at least 100 times. 1000 is even better. The program does not save the raw results. Instead, for each repetition, it saves the sum of the tickets for each trial, the average of the tickets for each trial, and the standard deviation of the tickets at each trial. Because we are only drawing out 1 ticket, the sum of the tickets will just be the value on the ticket. To answer the next few questions, do 100 repetitions of throwing a single die. Question 1: What s the experimental probability of getting a 3? Of course almost everyone will have a different answer. But to figure this out you need to count the number of times you rolled a 3, and divide by the number of trials. To count the number of 3 s you rolled, type. count if sum==3. Your experimental probability is this number divided by the number of repetitions. What answer did you expect to get? Was this close? Question 2: What s the empirical probability density function for rolling a fair die? Before answering this, note that the shape should be similar to the theoretical probability density function. In this case, the probability of each outcome is 1/6, and so we should expect each of the 6 outcomes (1,2,3,4,5,6) to occur about 1/6th of the time. To see whether this was the case, type. graph sum. Question 3: Repeat the above experiment (100 repetitions of rolling a single die) 10 times. Each time, calculate (i) the experimental probability of rolling a 3 and (ii) the difference between the experimental probability and the theoretical probability. 5

Question 4: Now do 10,000 repetitions of rolling a single die. Repeat 10 times, and each time calculate (i) the experimental probability of rolling a 3 and (ii) the difference between the experimental probability and the theoretical probability. How should the differences you compute compare for the 10,000 repetition experiments with the 100 repetitions? Question 5: To play the popular casino game of craps, you roll two dice. The outcome is based on the sum of the two dice. The game places special significance on an outcome of 7. (If a 7 occurs on the first throw, this is usually good for the player. Otherwise, 7 s are usually bad news.) Estimate the probability of throwing a 7. Compare this to the theoretical probability. Question 6: In the game of craps, the payoffs (the money the casino gives you should you win) are proportional to the probability of certain outcomes. Inversely proportional, of course. So the less likely the outcome, the greater the payoff. Which outcomes do you think have the biggest payoffs? Demonstrate with a simulation. Question 7: In the card game poker, you are dealt a hand, which consists of 5 cards. To vastly oversimplify this game, basically the more rare your hand, the better an advantage you have over your opponents. One rare hand is to have all of your cards of the same suit. (There are four suits: hearts, diamonds, clubs, spades.) Use a box model to estimate the probability that all 5 cards will be spades. First do this with 1000 repetitions. Try this maybe two or three times. Then try 10,000 repetitions. Why do you need to do so many repetitions? Hint: There are 52 cards in a deck, and 13 of each suit. Assign the value 1 to spades, and 0 to all the other suits. A hand consists of 5 cards dealt 6

without replacement. Question 8: In a classroom of 20 people, what are the chances that at least two will have the same birthday? How can we estimate this probability with a box model? The first step is to imagine that each day has a number. (The second step is to ignore leap year.) Next we make a crucial assumption: that birthdays are uniformly distributed. In other words, a person is just as likely to have his birthday on one day as any other. Now we can imagine that each person goes through life with a number between 1 and 365 assigned to them. And when we assemble 20 people in a classroom, it s as if we just randomly selected, with replacement, 20 numbers from a box, that has the numbers 1... 365 in it. Hence a single repetition consists of drawing 20 tickets from the box with replacement. But this time it won t help us to record the sum or mean of the tickets. Instead, we want to know how many of the tickets are identical. Because if two of the 20 people have the same number, then this means they have the same birthday. So the first step is to create a data file with two columns. The column labeled value will have the numbers 1 through 365, and the column labeled n will consist of a string of 1 s. (So that each value appears in the box only once.) You are probability thinking that it will be rather tedious to type in all 136 numbers into this box. There s a better way. Type in these commands:. clear. set obs 365. generate value = n. generate n = 1 The first command clears the memory. The next command tells it to save space for 365 observations. Next, the generate command creates a new variable named value which is given all of the values from 1 to n, where Stata 7

knows that n means 365. The final command creates a new variable named n and gives it a value of 1 for all observations. For number, put in the number of tickets to pull out: 20. Under type of box model select Birthday. When you select Birthday, tickets are drawn out with replacement. What s different from selecting with replacement is that the output changes. You ll see two variables, match and unique. For each repetition, match is a 1 if any two or more tickets in the 20 selected match. the variable unique counts the number of tickets in those selected that are unique. So, if there are two people with the same birthday, match will be 1 and unique will be 19 (since there are 19 unique numbers.) If 3 people shared the same birthday, match would still be 1, but unique would be 18. If there were two pairs with the same birthday (so two people were born on, say, day 34 and two more born on day 165), then match would be 1 and unique would be 18. Finally, we are able to estimate this probability. Select 1000 repetitions. The experimental probability is the number of repetitions for which match is a 1, divided by the number of repetitions. You can see this just by typing. summarize match. It s in the Mean column. Question 9: How many people in a classroom until the chances that at least two have the same birthday is over 90%. Question 10: A children s cereal is having a special promotion. Each box of cereal has one of seven tokens inside. If you collect all 7 tokens, you send them in and receive a Big Prize. Assume that tokens are evenly distributed, so that if you select a box at random, tokens have an equal chance of appearing. Suppose you buy 7 cereal boxes. What s the probability you ll get all 7 tokens, and will therefore win the Big Prize? Question 11: How many boxes must you buy for the probability of getting all 7 tokens to be at least 50%? 8