0% found this document useful (0 votes)
20 views35 pages

Topic6 Counting SimulatingChance

The document covers fundamental concepts of probability, including classical probability, counting methods, and chance simulations. It explains how to calculate probabilities using various methods such as enumeration, tree diagrams, and simulations in R, along with the multiplication principle and factorials. Additionally, it discusses specific examples like drawing cards and rolling dice to illustrate these concepts.

Uploaded by

ishrat
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)
20 views35 pages

Topic6 Counting SimulatingChance

The document covers fundamental concepts of probability, including classical probability, counting methods, and chance simulations. It explains how to calculate probabilities using various methods such as enumeration, tree diagrams, and simulations in R, along with the multiplication principle and factorials. Additionally, it discusses specific examples like drawing cards and rolling dice to illustrate these concepts.

Uploaded by

ishrat
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/ 35

Counting and Simulating Chance

Sampling Data | Understanding Chance

© University of Sydney MATH1062


06 September 2024

 Module3 Sampling Data

Understanding probability
What is probability?

Counting and chance simulation


How to count the number of possible outcomes?

Chance variability
How can we model chance variability by a box model?

Central limit theorem


What is the behaviour of the sample mean for a large sample size?

2/35

 Simulating Chance

“Classical” probability

Multiplication principle of counting

Factorial

Combinations

Summary

3/35
“Classical” probability
The sample space Ω consist of a finite, known number of equally likely outcomes (e.g.,
coins, dice, cards). The probability of an event 𝐴 ⊂ Ω occurring is

Number of ways 𝐴 can occur


𝑃 (𝐴) =
Total number of possible outcomes in Ω

For example, suppose we want to know the probability of getting an even number when
we roll a fair die. There are 6 equally likely possible outcomes,

Ω = {⚀⚁⚂⚃⚄⚅}
of which 3 are even. Therefore, the probability of rolling an even number is

𝑃 (number of outcomes that are even) 3


𝑃 (even number) = = .
𝑃 (number of possible outcomes) 6

4/35
Enumeration
Counting and drawing trees
· For simple problems, a good start is to enumerate all the possible outcomes using:
· Method 1
- Write a list of all outcomes
- Count which outcomes belong to the event of interest.
· Method 2
- Draw a tree

6/35

 Example
Two dice are thrown. What is the chance that their sum is 6?

Method 1: Write a full list of outcomes and count the outcomes of interest.

So the chance is 5/36 (approx 0.14).

7/35
Method 2: Summarise in a tree diagram

Start

1 2 3 4 5 6

1 2 3 4 5 6

· One path has probability 1/36, because independence of 1st draw and 2nd draw
means probabilities of edges can be multiplied: 1/6*1/6=1/36

· Probability of paths can be added because events are mutually exclusive (if you throw
(1,5) you can’t have thrown (2,4) at the same time)

· Possible paths are (1,5), (2,4), (3,3), (4,2), (5,1), hence probability of 6 spots is
1/36+1/36+1/36+1/36+1/36=5/36.

8/35
Sample with/without replacement
Method 3: Simulate (in R)
· Use R and simulate throwing 2 dice 𝑥 times and record the findings.

set.seed(23) # set the random seed


totals = sample(1:6, 1000, rep = T) + sample(1:6, 1000, rep = T)
table(totals)
## totals
## 2 3 4 5 6 7 8 9 10 11 12
## 27 55 79 124 144 168 138 109 88 45 23

· We set the random seed so this can be reproduced

· Sample from 1,2,3,4,5,6 (a die) with equal probability

· Sample 1000 times

· Sample with replacement using rep=T (independent experiments)

10/35
Method 3: Simulate (in R)
barplot(table(totals), main = "1000 rolls: sum of 2 dice")

So the (simulated) chance of getting a total of 6 is 144/1000 = 0.144, which is very close
to the exact answer of 5/36 = 0.139.

11/35
· What will happen if sample without replacement (without rep=T )?

- This implies dependent experiments - the next outcome depends on previous


ones
- See code demo

12/35
A simple box model
Many counting and probability problems can be reduced to a box model. In a box
model, there are 𝑁 tickets in a box, and we draw 𝑚 tickets from the box.

· For example, three rolls of a fair die can be modeled as 𝑚 = 3 draws from the box

1 2 3 4 5 6

we have to place the ticket back in the box after each draw, so the outcome of one die
roll does not affect the outcome of another. In other words, the 𝑚 = 3 draws are
made with replacement.

· In other situations, the draws are made without replacement. For example, consider
drawing four cards from a standard deck of 52 cards (without putting the drawn cards
back).

13/35

 Example (a bit more complex)
Three dice are thrown. What is the chance of getting a total equal to 6?

Method 1: Write a list manually


