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?
setwd("C:\\Users\\jkuruvilla\\Desktop\\Education\\MS Data Analytics - CUNY\\Lab2")
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"
Answer : A streak of length 1 means, only 1 hit( “H”) and the following one is a miss (“M”). A streak of length 0 means no hit and only one miss.
Exercise 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?
calc1_streak = function(x) {
y <- rep(0, length(x))
y[x == "H"] <- 1
y <- c(0, y, 0)
wz <- which(y == 0)
streak <- diff(wz) - 1
return(streak)
}
kobe_streak <- calc_streak(kobe$basket)
barplot(table(kobe_streak))
IQR(kobe_streak)
## [1] 1
Answer :
Excercise 3 : In your simulation of flipping the unfair coin 100 times, how many flips came up heads?
outcomes <- c("heads", "tails")
ss<-sample(outcomes, size = 100, replace = TRUE, prob=c(.3,.7))
table(ss)
## ss
## heads tails
## 30 70
Answer : Number of flips came up as heads is as above.
Excercise 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" "H" "M" "M" "H" "H" "M" "H" "H" "M" "H" "H" "M" "M" "H" "M"
## [18] "H" "H" "H" "H" "M" "M" "H" "H" "M" "H" "M" "H" "M" "M" "M" "H" "M"
## [35] "M" "M" "H" "H" "M" "H" "M" "M" "H" "H" "M" "H" "M" "H" "M" "H" "M"
## [52] "M" "M" "M" "M" "H" "H" "M" "M" "M" "H" "M" "M" "M" "H" "H" "H" "H"
## [69] "M" "H" "M" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M" "M" "M" "H" "H"
## [86] "M" "H" "M" "H" "H" "M" "H" "H" "M" "H" "H" "H" "M" "H" "M" "M" "M"
## [103] "H" "H" "M" "M" "M" "M" "M" "M" "M" "M" "H" "H" "H" "H" "H" "M" "M"
## [120] "M" "H" "H" "H" "H" "H" "M" "H" "M" "M" "M" "M" "H" "M"
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"
kobe_sim_streak<-calc1_streak(sim_basket)
barplot(table(kobe_sim_streak))
table(kobe_sim_streak)
## kobe_sim_streak
## 0 1 2 3 4 5
## 38 17 12 1 2 2
IQR(kobe_sim_streak)
## [1] 1
Answer :
Answer : Somewhat similar. In case of Kobe, the assumption is P(shot 1 = H)=0.45. Not many shooters can claim this kind of a high probability. So an average shooter would probably will miss more than Kobe. So there will even more zero streak length in case of an independent shooter.
Answer : In both case the typical streak length measured by meadian which is 0. In both case the streak length is right scewed. In case of the simulated data, the longest streak of basket is 7 where as the longest streak in the real data is only 4.