#library(tidyverse)
#library(openintro)
#library(dplyr)
#library(ggplot2)
#library(mosaic)
#glimpse(kobe_basket)
#write.csv (kobe_basket, file = "kobe_basket.csv")
#kobe_basket
#table(kobe_basket$shot)

Exercise 1

Insert any text here.

# Insert code for Exercise 1 here
#kobe_streak <- calc_streak(kobe_basket$shot)
#ggplot(data = kobe_streak, aes(x=length)) +
   #geom_bar()
#table(kobe_streak)

A streak of 1 isn’t a streak. It’s an observation, an event, an incident, a one-off. I assume streaks of zero mean misses. But if it does, the math doesn’t work - see below.

Exercise 2

Answer: Kobe apparently had 1 streak of 4 baskets in a row. His most frequent “streak” was one basket. He had 6 streaks of 2 and the same number for 3. See the histogram and table above. (241) + (26) + (36) + (41) = 58. Add 39 = 97. What does a streak of zero mean? So if the zero means he made 39 shots, then he made 97 of 133, or 72.9%. But if zero means his misses, the made 58 of 97 attempts, or 59.8%. In order to get at the bottom of this, I saved kobe_basket using the write command, then did a table of hits and misses. The code is above the histogram; I did all this analysis to answer Exercise 5, well after I completed Exercise 2. According to the results of the table command, Kobe missed 75 shots and made 58. I have no clue why the zero column represents 39 values when he missed 75 shots. 75+ 58 is 133. 58 is 43.6%. So Kobe’s actual shooting % was 43.6. Rounded to the nearest 5%, that’s 45%.

Exercise 3

coin_outcomes <- c("heads", "tails")
sample(coin_outcomes, size = 1, replace = TRUE)
## [1] "heads"
sim_fair_coin <-sample(coin_outcomes, size = 100, replace = TRUE)

