Hot Hands Lab

Author

A Isa

Hot Hands Lab

Getting Started

Load libraries

library(tidyverse)
library(openintro)

Data

data(kobe_basket)
head(kobe_basket)
# A tibble: 6 × 6
  vs     game quarter time  description                                    shot 
  <fct> <int> <fct>   <fct> <fct>                                          <chr>
1 ORL       1 1       9:47  Kobe Bryant makes 4-foot two point shot        H    
2 ORL       1 1       9:07  Kobe Bryant misses jumper                      M    
3 ORL       1 1       8:11  Kobe Bryant misses 7-foot jumper               M    
4 ORL       1 1       7:41  Kobe Bryant makes 16-foot jumper (Derek Fishe… H    
5 ORL       1 1       7:03  Kobe Bryant makes driving layup                H    
6 ORL       1 1       6:01  Kobe Bryant misses jumper                      M    

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?

Answer: A streak length of one means 1 basket was made followed by a miss. A streak of zero means the basket was missed.

kobe_streak <- calc_streak(kobe_basket$shot)
summary(kobe_streak)
     length      
 Min.   :0.0000  
 1st Qu.:0.0000  
 Median :0.0000  
 Mean   :0.7632  
 3rd Qu.:1.0000  
 Max.   :4.0000  

Create A Bar Graph

k1 <- ggplot(data = kobe_streak, aes(x = length)) +
  geom_bar()
k1

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: The plot of Kobe’s streaks is skewed right. His typical streak length was 0 (the median streak length and also the highest frequency of streaks). As demonstrated in the plot below, Kobe’s longest streak was 4 baskets.

#Answer 2 plot
k1

Simulations in R

Simulation 1

coin_outcomes <- c("heads", "tails")
sample(coin_outcomes, size = 1, replace = TRUE)
[1] "heads"

Simulation 2

sample(coin_outcomes, size = 1, replace = TRUE)
[1] "heads"

Simulation 3

sample(coin_outcomes, size = 1, replace = TRUE)
[1] "tails"

Simulation * 100

sim_fair_coin <- sample(coin_outcomes, size = 100, replace = TRUE)
sim_fair_coin
  [1] "tails" "heads" "heads" "heads" "heads" "tails" "heads" "tails" "heads"
 [10] "heads" "tails" "heads" "heads" "heads" "tails" "tails" "heads" "tails"
 [19] "tails" "heads" "tails" "tails" "heads" "heads" "heads" "tails" "tails"
 [28] "heads" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "heads"
 [37] "tails" "tails" "tails" "heads" "heads" "heads" "heads" "tails" "tails"
 [46] "heads" "heads" "tails" "heads" "tails" "tails" "heads" "tails" "heads"
 [55] "heads" "heads" "tails" "tails" "heads" "tails" "heads" "heads" "heads"
 [64] "heads" "tails" "heads" "heads" "heads" "tails" "heads" "tails" "tails"
 [73] "tails" "heads" "tails" "heads" "heads" "tails" "tails" "heads" "tails"
 [82] "heads" "heads" "tails" "heads" "tails" "heads" "heads" "tails" "heads"
 [91] "tails" "heads" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
[100] "heads"
table(sim_fair_coin)
sim_fair_coin
heads tails 
   50    50 

Setting Seed

set.seed(35797)
sim_unfair_coin <- sample(coin_outcomes, size = 100, replace = TRUE, 
                          prob = c(0.2, 0.8))

Exercise 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. Since the markdown file will run the code, and generate a new sample each time you Knit it, you should also “set a seed” before you sample. Read more about setting a seed below.

Answer: As shown in the following chunk, 26 flips came up heads when I flipped the unfair coin 100 times.

#Answer 3 code
sim_unfair_coin
  [1] "tails" "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails"
 [10] "tails" "tails" "heads" "heads" "tails" "heads" "heads" "heads" "tails"
 [19] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails"
 [28] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
 [37] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
 [46] "heads" "tails" "tails" "tails" "heads" "heads" "tails" "tails" "heads"
 [55] "heads" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
 [64] "heads" "tails" "tails" "heads" "tails" "tails" "tails" "tails" "heads"
 [73] "heads" "tails" "tails" "tails" "tails" "tails" "heads" "heads" "tails"
 [82] "heads" "tails" "tails" "heads" "tails" "tails" "tails" "tails" "tails"
 [91] "tails" "heads" "heads" "tails" "tails" "tails" "heads" "tails" "tails"
[100] "tails"
table(sim_unfair_coin)
sim_unfair_coin
heads tails 
   26    74 
#to learn more about the 'sample' function
#?sample

Simulating the Independent Shooter

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

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.

Answer: To make the sample function reflect a shooting percentage of 45%, I need to adjust the probability weights using the prob argument.

#Answer 4 code
sim_basket <- sample(shot_outcomes, size = 133, replace = TRUE, 
                     prob = c(0.45, 0.55))

More Practice

Exercise 5

Using calc_streak, compute the streak lengths of sim_basket, and save the results in a data frame called sim_streak.

#Answer 5 code
sim_streak <- calc_streak(sim_basket)
head(sim_streak)
  length
1      2
2      0
3      0
4      3
5      0
6      1

Exercise 6

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? Make sure to include a plot in your answer.

Answer: The plot is heavily skewed right. The typical streak length with a 45% shooting percentage is 0 (at least half of the streaks are of length 0 and lengths of 0 occur most frequently). The longest streak of baskets is 6. Please see the following plot for more information.

#Answer 6 code pt 1
summary(sim_streak)
     length      
 Min.   :0.0000  
 1st Qu.:0.0000  
 Median :0.0000  
 Mean   :0.6543  
 3rd Qu.:1.0000  
 Max.   :6.0000  
#Answer 6 code pt 2
s1 <- ggplot(data = sim_streak, aes(x=length)) + geom_bar()

s1

Exercise 7

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.

Answer: Because I set a seed value, I expect the results to stay the same no matter how often I press “run chunk”. If I created a new chunk with the same information, I think the distribution would change somewhat since it would be a random simulation. Results would be similar to streak lengths in Chunk 5.

Exercise 8

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.

Answer: The plots of Kobe’s and the simulated shooter’s streaks both skew right. As the simulated data is based on a shooter that does not have a hot hand and Kobe’s data is distributed similarly to the simulated data, this suggests that the hot hand model does not fit Kobe’s shooting patterns.