library(tidyverse)
library(openintro)
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?
Answer:
A streak length of 1 means that Kobe made one shot before missing a shot, so there is one hit followed by a miss. A streak length of 0 means that Kobe missed the shot without making a basket immediately before it. In other words, the streak length represents the number of consecutive hits before a miss.
kobe_streak <- calc_streak(kobe_basket$shot)
Next, I calculated Kobe’s streak lengths and created a bar chart to see how the streaks are distributed.
ggplot(data = kobe_streak, aes(x = length)) +
geom_bar()
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.
Answer:
Kobe Bryant’s streak-length distribution is right-skewed and unimodal, with most of the streaks being short. The typical streak length was 0, meaning most shots did not result in a consecutive streak of made baskets. His longest streak was 4 baskets.
summary(kobe_streak)
## length
## Min. :0.0000
## 1st Qu.:0.0000
## Median :0.0000
## Mean :0.7632
## 3rd Qu.:1.0000
## Max. :4.0000
barplot(table(kobe_streak))
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.
Answer:
For this simulation, I used an unfair coin with a 30% probability of heads and a 70% probability of tails. I set a seed so that the results can be reproduced each time the Markdown file is knitted. After 100 flips, the simulation resulted in 35 heads and 65 tails.
set.seed(99999)
results <- c("heads", "tails")
simulation_unfair_coin <- sample(
results,
size = 100,
replace = TRUE,
prob = c(0.3, 0.7)
)
table(simulation_unfair_coin)
## simulation_unfair_coin
## heads tails
## 35 65
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.
Answer:
To simulate a shooter with a 45% shooting percentage, I changed the probabilities so that a hit has a 45% chance and a miss has a 55% chance. I used a seed so the results can be reproduced and simulated 133 shots. The simulation resulted in 57 hits and 76 misses.
set.seed(99990)
possible_outcomes <- c("H", "M")
sim_basket <- sample(
possible_outcomes,
size = 133,
replace = TRUE,
prob = c(0.45, 0.55)
)
table(sim_basket)
## sim_basket
## H M
## 57 76
Using calc_streak, compute the streak lengths of sim_basket, and save the results in a data frame called sim_streak.
Answer:
I used calc_streak() to calculate the streak lengths
from sim_basket and saved the results as
sim_streak. The distribution is unimodal and right-skewed.
The most common streak length was 0, and the longest streak was 4
baskets.
sim_streak <- calc_streak(sim_basket)
table(sim_streak)
## length
## 0 1 2 3 4
## 43 18 11 3 2
barplot(table(sim_streak))
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.
Answer:
The streak-length distribution for the simulated independent shooter is right-skewed, with most of the streaks being short. The most common streak length was 0. In 133 shots, the longest streak was 7 baskets. Since the results are based on random simulation, a longer streak can occur even when each shot is independent.
set.seed(99998)
possible_outcomes_1 <- c("H", "M")
sim_basket <- sample(
possible_outcomes_1,
size = 133,
replace = TRUE,
prob = c(0.45, 0.55)
)
sim_streak <- calc_streak(sim_basket)
barplot(table(sim_streak))
table(sim_streak)
## length
## 0 1 2 3 4 6 7
## 36 14 10 2 2 2 1
max(sim_streak)
## [1] 7
min(sim_streak)
## [1] 0
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.
Answer:
If I ran the simulation a second time, I would expect the streak distribution to be somewhat similar, but not exactly the same. Since the shooting percentage is still 45%, the overall pattern should remain similar, with mostly short streaks. However, the exact number of streaks and the longest streak could change because each simulation is based on random outcomes.
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.
Answer:
Kobe Bryant’s streak distribution is fairly similar to the distribution from the simulated independent shooter. Both distributions are right-skewed and mostly have short streaks, with 0 being the most common streak length. Kobe’s longest streak was 4 baskets, while the simulated shooter had a longest streak of 7 baskets. Based on this comparison, there is not enough evidence to conclude that Kobe’s shooting pattern supports the hot hand model.
barplot(table(kobe_streak))
barplot(table(sim_streak))