Download the data and make it viewable as “kobe.RData”
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
Allows us to view the amount of steaks after 9 shot attempts. Every streak ends after a “M” so there are 6 streaks
kobe$basket[1:9]
## [1] "H" "M" "M" "H" "H" "M" "M" "M" "M"
calc_streak is a customized funtion which was loaded in with the data. It’s used to calculate the lengths of all shooting streaks. The barplot funtion is meant to look at distribution.
kobe_streak <- calc_streak(kobe$basket)
barplot(table(kobe_streak))
Think of this as a hat with two slips of paper in it: one slip says heads and the other says tails. The sample function draws one slip from the hat and tells us if it was a head or a tail.
outcomes <- c("heads", "tails")
sample(outcomes, size = 1, replace = TRUE)
## [1] "tails"
There are 2 elements so there’s a push towards 50/50
sim_fair_coin <- sample(outcomes, size = 100, replace = TRUE)
sim_fair_coin
## [1] "tails" "tails" "heads" "tails" "heads" "tails" "tails" "tails"
## [9] "heads" "tails" "tails" "heads" "tails" "heads" "heads" "tails"
## [17] "heads" "tails" "heads" "tails" "heads" "tails" "heads" "heads"
## [25] "tails" "tails" "heads" "tails" "tails" "heads" "heads" "tails"
## [33] "heads" "heads" "heads" "tails" "tails" "heads" "heads" "heads"
## [41] "heads" "heads" "tails" "tails" "tails" "tails" "tails" "heads"
## [49] "tails" "heads" "heads" "heads" "heads" "tails" "heads" "heads"
## [57] "tails" "tails" "heads" "tails" "tails" "tails" "heads" "tails"
## [65] "tails" "tails" "heads" "tails" "tails" "tails" "heads" "tails"
## [73] "heads" "heads" "tails" "tails" "heads" "heads" "tails" "tails"
## [81] "tails" "heads" "tails" "tails" "heads" "tails" "tails" "tails"
## [89] "heads" "heads" "tails" "tails" "tails" "heads" "heads" "tails"
## [97] "tails" "tails" "tails" "heads"
table(sim_fair_coin)
## sim_fair_coin
## heads tails
## 44 56
The probability of drawing “Head” 20% of the time and “Tails” 80% of the time.
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
Simulating an independent shooter
outcomes <- c("H", "M")
sim_basket <- sample(outcomes, size = 1, replace = TRUE)
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"
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?
kobe_streak <- calc_streak(kobe$basket)
barplot(table(kobe_streak))
kobe_streak_ind <- sample(outcomes, size = 133, replace = TRUE, prob = c(0.45, 0.55))
kobe_streak_ind
## [1] "M" "H" "M" "M" "M" "H" "H" "H" "M" "H" "H" "M" "H" "H" "M" "H" "M"
## [18] "M" "M" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M" "M" "H" "M" "M" "M"
## [35] "H" "H" "M" "M" "H" "H" "H" "M" "H" "M" "H" "H" "H" "M" "M" "M" "H"
## [52] "M" "H" "M" "M" "M" "M" "H" "H" "M" "M" "H" "H" "H" "H" "H" "M" "H"
## [69] "H" "H" "M" "M" "H" "H" "H" "H" "M" "M" "H" "M" "H" "H" "M" "M" "M"
## [86] "H" "H" "M" "M" "M" "M" "M" "H" "M" "M" "H" "H" "M" "M" "M" "H" "H"
## [103] "M" "H" "M" "H" "H" "M" "M" "M" "H" "M" "H" "H" "M" "M" "H" "H" "H"
## [120] "M" "M" "H" "M" "M" "H" "H" "H" "M" "M" "M" "M" "M" "M"
table(kobe_streak_ind)
## kobe_streak_ind
## H M
## 62 71
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.
# I would expect the results to be somewhat similar. The data will always have a bit of variation due to randomness but there is same probablility trend that is being followed
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.
# I would say that it;s similar to the similations.