Hot hand phenomenon - is each shot independent of the next shot?
Always start by loading packages
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.0.5 v dplyr 1.0.3
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(openintro)
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata
Look at the data set we will be using for this lab
glimpse(kobe_basket)
## Rows: 133
## Columns: 6
## $ vs <fct> 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...
## $ quarter <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3...
## $ time <fct> 9:47, 9:07, 8:11, 7:41, 7:03, 6:01, 4:07, 0:52, 0:00, 6...
## $ description <fct> Kobe Bryant makes 4-foot two point shot, Kobe Bryant mi...
## $ shot <chr> "H", "M", "M", "H", "H", "M", "M", "M", "M", "H", "H", ...
kobe_basket <- kobe_basket
Added this data set to my global environment 133 obs and 6 variables
kobe_streak <- calc_streak(kobe_basket$shot)
ggplot(kobe_streak, aes(x=length)) +
geom_bar()
kobe_streak %>%
summarise(Median = median(length),
Min = min(length),
Max = max(length))
## Median Min Max
## 1 0 0 4
table(kobe_streak)
## kobe_streak
## 0 1 2 3 4
## 39 24 6 6 1
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
Simulate independent shots
coin_outcomes <- c("heads", "tails")
sample(coin_outcomes, size = 1, replace = TRUE)
## [1] "tails"
sim_fair_coin <- sample(coin_outcomes, size = 100, replace = TRUE)
sim_fair_coin
## [1] "heads" "heads" "tails" "tails" "heads" "tails" "heads" "heads" "tails"
## [10] "heads" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
## [19] "heads" "tails" "heads" "tails" "heads" "heads" "tails" "tails" "heads"
## [28] "heads" "heads" "heads" "tails" "tails" "tails" "heads" "heads" "tails"
## [37] "tails" "heads" "tails" "heads" "heads" "tails" "heads" "heads" "tails"
## [46] "tails" "tails" "tails" "heads" "heads" "heads" "heads" "tails" "heads"
## [55] "tails" "tails" "heads" "heads" "tails" "heads" "tails" "heads" "tails"
## [64] "heads" "tails" "heads" "heads" "tails" "heads" "heads" "tails" "heads"
## [73] "heads" "tails" "heads" "tails" "tails" "heads" "heads" "heads" "tails"
## [82] "heads" "heads" "heads" "tails" "tails" "heads" "tails" "tails" "heads"
## [91] "heads" "tails" "tails" "heads" "tails" "heads" "heads" "tails" "heads"
## [100] "heads"
table(sim_fair_coin)
## sim_fair_coin
## heads tails
## 53 47
sim_unfair_coin <- sample(coin_outcomes, size = 100, replace = TRUE,
prob = c(0.2, 0.8))
set.seed(1)
sim_unfair_coin1 <- sample(coin_outcomes, size = 100, replace = TRUE,
prob = c(0.2, 0.8))
sim_unfair_coin1
## [1] "tails" "tails" "tails" "heads" "tails" "heads" "heads" "tails" "tails"
## [10] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
## [19] "tails" "tails" "heads" "tails" "tails" "tails" "tails" "tails" "tails"
## [28] "tails" "heads" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
## [37] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails"
## [46] "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails" "tails"
## [55] "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails" "tails"
## [64] "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails" "heads"
## [73] "tails" "tails" "tails" "heads" "heads" "tails" "tails" "heads" "tails"
## [82] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
## [91] "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails" "heads"
## [100] "tails"
table(sim_unfair_coin1)
## sim_unfair_coin1
## heads tails
## 17 83
shot_outcomes <- c("H", "M")
sim_basket <- sample(shot_outcomes, size = 1, replace = TRUE)
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
## 58 75
sim_streak <- calc_streak(sim_basket)
ggplot(sim_streak, aes(x=length)) +
geom_bar()
kobe_streak %>%
summarise(Median_kobe = median(length),
Min_kobe = min(length),
Max_kobe = max(length),
Mean_kobe = mean(length))
## Median_kobe Min_kobe Max_kobe Mean_kobe
## 1 0 0 4 0.7631579
sim_streak %>%
summarise(Median_sim = median(length),
Min_sim = min(length),
Max_sim = max(length),
Mean_sim = mean(length))
## Median_sim Min_sim Max_sim Mean_sim
## 1 0 0 5 0.7631579