#DATA606::startLab('Lab2')
load("/Users/Michele/Lab2/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

Question 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?

I believe, that a streak length of 1 would mean that Kobe made one basket and did not make any before or after that basket. A streak length of 0 would mean that Kobe missed a basket.

kobe_streak <- calc_streak(kobe$basket)
barplot(table(kobe_streak))

Question 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?

His most typical streak was 0, which would be an instance where he missed a basket. His longest streak was 4 baskets in a row.

Question 3

outcomes <- c("heads", "tails")
sim_fair_coin <- sample(outcomes, size = 100, replace = TRUE)
table(sim_fair_coin)
## sim_fair_coin
## heads tails 
##    39    61

In your simulation of flipping the unfair coin 100 times, how many flips came up heads?

sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
table(sim_unfair_coin)
## sim_unfair_coin
## heads tails 
##    19    81

Question 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] "M" "M" "M" "H" "H" "M" "M" "H" "M" "H" "H" "H" "H" "M" "H" "M" "M"
##  [18] "H" "M" "H" "H" "M" "M" "M" "M" "M" "M" "M" "M" "H" "H" "H" "H" "H"
##  [35] "H" "M" "H" "H" "M" "M" "M" "M" "M" "H" "M" "H" "M" "H" "M" "M" "H"
##  [52] "H" "M" "M" "H" "H" "M" "H" "H" "M" "H" "H" "M" "M" "M" "H" "M" "H"
##  [69] "M" "M" "M" "H" "H" "H" "M" "H" "M" "M" "H" "M" "H" "H" "H" "H" "M"
##  [86] "M" "H" "M" "M" "H" "H" "M" "H" "M" "M" "H" "M" "M" "M" "M" "M" "M"
## [103] "M" "M" "H" "M" "M" "H" "H" "M" "H" "M" "H" "M" "M" "H" "M" "M" "H"
## [120] "M" "H" "M" "M" "H" "M" "H" "M" "M" "M" "M" "M" "M" "H"
table(sim_basket)
## sim_basket
##  H  M 
## 57 76
table(kobe$basket)
## 
##  H  M 
## 58 75

On Your Own

Using calc_streak, compute the streak lengths of sim_basket.

simulation_kobe <- calc_streak(sim_basket)
barplot(table(simulation_kobe))

The typical streak length is still at 0, but the longest streak has increased to five as opposed to four.

This would depend on how the simulation is run – sometimes one needs a simulation buffer to ensure it is running properly. However, I would assume it would be similar, because the simulation has a large sample size.

Kobe’s distribution demonstrates that he is very likely to geta basket, but is more likely to get only one streak as opposed to multiple. It appears as though our independent shooter is more likely to get multiple shots in than Kobe is.