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"
kobe_streak2009 <- calc_streak(kobe$basket)
barplot(table(kobe_streak2009))
outcomes <- c("heads", "tails")
sample(outcomes, size = 1, replace = TRUE)
## [1] "heads"
sim_unfair_flip <- sample(outcomes,size=100,replace = TRUE)
sim_unfair_flip
## [1] "heads" "tails" "tails" "heads" "tails" "heads" "tails" "tails"
## [9] "tails" "tails" "tails" "heads" "heads" "tails" "heads" "heads"
## [17] "tails" "heads" "heads" "tails" "heads" "heads" "tails" "tails"
## [25] "tails" "tails" "tails" "tails" "heads" "heads" "tails" "heads"
## [33] "tails" "heads" "tails" "heads" "heads" "tails" "heads" "heads"
## [41] "tails" "tails" "heads" "tails" "heads" "tails" "tails" "heads"
## [49] "heads" "tails" "heads" "tails" "heads" "tails" "heads" "tails"
## [57] "heads" "tails" "tails" "tails" "tails" "heads" "tails" "heads"
## [65] "tails" "tails" "tails" "tails" "heads" "tails" "heads" "tails"
## [73] "heads" "tails" "tails" "tails" "heads" "heads" "heads" "tails"
## [81] "tails" "heads" "tails" "heads" "heads" "tails" "heads" "heads"
## [89] "tails" "heads" "heads" "tails" "tails" "tails" "heads" "tails"
## [97] "tails" "tails" "tails" "tails"
table(sim_unfair_flip)
## sim_unfair_flip
## heads tails
## 43 57
outcomes <- c("H", "M")
sim_basket <- sample(outcomes,size=133,replace = TRUE,prob = c(0.45,0.55))
sim_basket
## [1] "M" "H" "M" "M" "H" "M" "H" "H" "H" "M" "H" "M" "M" "H" "M" "H" "M"
## [18] "M" "M" "H" "H" "H" "M" "M" "H" "M" "H" "M" "M" "H" "M" "H" "M" "M"
## [35] "M" "H" "H" "H" "M" "M" "H" "M" "H" "M" "M" "H" "M" "H" "H" "M" "M"
## [52] "H" "M" "H" "M" "H" "M" "H" "H" "M" "M" "H" "M" "M" "M" "H" "H" "M"
## [69] "H" "M" "H" "H" "M" "M" "M" "M" "M" "H" "H" "M" "H" "M" "H" "H" "M"
## [86] "M" "M" "H" "M" "H" "H" "M" "M" "M" "M" "M" "M" "M" "H" "M" "M" "H"
## [103] "M" "H" "H" "H" "M" "H" "M" "M" "H" "M" "H" "M" "H" "H" "M" "M" "H"
## [120] "H" "M" "M" "M" "H" "H" "M" "M" "H" "M" "M" "H" "H" "M"
table(sim_basket)
## sim_basket
## H M
## 59 74
sim_shooter_Independant <- calc_streak(sim_basket)
sim_shooter_Independant
## [1] 0 1 0 1 3 1 0 1 1 0 0 3 0 1 1 0 1 1 0 0 3 0 1 1 0 1 2 0 1 1 1 2 0 1 0
## [36] 0 2 1 2 0 0 0 0 2 1 2 0 0 1 2 0 0 0 0 0 0 1 0 1 3 1 0 1 1 2 0 2 0 0 2
## [71] 0 1 0 2 0
barplot(table(sim_shooter_Independant))
#2, 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: It’s somewhat similar since the distribution is a unimodule distribution and skewing towards left. #3, 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.
barplot(table(kobe_streak2009))
barplot(table(sim_shooter_Independant))
#Answer: