library(tidyverse)
library(openintro)
glimpse(kobe_basket)
## Rows: 133
## Columns: 6
## $ vs <fct> ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL…
## $ game <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ quarter <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3…
## $ time <fct> 9:47, 9:07, 8:11, 7:41, 7:03, 6:01, 4:07, 0:52, 0:00, 6:35…
## $ description <fct> Kobe Bryant makes 4-foot two point shot, Kobe Bryant misse…
## $ shot <chr> "H", "M", "M", "H", "H", "M", "M", "M", "M", "H", "H", "H"…
Exercise 1
A streak length of 1 means that there is 1 hit and then a miss. A
streak length of 2 would refer to there being 2 hits and then a miss. A
streak length of 0 would involve one miss.
# Creating a variable for the lengths of each streak
kobe_streak <- calc_streak(kobe_basket$shot)
# Visualizing the distribution of the streak lengths
ggplot(data = kobe_streak, aes(x = length))+
geom_bar()

Exercise 2
Kobe’s overall distribution of streak lengths is fairly skewed to
the right. Most commonly, he was achieving a streak of 0, but there were
a couple of times when he achieved his longest streak of 4.
coin_outcomes <- c(“heads”, “tails”) sample(coin_outcomes, size =
1, replace = TRUE) sim_fair_coin <- sample(coin_outcomes, size = 100,
replace = TRUE) sim_fair_coin table(sim_fair_coin) # Simulating an
unfair coin sim_unfair_coin <- sample(coin_outcomes, size = 100,
replace = TRUE, prob = c(0.2, 0.8)) sim_unfair_coin set.seed(12345)
sim_unfair_coin
Exercise 3
18 of the coins came up as heads. The code for the sample of the
unfair coin can be seen above.
Simulating one shot from an independent shooter shot_outcomes
<-
c(“H”, “M”) sim_basket <- sample(shot_outcomes, size = 1, replace
= TRUE)
Exercise 4
Adjusting shot outcomes to a shooting percentage of 45% for 133
shots
sim_basket <- sample(shot_outcomes, size = 133, replace = TRUE,
prob = c(0.45, 0.55))
Exercise 5
Using calc_streak to compute streak lengths of sim basket
sim_streak <- calc_streak(sim_basket) ggplot(data = sim_streak,
aes(x = length))+ geom_bar()
Exercise 6
The distribution of streak lengths, as with Kobe’s, is fairly
right-skewed. The majority of the time, the streak length is zero, but
there are a reasonable amount of streaks with a length of one or two.
The highest streak length is an outlier of around 8; there are no
streaks between it and 5.
ggplot(data = kobe_streak, aes(x = length))+ geom_bar() http://127.0.0.1:20111/graphics/071761e7-94b2-4f6f-9d48-7e358748e646.png
# The image can be seen above.
Exercise 7
I would expect the streak distribution to be slightly different, as
this one involved an unexpected outlier that might not otherwise appear
in other distributions, but I would expect the general shape and overall
rightward skew to remain the same. Given that the probability of scoring
would be very low in general, I would expect the streak lengths to be
most numerous at 0.
Exercise 8
Kobe’s distribution is very similar to the one shown above. It
doesn’t have quite as strong of a rightward skew, but it shares the very
distinct shape. This would indicate that the hot hand model does not
suit Kobe, as his shooting streak distribution generally resembles that
of the shooter whose shots have no probable influence on each
other.
install.packages("tinytex")