In this lab we will examine Kobe Bryant’s performance in the 2009 NBA finals, and whether or not he exhibited the fabled “hot hand”.
This lab uses the “kobe_basket” dataset, which is included in the openintro package
library(tidyverse)
library(openintro)set.seed(100)A streak length of 1 is defined to be a single “hit” followed by a “miss”. A streak length of 0 is just a single missed shot, which must be preceeded by a “miss” as well (otherwise it would be part a 1-streak).
Plot Kobe’s streak lengths:
kobe_streak <- calc_streak(kobe_basket$shot)
ggplot(data = kobe_streak, aes(x = length)) + geom_bar()Kobe’s most frequently occurring streak length was 0. This is unsurprising, as even professionals miss many shots. His longest streak of “hits” was four baskets in a row.
Next, we’ll try comparing Kobe’s streak distribution to that of an “independent” shooter.
To this end, we’ll first demonstrate R’s functions for sampling probabilistic outcomes. The following code simulates a single coin toss:
coin_outcomes <- c("heads", "tails")
sample(coin_outcomes, size = 1, replace = TRUE)## [1] "tails"
Now, we will repeat the coin toss 100 times with the “size” parameter:
sim_fair_coin <- sample(coin_outcomes, size = 100, replace = TRUE)Let’s have a look at the actual outcomes which were computed:
sim_fair_coin## [1] "heads" "tails" "tails" "heads" "heads" "tails" "tails" "tails" "heads"
## [10] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "heads" "heads"
## [19] "heads" "heads" "tails" "tails" "heads" "tails" "heads" "heads" "tails"
## [28] "tails" "heads" "tails" "heads" "tails" "tails" "tails" "tails" "tails"
## [37] "tails" "heads" "heads" "heads" "heads" "tails" "heads" "tails" "tails"
## [46] "tails" "heads" "heads" "tails" "tails" "heads" "heads" "heads" "heads"
## [55] "heads" "heads" "tails" "heads" "heads" "tails" "heads" "heads" "heads"
## [64] "tails" "tails" "heads" "heads" "heads" "heads" "heads" "tails" "tails"
## [73] "tails" "heads" "heads" "tails" "tails" "heads" "tails" "tails" "heads"
## [82] "heads" "heads" "tails" "tails" "heads" "tails" "tails" "heads" "heads"
## [91] "heads" "heads" "tails" "tails" "heads" "heads" "tails" "tails" "tails"
## [100] "tails"
table(sim_fair_coin)## sim_fair_coin
## heads tails
## 50 50
We see that the results are very close to 50/50, as we would expect.
Unlike a coin toss, a basketball shot does not have a 50% probability of either outcome. Therefore, we will add a probability argument to simulate shooting with an unfair coin toss:
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
## 22 78
We could simulate an independent shooter with 50% hit rate like so:
shot_outcomes <- c("H", "M")
sim_basket <- sample(shot_outcomes, size=1, replace=TRUE)to simulate Kobe’s rate of 45%, we include the probability argument:
sim_basket <- sample(shot_outcomes, size=133, replace=TRUE, prob=c(0.45, 0.55))
table(sim_basket)## sim_basket
## H M
## 67 66
Use calc_streak to compute the streak lengths of sim_basket and save the results in a data frame called “sim_streak”.
sim_streak <- calc_streak(sim_basket)ggplot(data = sim_streak, aes(x = length)) + geom_bar()The distribution looks very similar to Kobe’s. The most common streak length is 0, with a sharply decreasing frequency as the length of the streaks increases.
If we run the trial a second time, we would expect the distributions to be qualitatively similar, but not necessarily exactly the same. In particular, we would expect 0 to be the most common streak length, with a decreasing frequency as the streaks get longer.
Let’s try running and plotting it once more:
sim_basket <- sample(shot_outcomes, size=133, replace=TRUE, prob=c(0.45, 0.55))
sim_streak <- calc_streak(sim_basket)
ggplot(data = sim_streak, aes(x = length)) + geom_bar()And indeed, this is what we observe.
If the “hot hand” hypothesis were true, we would expect Kobe to have longer generally longer and more frequent streaks than the independent shooter. We actually found that overall, Kobe’s tendency towards streaks was at best equal to, if not worse, than that of an independent shooter. Thus, our experiment seems to indicate that the “hot hands” hypothesis is false.