Probability Lab

Author

Feraol Abera

Probability

The Hot Hand

Getting Started

Load Packages

library(tidyverse)
library(openintro)

Data

glimpse(kobe_basket)
Rows: 133
Columns: 6
$ vs          <fct> ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL…
$ game        <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
$ quarter     <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3…
$ time        <fct> 9:47, 9:07, 8:11, 7:41, 7:03, 6:01, 4:07, 0:52, 0:00, 6:35…
$ description <fct> Kobe Bryant makes 4-foot two point shot, Kobe Bryant misse…
$ shot        <chr> "H", "M", "M", "H", "H", "M", "M", "M", "M", "H", "H", "H"…
data("kobe_basket")

Excercise 1

What does a streak length of 1 mean, i.e. how many hits and misses are in a streak of 1? What about a streak length of 0?

Answer: A streak of 1 means one shot was made. A streak of one has one hit. A streak of 0 means no shots were made.

kobe_streak <- calc_streak(kobe_basket$shot)
ggplot(data = kobe_streak, aes(x = length)) +
  geom_bar()

Excercise 2

Describe the distribution of Kobe’s streak lengths from the 2009 NBA finals. What was his typical streak length? How long was his longest streak of baskets? Make sure to include the accompanying plot in your answer.

Answer: Most of Kobe’s streaks were 0 streaks with his longest streak being 4 makes in a row. The longest streak of baskets only happened once as shown in the plot above.

Compared to What?

Two processes are independent if the outcome of one doesn’t effect the outcome of the other

P (shot 1 = H) = 0.45 If not independent: P(shot 2 = H | shot 1 = H) = 0.60 If independent: P(shot 2 = H | shot 1 = H) = 0.45

Simulations in R

coin_outcomes <- c("heads", "tails")
sample(coin_outcomes, size = 1, replace = TRUE)
[1] "heads"
sim_fair_coin <- sample(coin_outcomes, size = 100, replace = TRUE)
sim_fair_coin
  [1] "heads" "tails" "tails" "heads" "tails" "heads" "tails" "heads" "heads"
 [10] "heads" "tails" "heads" "heads" "tails" "heads" "heads" "heads" "tails"
 [19] "tails" "tails" "heads" "tails" "tails" "heads" "tails" "tails" "tails"
 [28] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails" "heads"
 [37] "tails" "heads" "heads" "tails" "heads" "heads" "heads" "tails" "tails"
 [46] "heads" "tails" "tails" "tails" "heads" "tails" "heads" "heads" "heads"
 [55] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "heads" "tails"
 [64] "tails" "tails" "heads" "heads" "heads" "tails" "heads" "tails" "heads"
 [73] "tails" "tails" "tails" "heads" "heads" "heads" "heads" "tails" "tails"
 [82] "tails" "heads" "tails" "heads" "heads" "tails" "heads" "heads" "heads"
 [91] "tails" "tails" "heads" "tails" "heads" "tails" "tails" "tails" "tails"
[100] "heads"
table(sim_fair_coin)
sim_fair_coin
heads tails 
   45    55 
sim_unfair_coin <- sample(coin_outcomes, size = 100, replace = TRUE, 
                          prob = c(0.2, 0.8))
sim_unfair_coin
  [1] "tails" "tails" "tails" "tails" "tails" "heads" "tails" "heads" "heads"
 [10] "tails" "heads" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
 [19] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails"
 [28] "tails" "tails" "heads" "tails" "tails" "tails" "tails" "tails" "tails"
 [37] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
 [46] "heads" "tails" "tails" "heads" "tails" "tails" "heads" "tails" "tails"
 [55] "tails" "tails" "tails" "tails" "heads" "heads" "heads" "tails" "tails"
 [64] "heads" "heads" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
 [73] "heads" "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails"
 [82] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
 [91] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
[100] "tails"
table(sim_unfair_coin)
sim_unfair_coin
heads tails 
   18    82 

Excercise 3

In your simulation of flipping the unfair coin 100 times, how many flips came up heads? Include the code for sampling the unfair coin in your response.

Answer: Heads came up 15 times. sim_unfair_coin <- sample(coin_outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))

Simulating the Independent Shooter

shot_outcomes <- c("H", "M")
sim_basket <- sample(shot_outcomes, size = 1, replace = TRUE)
sim_basket
[1] "M"
table(sim_basket)
sim_basket
M 
1 

Excercise 4: What change needs to be made to the sample function so that it reflects a shooting percentage of 45%? Make this adjustment, then run a simulation to sample 133 shots. Assign the output of this simulation to a new object called sim_basket.

Answer: Have to add a probability argument and change the size to 133.

shot_outcomes <- c("H", "M")
sim_basket <- sample(shot_outcomes, size = 133, replace = TRUE,
                     prob = c(0.45, 0.55))
table(sim_basket)
sim_basket
 H  M 
53 80