Introduction to the Course

Probability Puzzles in R

Peter Chi

Assistant Professor of Statistics

Course overview

  • Chapter 1: The Classics

    • The Birthday Problem
    • Monty Hall
  • Chapter 2: Games with Dice

    • Yahtzee
    • Settlers of Catan
    • Craps
  • Chapter 3: Inspired by the Web

    • iPhone Passcode Combinations
    • Sign Error Cancellation
    • Factoring a Quadratic
  • Chapter 4: Poker Games

    • Texas Hold'em Hole Cards
    • Consecutive Cashes in the WSOP
    • von Neumann Model of Poker
Probability Puzzles in R

Combinatorics

  • factorial(n)
    • factorial(3) $= 3! = 3 \times 2 \times 1$
factorial(3)
6
  • choose(n,k)
    • choose(5,3) $ = {5 \choose 3} = \frac{5!}{3! \times (5-3)!} $
choose(5,3)
10
Probability Puzzles in R

Simulations

  • Select an object at random - sample()
  • Simulate a coinflip - rbinom()
  • Repeat a process
    • replicate()
    • Loops: for, while
  • Set a seed - set.seed()
Probability Puzzles in R

More details on for loops

for(i in 1:10){
  sum(sample(x = c(1,2,3,4,5,6), size = 2, replace = TRUE))
}

Storing the results:

rolls <- rep(NA, 10)
for(i in 1:10){
  rolls[i] <- sum(sample(x = c(1,2,3,4,5,6), size = 2, replace = TRUE))
}

rolls
3  6  3  9  9  3  6 11  9 10
Probability Puzzles in R

Functions

my_function <- function(n){
  answer <- n^3
  return(answer)
}

 

my_function(10)
1000
Probability Puzzles in R

Let's practice!

Probability Puzzles in R

Preparing Video For Download...