library(tidyverse)
library(openintro)Probability Lab
Probability Lab
Load packages
Data
head(kobe_basket) #preview data frame# A tibble: 6 × 6
vs game quarter time description shot
<fct> <int> <fct> <fct> <fct> <chr>
1 ORL 1 1 9:47 Kobe Bryant makes 4-foot two point shot H
2 ORL 1 1 9:07 Kobe Bryant misses jumper M
3 ORL 1 1 8:11 Kobe Bryant misses 7-foot jumper M
4 ORL 1 1 7:41 Kobe Bryant makes 16-foot jumper (Derek Fishe… H
5 ORL 1 1 7:03 Kobe Bryant makes driving layup H
6 ORL 1 1 6:01 Kobe Bryant misses jumper M
data("kobe_basket") #loading the data set into global environmentQuestion - 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 of 1 means with no streak going, Kobe made a shot, then missed the one after. There is exactly one hit and one miss in a streak of 1. Streak of 0 has one shot, which is a miss.
Question - 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()The distribution of Kobe’s shooting streak in the 2009 finals seems to be skewed right. His typical streak length is 0 and his longest streak is 4.
print(max(kobe_streak)) #double checking the maximum streak[1] 4
Simulating flipping an unfair coin & Setting a Seed
coin_outcomes <- c("heads", "tails")
set.seed(2556)
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
Simulating Kobe’s shots (With 45% hit percentage)
shot_outcomes <- c("H", "M")
set.seed(62622)
sim_baskets <- sample(shot_outcomes, size = 133, replace = TRUE,
prob = c(0.45,0.55))
table(sim_baskets)sim_baskets
H M
57 76
Showing the streak of the simulated shots
sim_streak <- calc_streak(sim_baskets)
ggplot(data = sim_streak, aes(x = length)) +
geom_bar()Question - 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.
With a 45% shooting percentage and 133 simulated shots, the streak also seems to be right skewed. Most streak length being 0, and the longest streak being 4.
Question - 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.
If I were to run the simulation with a different seed, I believe the streak distribution to be similar, but not exactly the same. Because it’s rare to have the exact same number of streaks, but the overall trend should be about the same since the shot percentage stays the same and our simulated sample size (133 shots) is pretty large.
Question - 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.
The simulated shooter’s distribution of streaks is pretty similar to Kobe’s. Both distributions are left skewed, with 0 being the typical streak and 4 being the longest, the amount of streaks of length 1-3 are also similar. Since the simulated shooter have independent shots, I think Kobe’s shooting patterns does not fit the hot hand model.