load("more/kobe.RData")
#head(kobe)

Excercise:

Q1. 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?

#Streak length of 1 means the time counting from 1st time miss to 2nd time miss. 
#In his 1st streak, he missed one time. 
#Streak length of 0 means the time counting from the beginning to 1st time miss. 

Q2. 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?

kobe_streak <- calc_streak(kobe$basket)
kobe_streak
##  [1] 1 0 2 0 0 0 3 2 0 3 0 1 3 0 0 0 0 0 1 1 0 4 1 0 1 0 1 0 1 2 0 1 2 1 0
## [36] 0 1 0 0 0 1 1 0 1 0 2 0 0 0 3 0 1 0 1 2 1 0 1 0 0 1 3 3 1 1 0 0 0 0 0
## [71] 1 1 0 0 0 1
#Typical streak length
summary(kobe_streak)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  0.0000  0.7632  1.0000  4.0000
#The longest streak of the baskets is 4.

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

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

Q4. 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("hites", "misses")
sim_basket<- sample(outcomes, size = 133, replace = TRUE,prob = c(0.45, 0.55))
table(sim_basket)
## sim_basket
##  hites misses 
##     56     77

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?

outcomes <- c("H", "M")
sim_basket<- sample(outcomes, size = 133, replace = TRUE,prob = c(0.45, 0.55))
sim_basket
##   [1] "M" "H" "H" "M" "M" "H" "H" "H" "M" "H" "M" "H" "M" "M" "M" "M" "M"
##  [18] "H" "H" "H" "H" "H" "M" "M" "M" "M" "M" "M" "M" "H" "M" "M" "M" "H"
##  [35] "H" "M" "M" "H" "H" "M" "M" "M" "H" "H" "H" "H" "M" "M" "M" "H" "H"
##  [52] "H" "H" "M" "M" "M" "H" "M" "M" "H" "M" "H" "M" "M" "H" "H" "H" "M"
##  [69] "M" "M" "M" "M" "M" "M" "M" "M" "H" "M" "M" "M" "M" "H" "H" "H" "H"
##  [86] "H" "H" "M" "H" "M" "H" "H" "M" "M" "H" "M" "M" "H" "M" "M" "H" "M"
## [103] "H" "M" "H" "H" "M" "H" "H" "M" "H" "M" "H" "M" "H" "M" "M" "M" "H"
## [120] "H" "M" "M" "H" "H" "H" "M" "M" "M" "M" "M" "M" "H" "H"
table(sim_basket)
## sim_basket
##  H  M 
## 59 74
a<-calc_streak(sim_basket)
summary(a) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  0.0000  0.7867  1.0000  6.0000
# Max is the longest steak
  • 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.
sim_basket2<- sample(outcomes, size = 133, replace = TRUE,prob = c(0.45, 0.55))
sim_basket2
##   [1] "M" "M" "H" "H" "M" "M" "M" "H" "H" "H" "M" "M" "M" "H" "M" "H" "M"
##  [18] "M" "H" "M" "M" "H" "H" "H" "M" "M" "M" "H" "H" "M" "M" "M" "M" "H"
##  [35] "M" "M" "M" "M" "H" "H" "M" "M" "M" "H" "H" "M" "M" "H" "H" "M" "H"
##  [52] "M" "H" "H" "M" "M" "M" "M" "H" "H" "H" "H" "M" "M" "M" "M" "H" "H"
##  [69] "M" "M" "M" "M" "M" "M" "H" "H" "M" "H" "M" "H" "H" "H" "M" "H" "M"
##  [86] "H" "H" "M" "H" "H" "M" "M" "M" "H" "H" "H" "H" "H" "M" "M" "M" "M"
## [103] "H" "M" "M" "H" "H" "M" "M" "M" "M" "H" "M" "M" "H" "H" "M" "M" "H"
## [120] "H" "M" "M" "M" "H" "M" "M" "H" "H" "H" "H" "H" "H" "M"
table(sim_basket2)
## sim_basket2
##  H  M 
## 60 73
a2<-calc_streak(sim_basket2)
summary(a2)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  0.0000  0.8108  1.7500  6.0000
#The second simulation has totally different outcome. The reason is the computer generat random process while simulated sample again. 
  • 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(calc_streak(sim_basket)))

#Both data sets represent the results of 133 shot attempts,each with the same shooting percentage of 45%.We know that our simulated data is from a shooter that has independent shots. That is, we know the simulated shooter does not have a hot hand.
#The vector `outcomes` can be thought of as a stock price go up and down. ramdom process for stock price also can use flip coin to simulate the stock movement.