download.file("http://www.openintro.org/stat/data/kobe.RData", destfile = "kobe.RData")
load("kobe.RData")
head(kobe)
## vs game quarter time
## 1 ORL 1 1 9:47
## 2 ORL 1 1 9:07
## 3 ORL 1 1 8:11
## 4 ORL 1 1 7:41
## 5 ORL 1 1 7:03
## 6 ORL 1 1 6:01
## description basket
## 1 Kobe Bryant makes 4-foot two point shot H
## 2 Kobe Bryant misses jumper M
## 3 Kobe Bryant misses 7-foot jumper M
## 4 Kobe Bryant makes 16-foot jumper (Derek Fisher assists) H
## 5 Kobe Bryant makes driving layup H
## 6 Kobe Bryant misses jumper M
kobe$basket[1:9]
## [1] "H" "M" "M" "H" "H" "M" "M" "M" "M"
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 1 means that Kobe only made one basket before missing the next shot. A strength length of 0 means that Kobe had no hits, only misses.
kobe_streak <- calc_streak(kobe$basket)
barplot(table(kobe_streak))

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?
The distribution of Kobe’s streak length is right skewed. His typical streak length is 0 and his longest streak was 4 baskets.
outcomes <- c("heads", "tails")
sample(outcomes, size = 1, replace = TRUE)
## [1] "tails"
outcomes <- c("heads", "tails")
sample(outcomes, size = 1, replace = TRUE)
## [1] "heads"
outcomes <- c("heads", "tails")
sample(outcomes, size = 1, replace = TRUE)
## [1] "tails"
outcomes <- c("heads", "tails")
sample(outcomes, size = 1, replace = TRUE)
## [1] "tails"
sim_fair_coin <- sample(outcomes, size = 100, replace = TRUE)
sim_fair_coin
## [1] "tails" "tails" "heads" "heads" "heads" "heads" "heads" "heads"
## [9] "heads" "tails" "heads" "heads" "heads" "heads" "tails" "heads"
## [17] "tails" "heads" "tails" "tails" "heads" "heads" "heads" "heads"
## [25] "tails" "tails" "tails" "heads" "heads" "tails" "tails" "tails"
## [33] "heads" "heads" "heads" "tails" "tails" "tails" "tails" "heads"
## [41] "heads" "heads" "heads" "tails" "heads" "tails" "heads" "heads"
## [49] "heads" "tails" "heads" "heads" "heads" "tails" "tails" "tails"
## [57] "heads" "tails" "heads" "heads" "tails" "tails" "tails" "tails"
## [65] "heads" "heads" "heads" "tails" "tails" "tails" "heads" "heads"
## [73] "heads" "tails" "heads" "tails" "tails" "heads" "tails" "heads"
## [81] "tails" "heads" "tails" "tails" "tails" "heads" "tails" "heads"
## [89] "tails" "heads" "tails" "tails" "tails" "heads" "heads" "tails"
## [97] "heads" "tails" "heads" "tails"
table(sim_fair_coin)
## sim_fair_coin
## heads tails
## 53 47
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
Exercise 3: In your simulation of flipping the unfair coin 100 times, how many flips came up heads?
51 heads
?sample
## starting httpd help server ... done
outcomes <- c("H", "M")
sim_basket <- sample(outcomes, size = 1, replace = TRUE)
Exercise 4: What change needs to be made to the sample function so that it reflects a shooting percentage of 45% Make this adustment, then run a simulation to sample 133 shots. Assign the output of this sumulation to a new object called sim_basket.
outcomes <- c("H", "M")
sim_basket <- sample(outcomes, size = 133, replace = TRUE, prob=c(.45,.55))
Add the “prob” argument
kobe$basket
## [1] "H" "M" "M" "H" "H" "M" "M" "M" "M" "H" "H" "H" "M" "H" "H" "M" "M"
## [18] "H" "H" "H" "M" "M" "H" "M" "H" "H" "H" "M" "M" "M" "M" "M" "M" "H"
## [35] "M" "H" "M" "M" "H" "H" "H" "H" "M" "H" "M" "M" "H" "M" "M" "H" "M"
## [52] "M" "H" "M" "H" "H" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M" "M" "H"
## [69] "M" "M" "M" "M" "H" "M" "H" "M" "M" "H" "M" "M" "H" "H" "M" "M" "M"
## [86] "M" "H" "H" "H" "M" "M" "H" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M"
## [103] "H" "M" "M" "M" "H" "M" "H" "H" "H" "M" "H" "H" "H" "M" "H" "M" "H"
## [120] "M" "M" "M" "M" "M" "M" "H" "M" "H" "M" "M" "M" "M" "H"
sim_basket
## [1] "H" "H" "H" "H" "M" "M" "M" "H" "H" "M" "H" "M" "M" "H" "H" "M" "M"
## [18] "M" "M" "H" "M" "H" "H" "H" "H" "M" "H" "M" "M" "H" "H" "H" "M" "M"
## [35] "H" "H" "M" "H" "H" "H" "H" "H" "H" "H" "M" "M" "H" "H" "M" "M" "H"
## [52] "H" "H" "H" "M" "M" "H" "H" "M" "H" "M" "H" "H" "H" "H" "M" "H" "M"
## [69] "H" "M" "H" "M" "M" "H" "M" "H" "H" "M" "M" "M" "M" "H" "H" "H" "M"
## [86] "H" "M" "M" "H" "H" "M" "M" "M" "M" "H" "M" "M" "M" "H" "H" "M" "H"
## [103] "M" "H" "H" "M" "H" "M" "H" "M" "M" "H" "M" "H" "M" "H" "M" "M" "M"
## [120] "M" "M" "H" "H" "M" "H" "M" "H" "M" "H" "M" "M" "H" "M"
On Your Own
1:
basket_streak <- calc_streak(sim_basket)
barplot(table(basket_streak))

THe distribution for the independent shooter is right skewed. The player’s typical streak length is 0 hits but the player’s longst streak is 8 baskets.
2:
I would expect the distribution to be someewhat similar since the shooting percentage is the same.
3:
Kobe’s distribution is similar to the distribution of the simulated shooter which was determined to not have hot hands, so Kobe’s distribution also does not fit the hot hand model