แนะนำคอร์ส

Probability Puzzles in R

Peter Chi

Assistant Professor of Statistics

ภาพรวมคอร์ส

  • บทที่ 1: คลาสสิก

    • ปัญหาวันเกิด
    • Monty Hall
  • บทที่ 2: เกมลูกเต๋า

    • Yahtzee
    • Settlers of Catan
    • Craps
  • บทที่ 3: แรงบันดาลใจจากเว็บ

    • การผสมรหัสผ่าน iPhone
    • Sign Error Cancellation
    • การแยกตัวประกอบสมการกำลังสอง
  • บทที่ 4: เกมโป๊กเกอร์

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

การจัดหมู่

  • 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

การจำลอง

  • สุ่มเลือกวัตถุ - sample()
  • จำลองการโยนเหรียญ - rbinom()
  • ทำซ้ำกระบวนการ
    • replicate()
    • ลูป: for, while
  • กำหนด seed - set.seed()
Probability Puzzles in R

รายละเอียดเพิ่มเติมของ for loop

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

การเก็บผลลัพธ์:

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

ฟังก์ชัน

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

 

my_function(10)
1000
Probability Puzzles in R

มาฝึกกันเถอะ!

Probability Puzzles in R

Preparing Video For Download...