sim_fair_coin
##   [1] "heads" "tails" "heads" "tails" "tails" "tails" "tails" "tails" "heads"
##  [10] "heads" "tails" "heads" "tails" "tails" "heads" "heads" "heads" "tails"
##  [19] "tails" "heads" "tails" "tails" "tails" "heads" "tails" "heads" "tails"
##  [28] "heads" "heads" "heads" "tails" "heads" "heads" "tails" "heads" "tails"
##  [37] "heads" "tails" "heads" "tails" "heads" "heads" "heads" "heads" "tails"
##  [46] "heads" "tails" "tails" "tails" "heads" "heads" "heads" "tails" "tails"
##  [55] "heads" "heads" "heads" "tails" "heads" "tails" "tails" "tails" "heads"
##  [64] "heads" "heads" "tails" "heads" "heads" "tails" "tails" "heads" "heads"
##  [73] "heads" "tails" "heads" "tails" "heads" "heads" "tails" "heads" "heads"
##  [82] "tails" "tails" "heads" "tails" "heads" "heads" "heads" "heads" "heads"
##  [91] "heads" "tails" "heads" "heads" "tails" "tails" "heads" "tails" "tails"
## [100] "tails"
table(sim_fair_coin)
## sim_fair_coin
## heads tails 
##    54    46
sim_unfair_coin <-sample(coin_outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
sim_unfair_coin <-sample(coin_outcomes, size = 100, replace = TRUE)

sim_unfair_coin
##   [1] "heads" "heads" "tails" "heads" "heads" "tails" "heads" "heads" "heads"
##  [10] "heads" "tails" "tails" "heads" "heads" "tails" "heads" "tails" "heads"
##  [19] "tails" "tails" "heads" "heads" "tails" "heads" "heads" "tails" "heads"
##  [28] "heads" "tails" "tails" "tails" "tails" "tails" "heads" "tails" "tails"
##  [37] "tails" "heads" "heads" "heads" "tails" "tails" "heads" "tails" "heads"
##  [46] "tails" "heads" "heads" "tails" "heads" "tails" "heads" "tails" "tails"
##  [55] "heads" "tails" "heads" "heads" "tails" "heads" "tails" "tails" "heads"
##  [64] "heads" "tails" "tails" "heads" "tails" "heads" "tails" "heads" "heads"
##  [73] "heads" "heads" "tails" "tails" "heads" "tails" "heads" "tails" "heads"
##  [82] "heads" "heads" "tails" "heads" "tails" "tails" "heads" "tails" "heads"
##  [91] "tails" "heads" "heads" "tails" "heads" "tails" "tails" "tails" "heads"
## [100] "tails"
table(sim_unfair_coin)
## sim_unfair_coin
## heads tails 
##    52    48

Run the unfair coin example after setting seed.

set.seed(740117)
sim_unfair_coin <-sample(coin_outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
sim_unfair_coin <-sample(coin_outcomes, size = 100, replace = TRUE)

sim_unfair_coin
##   [1] "heads" "heads" "heads" "heads" "heads" "tails" "heads" "tails" "heads"
##  [10] "tails" "tails" "tails" "tails" "tails" "tails" "heads" "heads" "tails"
##  [19] "tails" "tails" "heads" "tails" "tails" "tails" "heads" "tails" "tails"
##  [28] "tails" "tails" "heads" "tails" "heads" "heads" "tails" "tails" "heads"
##  [37] "tails" "heads" "heads" "tails" "tails" "heads" "tails" "tails" "heads"
##  [46] "tails" "tails" "heads" "tails" "heads" "heads" "heads" "heads" "heads"
##  [55] "heads" "tails" "tails" "tails" "heads" "heads" "tails" "tails" "heads"
##  [64] "tails" "heads" "heads" "tails" "heads" "tails" "tails" "tails" "heads"
##  [73] "heads" "tails" "tails" "tails" "heads" "heads" "tails" "heads" "heads"
##  [82] "tails" "heads" "tails" "heads" "tails" "tails" "tails" "tails" "heads"
##  [91] "tails" "heads" "heads" "tails" "heads" "tails" "tails" "heads" "heads"
## [100] "heads"
table(sim_unfair_coin)
## sim_unfair_coin
## heads tails 
##    47    53

This is a more expected result; I was actually surprised to get the same results, fair and unfair. But why the same 2 numbers - 53 & 47? What’s the probability of that?

Exercise 4

shot_outcomes <- c("H", "M")
sim_basket_ind <- sample(shot_outcomes, size = 1, replace = TRUE)
shot_outcomes <- c("H", "M")
sim_basket_ind <- sample(shot_outcomes, size = 133, replace = TRUE,
                   prob = c(0.45, 0.55))
table(sim_basket_ind)
## sim_basket_ind
##  H  M 
## 60 73

These results seem to indicate Kobe didn’t have a hot hand as compared to our hypothetical independent shooter. As shown above in the write-up for Exercise 2, Kobe’s actual shooting % was 43.6; he made 58 shots and missed 75. Our hypothetical independent shooter made 55 and missed 78, or 41.35% - nearly as good as Kobe.

Exercise 5

#sim_streak <- calc_streak (sim_basket_ind)
#ggplot(data=sim_streak, aes(x = length)) +
 # geom_bar()

Exercise 6

This distribution of streak lengths is similar to Kobe’s, in that it is skewed to the right, with the greatest number of streaks zero, whatever that means. Instead of streaks of 2 and 3, as was the case w/ Kobe, this player had many more streaks of 2. However, this player did manage 1 streak of 8, which is impressive.

Exercise 7

Given that two bar charts are skewed heavily to the right, and both have very high counts at the zero mark, I would expect subsequent runs to have a similar pattern. But as the 2nd bar chart shows, streaks along the tail will differ, with streaks occurring at different places along the tail. Large numbers of long streaks seem to be the exception rather than the rule.

Exercise 8

Kobe’s pattern of streak lengths roughly parallels the second shooter’s distribution of streak lengths, as noted in the response in Exercise 7. It would seem the hot hand model fits neither shooter. The patterns are random. Think of a real basketball game. If a good shooter like Kobe is open, he will likely make the shot. But whether he will be open is random; the action on the court is too fast-paced. If he is open and has the ball, he’s lucky. That scenario can’t be planned. If Kobe is covered and manages to take a shot, the degree to which he is covered and the angle at which he shoots through the coverage are both random. Both variables affect whether he will make the shot. Yes, skill is obviously a factor. But with a shooting percentage below 50%, the streaks do not come in any predictable fashion. Skill obviously raises the percentage, but much of it comes down to the quality of the playing of the other team, and, to a certain extent, luck.

LS0tDQp0aXRsZTogIkxhYiBOYW1lIg0KYXV0aG9yOiAiQXV0aG9yIE5hbWUiDQpkYXRlOiAiYHIgU3lzLkRhdGUoKWAiDQpvdXRwdXQ6IG9wZW5pbnRybzo6bGFiX3JlcG9ydA0KLS0tDQoNCmBgYHtyIGxvYWQtcGFja2FnZXMsIG1lc3NhZ2U9RkFMU0V9DQojbGlicmFyeSh0aWR5dmVyc2UpDQojbGlicmFyeShvcGVuaW50cm8pDQojbGlicmFyeShkcGx5cikNCiNsaWJyYXJ5KGdncGxvdDIpDQojbGlicmFyeShtb3NhaWMpDQojZ2xpbXBzZShrb2JlX2Jhc2tldCkNCmBgYA0KDQpgYGB7cn0NCg0KI3dyaXRlLmNzdiAoa29iZV9iYXNrZXQsIGZpbGUgPSAia29iZV9iYXNrZXQuY3N2IikNCiNrb2JlX2Jhc2tldA0KI3RhYmxlKGtvYmVfYmFza2V0JHNob3QpDQpgYGANCg0KDQoNCg0KIyMjIEV4ZXJjaXNlIDENCg0KSW5zZXJ0IGFueSB0ZXh0IGhlcmUuDQoNCmBgYHtyIGNvZGUtY2h1bmstbGFiZWx9DQojIEluc2VydCBjb2RlIGZvciBFeGVyY2lzZSAxIGhlcmUNCiNrb2JlX3N0cmV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