load("more/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"
Streak length of 1 meas that the player made one basket. Streak one has 1 basket and no misses.Streak 0 means player missed the basket.
kobe_streak <- calc_streak(kobe$basket)
table(kobe_streak)
## kobe_streak
## 0 1 2 3 4
## 39 24 6 6 1
barplot(table(kobe_streak))
mean(kobe_streak)
## [1] 0.7631579
table(kobe_streak)
## kobe_streak
## 0 1 2 3 4
## 39 24 6 6 1
mean(kobe_streak)
## [1] 0.7631579
Most of his streak was of length 0 or 1. Occaccionaly he had a streak of 2 and 3. He also had one streak of 4. He Longest streak is 4. Mean is 0.76. Typical streak lenght is “1”
outcomes <- c("heads", "tails")
sample(outcomes, size = 1, replace = TRUE)
## [1] "tails"
sim_fair_coin <- sample(outcomes, size = 100, replace = TRUE)
To view the results of this simulation, type the name of the object and then use table
to count up the number of heads and tails.
table(sim_fair_coin)
## sim_fair_coin
## heads tails
## 47 53
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
81, 80, 77 heads and 19,20, 23 tails. Heads will be about 80% of the time and 20% tails. If we run the simulation longer(like 100,000) then the numbers will get closer.
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
table(sim_unfair_coin)
## sim_unfair_coin
## heads tails
## 15 85
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
table(sim_unfair_coin)
## sim_unfair_coin
## heads tails
## 17 83
outcomes <- c("H", "M")
sim_basket <- sample(outcomes, size = 1, replace = TRUE)
To make a valid comparison between Kobe and our simulated independent shooter, we need to align both their shooting percentage and the number of attempted shots.
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, c(0.45, 0.55))
table(sim_basket)
## sim_basket
## H M
## 53 80
#kobe
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"
#Simulated shooter
sim_basket
## [1] "M" "M" "H" "H" "M" "H" "M" "M" "M" "H" "M" "H" "M" "M" "M" "M" "H"
## [18] "H" "M" "M" "M" "H" "M" "H" "H" "M" "M" "M" "M" "H" "M" "H" "M" "M"
## [35] "M" "H" "M" "H" "H" "M" "H" "M" "H" "H" "H" "H" "H" "H" "M" "H" "M"
## [52] "M" "M" "H" "H" "M" "H" "H" "M" "M" "H" "M" "H" "M" "M" "M" "H" "M"
## [69] "M" "H" "M" "M" "H" "M" "M" "H" "M" "H" "M" "M" "M" "M" "H" "M" "M"
## [86] "M" "M" "H" "M" "M" "M" "H" "M" "H" "H" "M" "M" "H" "M" "H" "M" "M"
## [103] "H" "M" "M" "M" "H" "H" "M" "M" "H" "M" "M" "M" "H" "M" "M" "M" "H"
## [120] "M" "M" "H" "H" "H" "M" "M" "H" "M" "M" "M" "H" "H" "M"
table(kobe$basket)
##
## H M
## 58 75
table(sim_basket)
## sim_basket
## H M
## 53 80
Using calc_streak
, compute the streak lengths of sim_basket
.
Streak is very similar to that of Kobe’s. Mostly had a streak of length 1 or 0. Occasional streak length of greater than 2 and one or two outliers. I have seen streak length of 6, this changes every time I run the r mark down.
sim_basket_streak <- calc_streak(sim_basket)
table(sim_basket_streak)
## sim_basket_streak
## 0 1 2 3 6
## 44 26 9 1 1
mean(sim_basket_streak)
## [1] 0.654321
barplot(table(sim_basket_streak))
The streak distribution is similar with different streak lengths and frequency. Simulated player’s shooting percent is 45% so it will vary a bit each time we run the simulation. If we run the simulation longer(greater number of shots) it will be very similar each time we run it.
Simulated players streak length is very similar to that of Kobe’s. Based on this, we could see that hot hand model doesnt fit kobe’s or simulated players shooting pattern. Each shot is indepenent of other shots so any player with similar shooting percentage will have similar pattern as Kobe. I play basketball at times, I could say that at times the shots will just go in and I attribute this to some sort of muscle memmory or something else.