· Total number of outcomes are 6x6x6 = 216
· The outcomes where the total is equal to 6 are: (1,1,4) (1,2,3) (1,3,2) (1,4,1) (2,1,3)
(2,2,2) (2,3,1) (3,1,2) (3,2,1), (4,1,1)
· So exact chance of getting total of 6 is 10/216 (approx 0.046).

14/35
Method 2: Summarise in a tree diagram

Start

1 2 3 4 5 6

1 2 3 4 5 6

1 2 3 4 5 6

15/35
Method 3: Simulate in R
set.seed(23)
totals = sample(1:6, 1000, rep = T) + sample(1:6, 1000, rep = T) + sample(1:6, 1000,
rep = T)
table(totals)/1000
## totals
## 3 4 5 6 7 8 9 10 11 12 13 14 15
## 0.007 0.011 0.025 0.048 0.066 0.105 0.112 0.135 0.134 0.113 0.094 0.065 0.041
## 16 17 18
## 0.029 0.013 0.002
barplot(table(totals), main = "1000 rolls: sum of 3 dice")

16/35

 Example
Why did the Chevalier lose money? What is the chance of winning?

· Game A: Roll a die 4 times. Win = at least 1 “ace”.


· Game B: Roll a pair of dice 24 times: Win = at least 1 “double-ace”.
· Note: an “ace” means “1”.

17/35
Method 3: Simulate in R (using a function)
gameA <- function() {
rolls <- sample(1:6, size = 4, replace = TRUE)
condition <- sum(rolls == 1) > 0
return(condition)
}
simsA <- replicate(1e+05, gameA())
sum(simsA)/length(simsA)
## [1] 0.51543
gameB <- function() {
first.die <- sample(1:6, size = 24, replace = TRUE)
second.die <- sample(1:6, size = 24, replace = TRUE)
condition <- sum((first.die == second.die) & (first.die == 1)) > 0
return(condition)
}
simsB <- replicate(1e+05, gameB())
sum(simsB)/length(simsB)
## [1] 0.48979
Indeed, Game A is better.

18/35
Sample without replacement (using R)


 Example
· A company has 10,000 male employees and 11,000 female employess. A
representative committee is created by randomly picking 10 employees.

· What is chance that more than 75% in the committee are male?

set.seed(1)
committee <- function() {
committee <- sample(c(rep(1, 10000), rep(0, 11000)), size = 10, replace = FALSE)
condition <- mean(committee) > 0.75
return(condition)
}
sim <- replicate(10000, committee())
mean(sim)
## [1] 0.0418

19/35
Multiplication Principle of Counting
Multiplication Principle of Counting


 Multiplication Principle of Counting
If a task can be performed in 𝑛1 ways, and for each of these ways, a second task
can be performed in 𝑛2 ways, then the two tasks can be performed together in a
total of 𝑛1 × 𝑛2 ways. If there are 𝑘 tasks in such a sequence, then 𝑘 tasks can be
performed together in a total of 𝑛1 × 𝑛2 × ⋯ 𝑛𝑘 ways.

For example, there are a total number 6 × 6 × 6 = 216 outcomes in rolling three dice.

21/35
Factorial
How many ways to arrange a deck of 52 cards?
We can use the multiplication principle to determine the number of ways to arrange the
deck.

· The first card can be any one of 52 cards.


· No matter which one it is, the second card can be any one of the remaining 51 cards.
So there are 52 × 51 ways to choose the first 2 cards.
· For every one of these 52 × 51 ways, there are 50 remaining cards to choose as the
third card, which makes 52 × 51 × 50 ways to choose the first 3 cards.
· And so on. By the time we get to the last card in the deck, there is only 1 card left. So
there are 52 × 51 × 50 × ⋯ × 1 ways to arrange the 52 cards in a deck.

23/35
Factorial

 Factorial
The quantity 𝑛! (pronounced: “n factorial”) is defined as

𝑛! = 𝑛 × (𝑛 − 1) × ⋯ × 1.
It represents the number of ways to arrange n objects.

24/35

 Example
A deck of 52 cards is shuffled thoroughly. What is the probability that the four aces
are all next to each other? (Hint: First, count the number of positions that the block
of four aces can go, then multiply this by the number of ways of ordering the four
aces.)

There are 52! ways to order a deck of 52 cards (total number of outcomes in Ω )

How many possible ways to have four aces next to each other?

Note: A deck of cards has 13 ranks (ace, king, queen, jack, 10, …, 2) and 4 suits
(spades, clubs, hearts, and diamonds).

25/35
· Step 1: Consider the block of four aces (next to each other) as a single block

- then we have 48 other cards plus this one block, making a total of 48 + 1 = 49
units to arrange.
· Step 2: there are 49! ways to arrange these 49 units.

· Step 3: Calculate the number of ways to arrange the aces (with different suits) within
the block.

- the four aces can be arranged among themselves in 4! ways.


· Step 4: Calculate the probability

Number of ways 𝐴 can occur 49! ⋅ 4! 4⋅3⋅2⋅1 1


