The goal
- think about the effects of independent and dependent events
- learn how to simulate shooting streaks in R
- to compare a simulation to actual data in order to determine if the hot hand phenomenon appears to be real.
Exercise 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?
- the length of a shooting streak is the number of consecutive baskets (hits) until a miss occurs
- A streak length of 1 means a hit followed by a miss.
- A streak length of 0 means a miss followed by a miss.
Exercise 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?
- Kobe’s streak shows Unimodal, right skewed distribution.
- The IQR of the distribution is 1
- His typical streak length : 0 (using median)
- His longest streak length : 4
calc_streak
## function(x){
## y <- rep(0,length(x))
## y[x == "H"] <- 1
## y <- c(0, y, 0)
## wz <- which(y == 0)
## streak <- diff(wz) - 1
## return(streak)
## }
kobe_streak <- calc_streak(kobe$basket)
barplot(table(kobe_streak))

summary(kobe_streak)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.0000 0.0000 0.7632 1.0000 4.0000
boxplot(kobe_streak)

Exercise 3: In your simulation of flipping the unfair coin 100 times, how many flips came up heads?
set.seed(23)
outcomes <- c("heads", "tails")
sample(outcomes, size = 1, replace = TRUE)
## [1] "tails"
sim_fair_coin <- sample(outcomes, size = 100, replace = TRUE)
table(sim_fair_coin)
## sim_fair_coin
## heads tails
## 46 54
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
table(sim_unfair_coin)
## sim_unfair_coin
## heads tails
## 21 79
answer_ex_3 <- table(sim_unfair_coin)[1]
Exercise 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.
set.seed(23)
outcomes <- c("H", "M")
sim_basket <- sample(outcomes, size = 133, replace = TRUE, prob = c(0.45, 0.55))
table(sim_basket)
## sim_basket
## H M
## 63 70
On your own
Comparing Kobe Bryant to the Independent Shooter
- Using calc_streak, compute the streak lengths of sim_basket
# Note that this simulation is done with set.seed(23)
sim_basket_streak_length <- calc_streak(sim_basket)
1. Describe the distribution of streak lengths. What is the typical streak length for this simulated independent shooter with a 45% shooting percentage? How long is the player’s longest streak of baskets in 133 shots?
- The distribution of streak length is unimodal, right skewed (Median 0, IQR 1)
- The typical streak length for this simulation is 0.
- The longest streak of is 6.
barplot(table(sim_basket_streak_length))

boxplot(sim_basket_streak_length)

summary(sim_basket_streak_length)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.0000 0.0000 0.8873 1.0000 6.0000
2. If you were to run the simulation of the independent shooter a second time, how would you expect its streak distribution to compare to the distribution from the question above? Exactly the same? Somewhat similar? Totally different? Explain your reasoning.
- In this markdown, I have set the seed value with set.seed(), so the result is replicable. However, even if it wasn’t set, I assume the results would be somewhat similar. Because the shots are independant of each other and the probability of making the shot does not change between the two simulations.
3. How does Kobe Bryant’s distribution of streak lengths compare to the distribution of streak lengths for the simulated shooter? Using this comparison, do you have evidence that the hot hand model fits Kobe’s shooting patterns? Explain.
- The distribution of streak lengths are similar for the simulation and for Kobe. However, the evidence is insufficient that the hot hand model fits kobe’s shooting patterns as the distributions are similar; both distributions are right skewed with similar ranges and both modes are 0.