Load Packages

Load Data

kobe <- read.csv("kobe.csv")
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

Calculate streak

calc_streak <- function(x){
  y <- rep(0,length(x))
  y[x == "H"] <- 1
  y <- c(0, y, 0)
  wz <- which(y == 0)
  streak <- diff(wz) - 1
  return(streak)
}

Plot streak

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

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

1a.What about a streak length of 0?

The length of 1 a shooting streak to be the number of consecutive baskets made until a miss occurs.

A streak lenght of 0 means the number of misses until a basket is made.

2.Describe the distribution of Kobe’s streak lengths from the 2009 NBA finals.

2b. What was his typical streak length? How long was his longest streak of baskets?

The distribution reflects the longest streak to the right of the chart.

Kobe’s has his longet streaks at 4 baskets.

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

45

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")
sim_basket <- sample(outcomes, size = 133, replace = TRUE, prob = c(0.45, 0.55))
sim_basket
##   [1] "M" "M" "H" "M" "M" "M" "M" "M" "H" "M" "M" "H" "H" "H" "M" "M" "M"
##  [18] "M" "H" "H" "M" "M" "M" "M" "M" "M" "M" "H" "M" "M" "M" "H" "H" "H"
##  [35] "H" "M" "H" "M" "M" "M" "H" "H" "M" "M" "M" "M" "H" "H" "H" "M" "H"
##  [52] "H" "M" "M" "H" "M" "H" "M" "H" "M" "H" "M" "M" "H" "H" "M" "M" "H"
##  [69] "M" "M" "M" "M" "H" "M" "M" "H" "H" "H" "H" "H" "H" "H" "H" "H" "M"
##  [86] "M" "M" "M" "H" "H" "H" "M" "H" "H" "H" "M" "M" "H" "M" "H" "H" "H"
## [103] "H" "H" "M" "M" "H" "H" "M" "M" "M" "M" "M" "H" "M" "M" "M" "M" "H"
## [120] "H" "M" "H" "M" "M" "H" "H" "M" "M" "M" "M" "M" "M" "H"

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

Plot Streak

streak<- calc_streak(sim_basket)
barplot(table(streak))

The longest streak is 4 baskets.

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

The results are andomly selected. Therefore, the results will be significantly different.

If the set.seed, which chooses the starting point of the sequence of number were to be set

to a different numberthe results may vary.

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

Based on the charts above the distributions do not differ significantly.

As a result, the hot hand theory does not hold true.