load(url("http://www.openintro.org/stat/data/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 mean means 1 Hit then 1 Miss. A streak length of 0 is 1 miss.
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?
summary(kobe_streak)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.0000 0.0000 0.7632 1.0000 4.0000
Right skewed distribtuion. His longest streaks are of 4. The average streak(mean) are 0.7632.
outcomes <- c("heads", "tails")
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
sim_unfair_coin
## [1] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
## [9] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
## [17] "heads" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
## [25] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
## [33] "tails" "tails" "heads" "tails" "tails" "heads" "tails" "tails"
## [41] "heads" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
## [49] "tails" "heads" "tails" "tails" "tails" "tails" "tails" "tails"
## [57] "tails" "tails" "heads" "tails" "heads" "heads" "tails" "tails"
## [65] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
## [73] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
## [81] "tails" "tails" "tails" "tails" "tails" "heads" "heads" "tails"
## [89] "heads" "tails" "tails" "tails" "heads" "tails" "tails" "tails"
## [97] "tails" "tails" "tails" "tails"
table(sim_unfair_coin)
## sim_unfair_coin
## heads tails
## 14 86
Exercise 3. In your simulation of flipping the unfair coin 100 times, how many flips came up heads? 19 heads
Exercise 4. What change needs to be made to the sample function so that it reflects a shooting percentage of 45%? Make this adjustment, then run a simulation to sample 133 shots. Assign the output of this simulation to a new object called sim_basket.
outcomes <- c("H", "M")
sim_basket<- sample(outcomes, size= 133, replace=TRUE, prob=c(0.45, 0.55))
sim_basket
## [1] "H" "M" "M" "M" "M" "M" "M" "M" "M" "M" "M" "M" "M" "H" "M" "M" "H"
## [18] "M" "H" "M" "M" "M" "M" "M" "M" "M" "M" "H" "M" "M" "H" "M" "M" "M"
## [35] "M" "H" "M" "M" "H" "H" "M" "M" "M" "H" "H" "M" "H" "M" "H" "H" "M"
## [52] "M" "M" "H" "M" "H" "H" "M" "M" "M" "H" "H" "H" "H" "H" "M" "H" "M"
## [69] "H" "M" "M" "H" "M" "H" "M" "M" "M" "M" "M" "H" "H" "M" "M" "H" "H"
## [86] "M" "H" "M" "M" "M" "M" "H" "H" "H" "M" "M" "H" "M" "H" "M" "M" "M"
## [103] "M" "M" "M" "M" "M" "M" "H" "M" "M" "M" "M" "H" "H" "M" "M" "M" "M"
## [120] "H" "H" "M" "H" "M" "M" "H" "M" "M" "H" "H" "H" "M" "M"
table(sim_basket)
## sim_basket
## H M
## 46 87
On your own
Comparing Kobe Bryant to the Independent Shooter
Using calc_streak, compute the streak lengths of sim_basket.
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?
streak_133<-calc_streak(sim_basket)
summary(streak_133)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.0000 0.0000 0.5227 1.0000 5.0000
barplot(table(streak_133))
barplot
## function (height, ...)
## UseMethod("barplot")
## <bytecode: 0x000000000ba39e80>
## <environment: namespace:graphics>
Right skewed distribution. There is a highest streak of 4 and the lowest of 0.
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. Somewhat similar but there will be some variation between the first time and second time.
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.
Kobe Bryant’s distribution of streak lengths fit more to the simulated shooter. His shooting patterns will not match the hot hand model, because I changed the chance of occurance to 60%. And the barplot does not match Kobe Bryant’s shooting pattern. If Kobe Bryant’s shooting pattern matches the hot hand model, he would have more streaks of long length.
sim_basket2<- sample(outcomes, size= 133, replace=TRUE, prob=c(0.60, 0.40))
hot_hand<-calc_streak(sim_basket2)
table(hot_hand)
## hot_hand
## 0 1 2 3 4 5 6 12
## 23 16 10 2 3 1 1 1
barplot(table(hot_hand), main="Hot Hand", xlab="Streaks", ylab="Numbers")
barplot(table(streak_133), main="Sim Shooter", xlab="Streaks", ylab="Numbers")
barplot(table(kobe_streak), main="Kobe", xlab="Streaks", ylab="Numbers")