= = =
Total number of possible outcomes in Ω 52! 52 ⋅ 51 ⋅ 50 5525

26/35

 Example
If a five-letter word (in English) is formed at random (meaning that all sequences of
five letters are equally likely), what is the probability that no letter occurs more than
once?

5
Total number of outcomes in Ω : 26

Number of ways no letter occurs more than once: 26 ⋅ 25 ⋅ 24 ⋅ 23 ⋅ 22 (taking out a


letter from the box once it’s been used)

So the probability is

26 ⋅ 25 ⋅ 24 ⋅ 23 ⋅ 22
𝑃 = 5
≈ 0.6588
26

27/35
Combinations
Example
One of the most coveted hands in poker is a four-of-a-kind, which is when the hand
contains all four cards of a particular rank. For example, the hand below is an example
of a four-of-a-kind, since it contains all four 7s in the deck. (The last card, called the
“kicker”, can be any other card.)

Note: the order of the cards in the hand does not matter.

What is the probability of a four-of-a-kind?

29/35
If drawing without replacement, the number of ways to draw 𝑘 tickets from the box

1 2 3 ⋯ N
is
𝑁!
𝑁 × (𝑁 − 1) × ⋯ × (𝑁 − 𝑘 + 1) =
 (𝑁 − 𝑘)!
𝑘 terms
since the number of tickets remaining in the box decreases by 1 on each draw.

How many possible poker hands are there?


If we assign a number 1 to 52 to each card in a standard playing deck, then a poker
hand can be modeled as 𝑘 = 5 draws, without replacement, from the box

1 2 3 ⋯ 52

52!
Number of possible ordered poker hands: (52−5)!
= 52 ⋅ 51 ⋅ 50 ⋅ 49 ⋅ 48
> 300 × 106 .

30/35
Note that the order of cards in a hand matters here. We count not only how many hands
of cards, but also how many ordered hands.

Two hands formed by the same set of cards, but with different orders, for example

{2♠, 3♣, 𝐴𝑐𝑒♣, 9♡, 5♢}


and

{9♡, 3♣, 5♢, 2♠, 𝐴𝑐𝑒♣}


are considered as two different hands by directly applying factorials.

The factorial considers the different orders in which the cards might be drawn.

31/35
How many of these possible ordered outcomes result in a four-of-a-kind?
Let’s start by assuming that the first four cards in the hand are the four-of-a-kind and the
last card is the kicker.

· The first card can be any one of the 52 cards.


· Once we have chosen the first card, the rank of the four-of-a-kind is determined. The
second card must be one of the 3 remaining cards of the same rank.
· The third card must be one of the 2 remaining cards of that rank.
· The fourth card must be the 1 remaining card of that rank.
· The last card, the kicker, is one of the other 48 cards in the deck.

We assume the kicker is the last card in the hand. But the kicker can be in any one of 5
positions. So we need to multiply everything by 5 in the end.

There are (52 ⋅ 3 ⋅ 2 ⋅ 1 ⋅ 48) ⋅ 5 outcomes, the chance of getting a four-of-a-kind is


(52 ⋅ 3 ⋅ 2 ⋅ 1 ⋅ 48) ⋅ 5
≈ 0.00024.
52 ⋅ 51 ⋅ 50 ⋅ 49 ⋅ 48

32/35
Combinations
The previous calculation was complicated because we had to consider the different
orders in which the cards might be drawn. It is often easier to ignore the order when
counting outcomes.


 Combinations (order doesn’t matter)
The number of ways to draw 𝑘 tickets from the box

1 2 3 ⋯ N

( 𝑘 ) (pronounced: “N choose k”) and


𝑁
when the order doesn’t matter, is symbolized
is equal to

( 𝑘 ) 𝑘!(𝑁 − 𝑘)!
𝑁 𝑁!
=
𝑘! is the number of ways of ordering the same set of 𝑘 objects.

33/35
Revisit the probability of a four-of-a-kind using combinations.
(5)
52
If we ignore the order of the cards in the hand, there are = 2, 598, 960 possible
poker hands.
choose(52, 5)
## [1] 2598960

How many “unordered” four-of-a-kind hands are there?


· Any one of the 13 ranks (Ace through King) could be the rank for the four-of-a-kind.
· Once we have chosen the rank, it completely determines 4 of the 5 cards in the four-
of-a-kind. There are only 13 ways to include all 4 cards of a given rank.
· All that’s left is the kicker, which can be any one of the remaining 48 cards.

So when we ignore order, there are 13 ⋅ 48 = 624 ways to get a four-of-a-kind.

The chance is 624/2, 598, 960 ≈ 0.00024

34/35
Summary
“Classical” probability

Sample with/without replacement

Multiplication principle of counting

Factorial

Combinations
Key R Functions
set.seed , sample , replicate , choose

35/35

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy