load("kobe.RData")
head(kobe)
## vs game quarter time description
## 1 ORL 1 1 9:47 Kobe Bryant makes 4-foot two point shot
## 2 ORL 1 1 9:07 Kobe Bryant misses jumper
## 3 ORL 1 1 8:11 Kobe Bryant misses 7-foot jumper
## 4 ORL 1 1 7:41 Kobe Bryant makes 16-foot jumper (Derek Fisher assists)
## 5 ORL 1 1 7:03 Kobe Bryant makes driving layup
## 6 ORL 1 1 6:01 Kobe Bryant misses jumper
## basket
## 1 H
## 2 M
## 3 M
## 4 H
## 5 H
## 6 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 of length 1 equals a ‘hit’ then a ‘miss’ (or | HM |, 1 in a row, or a failed chance at a “streak” if streak is defined as two hits in a row). A streak of 0 equals a “miss” (or | M |, 0 in a row, or a failed chance at a “streak”).
kobe_streak <- calc_streak(kobe$basket)
barplot(table(kobe_streak))
##Exercise2: 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? Table below chunk shows that Kobe’s streak lengths were typically 2-3 baskets and that his longest streak length was 4 baskets. Table 1: kobe_streak
table(kobe_streak)
## kobe_streak
## 0 1 2 3 4
## 39 24 6 6 1
##Simulation in R (Coin Flips):
outcomes <- c("heads", "tails")
sim_fair_coin<-sample(outcomes, size =100, replace = TRUE)
sim_fair_coin
## [1] "tails" "heads" "tails" "tails" "tails" "heads" "tails" "tails" "tails"
## [10] "tails" "tails" "heads" "heads" "heads" "heads" "heads" "heads" "tails"
## [19] "heads" "tails" "heads" "tails" "tails" "heads" "tails" "heads" "heads"
## [28] "tails" "tails" "heads" "heads" "heads" "heads" "tails" "tails" "tails"
## [37] "heads" "heads" "tails" "heads" "heads" "heads" "tails" "tails" "heads"
## [46] "heads" "heads" "tails" "heads" "heads" "heads" "heads" "heads" "heads"
## [55] "tails" "tails" "tails" "heads" "heads" "heads" "tails" "heads" "tails"
## [64] "tails" "tails" "heads" "heads" "heads" "tails" "tails" "heads" "heads"
## [73] "tails" "tails" "heads" "heads" "tails" "heads" "tails" "heads" "tails"
## [82] "heads" "heads" "tails" "tails" "tails" "heads" "tails" "tails" "heads"
## [91] "heads" "tails" "heads" "heads" "tails" "heads" "tails" "heads" "heads"
## [100] "tails"
table(sim_fair_coin)
## sim_fair_coin
## heads tails
## 54 46
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
sim_fair_coin
## [1] "tails" "heads" "tails" "tails" "tails" "heads" "tails" "tails" "tails"
## [10] "tails" "tails" "heads" "heads" "heads" "heads" "heads" "heads" "tails"
## [19] "heads" "tails" "heads" "tails" "tails" "heads" "tails" "heads" "heads"
## [28] "tails" "tails" "heads" "heads" "heads" "heads" "tails" "tails" "tails"
## [37] "heads" "heads" "tails" "heads" "heads" "heads" "tails" "tails" "heads"
## [46] "heads" "heads" "tails" "heads" "heads" "heads" "heads" "heads" "heads"
## [55] "tails" "tails" "tails" "heads" "heads" "heads" "tails" "heads" "tails"
## [64] "tails" "tails" "heads" "heads" "heads" "tails" "tails" "heads" "heads"
## [73] "tails" "tails" "heads" "heads" "tails" "heads" "tails" "heads" "tails"
## [82] "heads" "heads" "tails" "tails" "tails" "heads" "tails" "tails" "heads"
## [91] "heads" "tails" "heads" "heads" "tails" "heads" "tails" "heads" "heads"
## [100] "tails"
table(sim_unfair_coin)
## sim_unfair_coin
## heads tails
## 22 78
##Exercise 3: In your simulation of flipping the unfair coin 100 times, how many flips came up heads? In my simulation (chunk above) flipping an “unfair coin,” heads came up 24 times.
##Exercie 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.
A argument called ‘prob’ needs to be added that expresses a 45% (0.45) chance of a H and a 55% (1-0.45) chance of a M [vector weights].
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" "H" "H" "M" "H" "H" "H" "M" "H" "H" "M" "H" "M" "H" "H"
## [19] "M" "H" "H" "M" "M" "M" "H" "H" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M"
## [37] "M" "M" "M" "H" "H" "M" "M" "H" "M" "H" "H" "M" "M" "M" "H" "H" "H" "M"
## [55] "H" "H" "M" "H" "H" "M" "H" "H" "H" "H" "H" "M" "M" "H" "H" "M" "M" "H"
## [73] "M" "H" "H" "H" "M" "M" "M" "M" "M" "M" "M" "M" "H" "H" "H" "M" "M" "H"
## [91] "H" "H" "M" "H" "M" "M" "M" "M" "M" "M" "H" "M" "H" "H" "H" "H" "M" "H"
## [109] "H" "H" "M" "M" "M" "H" "M" "M" "H" "M" "M" "M" "H" "M" "H" "M" "M" "M"
## [127] "M" "H" "M" "M" "M" "M" "M"
kobe$basket
## [1] "H" "M" "M" "H" "H" "M" "M" "M" "M" "H" "H" "H" "M" "H" "H" "M" "M" "H"
## [19] "H" "H" "M" "M" "H" "M" "H" "H" "H" "M" "M" "M" "M" "M" "M" "H" "M" "H"
## [37] "M" "M" "H" "H" "H" "H" "M" "H" "M" "M" "H" "M" "M" "H" "M" "M" "H" "M"
## [55] "H" "H" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M" "M" "H" "M" "M" "M" "M"
## [73] "H" "M" "H" "M" "M" "H" "M" "M" "H" "H" "M" "M" "M" "M" "H" "H" "H" "M"
## [91] "M" "H" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M" "H" "M" "M" "M" "H" "M"
## [109] "H" "H" "H" "M" "H" "H" "H" "M" "H" "M" "H" "M" "M" "M" "M" "M" "M" "H"
## [127] "M" "H" "M" "M" "M" "M" "H"
##1: 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? The typical streak of the simulated independent shooter is 2 “Hits” (mode)in a row or the lowest possible number of consecutive shots for a streak. In 133 shots, the players longest streak was 7 “shots” in a row ( | HHHHHHH |).In the distribution, I would call this streak an “outlier.”
I realize that I may have made an error by naming object streak_sim. When I tried to replace with sim_steak I had some difficulty getting other chunks to run… even when I replaced all objects with correction. What does the orange tag mean?
Streak_sim <-calc_streak(sim_basket)
table(Streak_sim)
## Streak_sim
## 0 1 2 3 4 5
## 40 13 11 6 1 1
barplot(table(Streak_sim))
##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. I would expect the streak to be somehwat similar in that the number of streaks would be around the same. I would not expect an outlier streak of 7 which might mean a few more succesful streaks overall.
##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. These two distributions are extremely similar, I would define kobe/sim_streak_success <- kobe/sim_streak[2-infinity] since 1 == | HM | which I would not consider a streak. Under these parameters, Kobe has 13 streaks in 133 shots and the simulated player has 14 streaks in 133 shots. This is vidence that the hot hand model dose not fit Kobe’s shooting pattern, but rather that any player with his shooting percentage would based on probability have a similar number of streaks.
table(kobe_streak)
## kobe_streak
## 0 1 2 3 4
## 39 24 6 6 1
table(Streak_sim)
## Streak_sim
## 0 1 2 3 4 5
## 40 13 11 6 1 1
success_kobe <- sum(kobe_streak >= 2)
success_sim <- sum(Streak_sim >= 2)
table(success_kobe)
## success_kobe
## 13
## 1
table(success_sim)
## success_sim
## 19
## 1
Wonder why these are not the same?
success_kobe <- sum(kobe_streak >= 2)
success_sim <- sum(Streak_sim >= 2)
table(success_kobe)
## success_kobe
## 13
## 1
table(success_sim)
## success_sim
## 19
## 1
sum(kobe_streak[2:7])
## [1] 5
sum(Streak_sim[2:7])
## [1] 8
sum(kobe_streak[2-7])
## [1] 58
sum(Streak_sim[2-7])
## [1] 59
?sample