Library Load In

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6     ✔ purrr   0.3.4
## ✔ tibble  3.1.8     ✔ dplyr   1.0.9
## ✔ tidyr   1.2.0     ✔ stringr 1.4.1
## ✔ readr   2.1.2     ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(openintro)
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata

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?

A streak length of one would be 1 hit and 1 miss. A streak length of zero would simply be 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? Make sure to include the accompanying plot in your answer.

kobe_streak <- calc_streak(kobe_basket$shot)
ggplot(data = kobe_streak, aes(x = length)) +
  geom_bar()

Kobe’s streak looks like a discrete graph of 1/x as <=1 is fairly common, whereas any positive integer is statistically uncommon.

In terms of Kobe’s streaks:

  1. His typical streak length (mode excluding streaks with zero baskets) is 1 basket.
  2. His longest streak of baskets is 4!

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.

set.seed(0144)
coin_outcomes <- c("heads", "tails")
sim_fair_coin <- sample(coin_outcomes, size = 100, replace = TRUE)
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 
##    20    80

20 flips came up heads, 80 came up tails.

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.

set.seed(0144)
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 
## 58 75

Effectively, 3 parameters needs to be updated, the shot_outcomes, the size and the prob parameter.

Exercise 5

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

sim_streak <- calc_streak(sim_basket)
sim_streak

Exercise 6

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.

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

The distribution of the streak looks like a discrete graph of 1/x as <=1 is fairly common, whereas any positive integer is statistically uncommon.

In terms of the streak:

  1. The typical streak length (mode excluding streaks with zero baskets) is 1 basket.
  2. The longest streak of baskets is 6!

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.

I would expect it to be approximately the same. Just from a more fun perspective, I would say this fits nicely with Benford’s Law. In addition, with a high degree of confidence, I can say that the streak of 6 will most likely not be replicated in most other distributions as its occurrence is significantly small.

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.

Kobe’s distribution of streak lengths compared to the “random” distribution show a few key similarities. Firstly, he has a remarkably high rate of sinking baskets, which increases the odds of creating a streak >= 1. What is interesting to note is that the simulated shooter had a greater range of values (0-6), whereas Kobe simply had a range of 0-4. Suffice to say, looking at this distribution, the hot hand model is not relevant to Kobe as there is nothing indicating that previous independent events can predict a future event.