Getting Started

Load data and get first few rows

load("more/kobe.RData")
head(kobe)
##    vs game quarter time
## 1 ORL    1       1 9:47
## 2 ORL    1       1 9:07
## 3 ORL    1       1 8:11
## 4 ORL    1       1 7:41
## 5 ORL    1       1 7:03
## 6 ORL    1       1 6:01
##                                               description basket
## 1                 Kobe Bryant makes 4-foot two point shot      H
## 2                               Kobe Bryant misses jumper      M
## 3                        Kobe Bryant misses 7-foot jumper      M
## 4 Kobe Bryant makes 16-foot jumper (Derek Fisher assists)      H
## 5                         Kobe Bryant makes driving layup      H
## 6                               Kobe Bryant misses jumper      M

Hit/Basket data

kobe$basket[1:9]
## [1] "H" "M" "M" "H" "H" "M" "M" "M" "M"

Exercise 1: A streak of 1 is when there is 1 successful shot, a hit, and a streak of zero is when there is an unsuccessful attempt, a miss.

kobe_streak <- calc_streak(kobe$basket)
barplot(table(kobe_streak))

Exercise 2 Kobe’s longest streak and his average streak length.

max(kobe_streak)
## [1] 4
mean(kobe_streak)
## [1] 0.7631579

Simulations in R Flipping a coin

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

Flipping a coin 100x

sim_fair_coin <- sample(outcomes, size = 100, replace = TRUE)
sim_fair_coin
##   [1] "tails" "tails" "heads" "tails" "heads" "tails" "tails" "heads"
##   [9] "tails" "tails" "heads" "heads" "heads" "heads" "tails" "heads"
##  [17] "heads" "heads" "heads" "heads" "tails" "heads" "heads" "heads"
##  [25] "tails" "tails" "heads" "heads" "heads" "tails" "tails" "tails"
##  [33] "heads" "heads" "tails" "tails" "heads" "tails" "tails" "heads"
##  [41] "heads" "heads" "tails" "tails" "tails" "tails" "tails" "tails"
##  [49] "heads" "tails" "heads" "heads" "tails" "tails" "heads" "heads"
##  [57] "tails" "tails" "heads" "heads" "heads" "heads" "heads" "tails"
##  [65] "tails" "tails" "heads" "tails" "tails" "heads" "heads" "tails"
##  [73] "tails" "tails" "tails" "heads" "tails" "tails" "tails" "heads"
##  [81] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
##  [89] "heads" "heads" "heads" "heads" "heads" "heads" "tails" "tails"
##  [97] "heads" "tails" "tails" "tails"

Table of 100 coin flips

table(sim_fair_coin)
## sim_fair_coin
## heads tails 
##    47    53

Probability of an unfair coin that will land on heads 20% of the time

sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))

Exercise 3: In mu simulation of flipping the unfair coin 100 times, it flipped heads 20 times.

table(sim_unfair_coin)
## sim_unfair_coin
## heads tails 
##    29    71

Simulating the Independent Shooter

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

Adjusting simulation so shooting percentage is 45% with a sample of 133 shots.

sim_basket <- sample(outcomes, size = 133, replace = TRUE, prob = c(0.45, 0.65))

Viewing Kobe’s data alongside our simulated data

kobe$basket
##   [1] "H" "M" "M" "H" "H" "M" "M" "M" "M" "H" "H" "H" "M" "H" "H" "M" "M"
##  [18] "H" "H" "H" "M" "M" "H" "M" "H" "H" "H" "M" "M" "M" "M" "M" "M" "H"
##  [35] "M" "H" "M" "M" "H" "H" "H" "H" "M" "H" "M" "M" "H" "M" "M" "H" "M"
##  [52] "M" "H" "M" "H" "H" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M" "M" "H"
##  [69] "M" "M" "M" "M" "H" "M" "H" "M" "M" "H" "M" "M" "H" "H" "M" "M" "M"
##  [86] "M" "H" "H" "H" "M" "M" "H" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M"
## [103] "H" "M" "M" "M" "H" "M" "H" "H" "H" "M" "H" "H" "H" "M" "H" "M" "H"
## [120] "M" "M" "M" "M" "M" "M" "H" "M" "H" "M" "M" "M" "M" "H"
sim_basket
##   [1] "M" "H" "H" "H" "M" "H" "M" "H" "M" "M" "H" "M" "M" "M" "M" "M" "H"
##  [18] "M" "M" "H" "H" "M" "H" "M" "M" "M" "M" "H" "H" "M" "H" "M" "M" "H"
##  [35] "H" "M" "H" "H" "M" "H" "H" "M" "H" "H" "H" "M" "M" "M" "M" "H" "M"
##  [52] "M" "H" "M" "H" "H" "M" "M" "M" "M" "H" "M" "H" "H" "H" "M" "M" "H"
##  [69] "H" "H" "M" "H" "H" "H" "M" "M" "H" "M" "M" "H" "M" "M" "M" "H" "H"
##  [86] "M" "M" "M" "M" "H" "M" "H" "M" "M" "M" "H" "M" "M" "H" "H" "M" "H"
## [103] "M" "M" "H" "H" "H" "H" "M" "M" "H" "M" "H" "M" "M" "M" "M" "M" "M"
## [120] "M" "H" "H" "H" "H" "H" "M" "H" "M" "M" "M" "M" "M" "H"

On your own 1) The max streak in the simulation is higher than Kobe’s. Kobe had a max streak of 4 while the simulation has a max streak of 6. The zero streak was the highest while each of the next streaks decreased for Kobe, and the 2 and 3 streak bars were very similar. For the simulation, the zero is also the highest and there is is a decrease as the streaks get higher, however, bars 4 and 6 are similar in size for the simulation instead of 2 and 3.

calc_streak(sim_basket)
##  [1] 0 3 1 1 0 1 0 0 0 0 1 0 2 1 0 0 0 2 1 0 2 2 2 3 0 0 0 1 0 1 2 0 0 0 1
## [36] 3 0 3 3 0 1 0 1 0 0 2 0 0 0 1 1 0 0 1 0 2 1 0 4 0 1 1 0 0 0 0 0 0 5 1
## [71] 0 0 0 0 1
sim_basket_streak <- calc_streak(sim_basket)
barplot(table(sim_basket_streak))

  1. If I were to run the simulation of the independent shooter a second time, I would expect the distribution to be somewhat similar. If no new variables or conditions are placed on the simulation, I don’t see why the results would be dramatically different.

  2. Kobe’s distribution of streak lengths is similar to the simulation. Most of the shot attempts were missed (streak of 0) with the second largest being 1 and a few streaks above 1. I do not think there is enough evidence to support the hot hand model. Both Kobe and the simulation had 13 streaks above 1. If hot hands was valid then I think you would see a greater number of streaks above 1, or at least a number of 2 streaks that was closer the number of 1 streaks.

table(kobe_streak)
## kobe_streak
##  0  1  2  3  4 
## 39 24  6  6  1
table(sim_basket_streak)
## sim_basket_streak
##  0  1  2  3  4  5 
## 41 19  8  5  1  1