Exercises


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?

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
kobe$basket[1:9]
## [1] "H" "M" "M" "H" "H" "M" "M" "M" "M"

Streak length of 1 means 1 hit followed by 0 miss Streak length of 0 means 0 hit followed by 1 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_streak <- calc_streak(kobe$basket)
kobe_streak
##  [1] 1 0 2 0 0 0 3 2 0 3 0 1 3 0 0 0 0 0 1 1 0 4 1 0 1 0 1 0 1 2 0 1 2 1 0
## [36] 0 1 0 0 0 1 1 0 1 0 2 0 0 0 3 0 1 0 1 2 1 0 1 0 0 1 3 3 1 1 0 0 0 0 0
## [71] 1 1 0 0 0 1
plot(kobe_streak)


The most common hit would be streak length of 1, however he did the max streak length of 4

Exercise 3: In your simulation of flipping the unfair coin 100 times, how many flips came up heads?

outcomes <- c("heads", "tails")
sim_fair_coin <- sample(outcomes, size = 100, replace = TRUE)
table(sim_fair_coin)
## sim_fair_coin
## heads tails 
##    48    52

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.

outcomes <- c("H", "M")
#45% of hit and 55% of miss
sim_basket<- sample(outcomes, size = 133, replace = TRUE,prob = c(0.45, 0.55)) 
table(sim_basket)
## sim_basket
##  H  M 
## 59 74

On your own


Analysis 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?

simu_streak <- calc_streak(sim_basket)
summary(simu_streak)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  1.0000  0.7867  1.0000  5.0000
plot(simu_streak)


Analysis 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.

shooter2<-calc_streak(sample(outcomes, size = 133, replace = TRUE,prob = c(0.45, 0.55)))
summary(shooter2)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   0.000   0.000   0.675   1.000   5.000
plot(shooter2)


Analysis 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.

par(mfrow=c(1,2))


barplot(table(kobe_streak), main="Kobe Finals Data", xlab="streak")
barplot(table(shooter2), main="Independent shooter a second time",xlab="streak")