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 there is one hit between two misses. 
#Streak length of 0 means there is no hit between two misses. 

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: mean, median, and max are as the following.
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 
##    48    52

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("H", "M")
sim_basket<- sample(outcomes, size = 133, replace = TRUE,prob = c(0.45, 0.55)) # set pr(hit)=0.45, pr(miss)=0.55
table(sim_basket)
## sim_basket
##  H  M 
## 60 73

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?

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

a
##  [1] 0 3 0 0 1 0 1 1 3 0 0 2 0 3 1 2 1 0 1 2 0 0 1 0 2 1 1 0 0 1 1 0 0 0 4
## [36] 0 4 0 1 0 0 4 3 1 2 0 1 0 1 0 0 1 0 1 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0
## [71] 0 0 1 0
#The simulate shoot distribution result is similar to Kobe's since simulation following the same probability to generat the random 
  • 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] "H" "M" "M" "H" "H" "H" "M" "M" "M" "H" "M" "H" "M" "H" "H" "M" "H"
##  [18] "H" "M" "M" "M" "M" "H" "H" "M" "M" "M" "M" "H" "M" "H" "M" "M" "H"
##  [35] "H" "H" "H" "H" "M" "M" "M" "M" "H" "H" "H" "H" "H" "H" "M" "M" "M"
##  [52] "H" "H" "M" "H" "M" "M" "H" "H" "M" "H" "H" "M" "H" "M" "H" "H" "H"
##  [69] "H" "M" "H" "H" "H" "M" "M" "H" "M" "M" "M" "H" "H" "H" "M" "M" "H"
##  [86] "M" "H" "H" "H" "M" "M" "H" "H" "M" "M" "H" "H" "H" "H" "H" "M" "M"
## [103] "H" "M" "H" "M" "M" "M" "H" "M" "H" "H" "M" "M" "M" "H" "M" "M" "M"
## [120] "M" "M" "M" "M" "M" "H" "M" "H" "H" "M" "H" "M" "H" "M"
table(sim_basket2)
## sim_basket2
##  H  M 
## 66 67
a2<-calc_streak(sim_basket2)
summary(a2)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  0.0000  0.9706  1.2500  6.0000
#The second simulation has different from the 1st simulation. 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 have similar distribution for 133 shot attempts with 45% hites rate.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, then Kobe doesn't have 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.