Hot hands lab

Author

Bahameen Farrukh

Hot hands Lab

Load libraries

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(openintro)
Loading required package: airports
Loading required package: cherryblossom
Loading required package: usdata

Data

data("kobe_basket")
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"…

Exercise 1

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

Answer: There is one hit and one miss in a streak length of 1. Whereas, a streak length of 0 means that there is no hit and 1 miss.

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

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

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

Answer: The distribution of Kobe’s streak lengths from 2009 appear to be right-skewed. His typical streak length was 0, and his longest streak of baskets was 4.

Simulations in R

set.seed(0711)

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] "tails" "heads" "tails" "tails" "heads" "tails" "heads" "tails" "tails"
 [10] "tails" "heads" "tails" "heads" "tails" "heads" "tails" "heads" "heads"
 [19] "heads" "tails" "tails" "tails" "heads" "tails" "tails" "heads" "heads"
 [28] "tails" "tails" "tails" "tails" "heads" "heads" "tails" "heads" "heads"
 [37] "heads" "tails" "heads" "tails" "heads" "tails" "heads" "heads" "tails"
 [46] "heads" "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails"
 [55] "tails" "heads" "tails" "tails" "heads" "heads" "heads" "tails" "heads"
 [64] "heads" "heads" "heads" "tails" "tails" "tails" "heads" "tails" "tails"
 [73] "tails" "heads" "tails" "heads" "heads" "heads" "tails" "heads" "tails"
 [82] "tails" "heads" "heads" "heads" "heads" "heads" "tails" "tails" "tails"
 [91] "heads" "heads" "tails" "heads" "tails" "tails" "heads" "tails" "heads"
[100] "tails"
table(sim_fair_coin)
sim_fair_coin
heads tails 
   47    53 
sim_unfair_coin <- sample(coin_outcomes, size = 100, replace = TRUE, 
                          prob = c(0.2, 0.8))

table(sim_unfair_coin)
sim_unfair_coin
heads tails 
   16    84 

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: In my simulation of flipping the unfair coin 100 times, 16 flips came up as heads. Code has been included above.

Simulating the Independent Shooter

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: Please see my code below.

set.seed(0711)

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 
67 66 

Exercise 5

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

Answer: Please see my code below.

sim_streak <- calc_streak(sim_basket)

sim_streak
   length
1       0
2       0
3       0
4       1
5       0
6       0
7       0
8       2
9       9
10      0
11      0
12      0
13      0
14      0
15      2
16      3
17      3
18      3
19      0
20      0
21      0
22      2
23      0
24      0
25      6
26      3
27      0
28      0
29      0
30      0
31      1
32      0
33      3
34      0
35      0
36      1
37      0
38      0
39      4
40      2
41      0
42      2
43      0
44      0
45      1
46      0
47      0
48      0
49      2
50      0
51      1
52      1
53      0
54      1
55      0
56      2
57      0
58      1
59      0
60      0
61      1
62      0
63      0
64      3
65      0
66      1
67      6

Exercise 6

ggplot(data = sim_streak, aes(x = length)) + geom_bar()

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 distribution of streak lengths appears to be right-skewed. The typical streak length is 0 while the longest streak is around 9.

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: I think the streak distribution pattern will remain the same (i.e: right-skewed) for both but the exact results could be slightly different everytime we run the simulation.

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: Kobe Bryant’s longest shooting streak is 4, while the simulated shooter’s longest streak is about 9. Both distributions are right-skewed, showing shorter streaks are more common. This difference in the longest streaks suggests that Kobe’s shooting patterns do not fit the hot hand model, as the simulated shooter, who is modeled by random chance, has longer streaks.