Lab 3: Probability

download.file("http://www.openintro.org/stat/data/kobe.RData", destfile = "kobe.RData")
load("kobe.RData")
head(kobe)
##    vs game quarter time                                             description
## 1 ORL    1       1 9:47                 Kobe Bryant makes 4-foot two point shot
## 2 ORL    1       1 9:07                               Kobe Bryant misses jumper
## 3 ORL    1       1 8:11                        Kobe Bryant misses 7-foot jumper
## 4 ORL    1       1 7:41 Kobe Bryant makes 16-foot jumper (Derek Fisher assists)
## 5 ORL    1       1 7:03                         Kobe Bryant makes driving layup
## 6 ORL    1       1 6:01                               Kobe Bryant misses jumper
##   basket
## 1      H
## 2      M
## 3      M
## 4      H
## 5      H
## 6      M
kobe$basket[1:9]
## [1] "H" "M" "M" "H" "H" "M" "M" "M" "M"

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?

A streak is counted after the first hit is made, other wise it is a zero. In a streak of one there is one hit and one miss. A streak of zero is only a miss.

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

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?

Technically his typical streak length was 0 but if you are counting actual streaks it is a streak of 1 as it happend over 20 times. His longest streak was 4 hits. For the most part Kobe did not have many streaks greater than 1.

outcomes <- c("heads", "tails")
sample(outcomes, size = 1, replace = TRUE)
## [1] "heads"
sim_fair_coin <- sample(outcomes, size = 100, replace = TRUE)
sim_fair_coin
##   [1] "tails" "tails" "tails" "heads" "tails" "heads" "heads" "tails" "tails"
##  [10] "heads" "tails" "tails" "tails" "heads" "heads" "tails" "tails" "heads"
##  [19] "tails" "tails" "heads" "tails" "heads" "tails" "heads" "heads" "tails"
##  [28] "heads" "tails" "tails" "tails" "heads" "heads" "tails" "heads" "tails"
##  [37] "heads" "tails" "tails" "heads" "tails" "tails" "tails" "tails" "heads"
##  [46] "heads" "heads" "tails" "heads" "heads" "heads" "tails" "tails" "tails"
##  [55] "heads" "tails" "tails" "heads" "tails" "tails" "tails" "heads" "heads"
##  [64] "tails" "tails" "tails" "heads" "heads" "tails" "tails" "heads" "heads"
##  [73] "tails" "tails" "heads" "tails" "heads" "heads" "heads" "heads" "tails"
##  [82] "tails" "heads" "tails" "tails" "tails" "tails" "heads" "heads" "tails"
##  [91] "tails" "tails" "tails" "heads" "tails" "tails" "tails" "heads" "heads"
## [100] "tails"
table(sim_fair_coin)
## sim_fair_coin
## heads tails 
##    42    58
sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
sim_unfair_coin
##   [1] "tails" "tails" "heads" "heads" "tails" "tails" "heads" "tails" "tails"
##  [10] "tails" "heads" "tails" "heads" "tails" "tails" "tails" "tails" "heads"
##  [19] "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails" "tails"
##  [28] "heads" "heads" "tails" "tails" "heads" "tails" "tails" "tails" "heads"
##  [37] "tails" "tails" "heads" "tails" "tails" "heads" "heads" "tails" "tails"
##  [46] "tails" "tails" "tails" "tails" "tails" "heads" "heads" "heads" "tails"
##  [55] "tails" "tails" "tails" "tails" "tails" "tails" "heads" "heads" "tails"
##  [64] "tails" "heads" "heads" "tails" "tails" "tails" "tails" "tails" "heads"
##  [73] "tails" "tails" "tails" "heads" "heads" "tails" "tails" "tails" "tails"
##  [82] "heads" "tails" "tails" "tails" "heads" "heads" "heads" "tails" "tails"
##  [91] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
## [100] "heads"
table(sim_unfair_coin)
## sim_unfair_coin
## heads tails 
##    29    71

###Exercise 3

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

Heads 19 times and tails 81 times.

outcomes <- c("H", "M")
sim_basket <- sample(outcomes, size = 1, replace = TRUE)

Exercise 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))
kobe$basket
##   [1] "H" "M" "M" "H" "H" "M" "M" "M" "M" "H" "H" "H" "M" "H" "H" "M" "M" "H"
##  [19] "H" "H" "M" "M" "H" "M" "H" "H" "H" "M" "M" "M" "M" "M" "M" "H" "M" "H"
##  [37] "M" "M" "H" "H" "H" "H" "M" "H" "M" "M" "H" "M" "M" "H" "M" "M" "H" "M"
##  [55] "H" "H" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M" "M" "H" "M" "M" "M" "M"
##  [73] "H" "M" "H" "M" "M" "H" "M" "M" "H" "H" "M" "M" "M" "M" "H" "H" "H" "M"
##  [91] "M" "H" "M" "M" "H" "M" "H" "H" "M" "H" "M" "M" "H" "M" "M" "M" "H" "M"
## [109] "H" "H" "H" "M" "H" "H" "H" "M" "H" "M" "H" "M" "M" "M" "M" "M" "M" "H"
## [127] "M" "H" "M" "M" "M" "M" "H"
sim_basket
##   [1] "H" "H" "H" "M" "M" "M" "H" "H" "H" "M" "H" "H" "M" "M" "M" "H" "M" "H"
##  [19] "M" "M" "H" "M" "M" "M" "H" "M" "H" "M" "H" "H" "M" "M" "H" "H" "M" "M"
##  [37] "M" "M" "M" "H" "M" "H" "H" "H" "M" "M" "M" "M" "H" "M" "M" "H" "M" "M"
##  [55] "H" "H" "M" "M" "M" "M" "H" "M" "M" "M" "M" "M" "H" "M" "H" "H" "M" "M"
##  [73] "H" "H" "M" "M" "H" "H" "M" "M" "H" "M" "M" "H" "M" "H" "M" "M" "M" "H"
##  [91] "M" "M" "H" "H" "H" "H" "H" "M" "H" "H" "H" "H" "M" "M" "M" "M" "M" "H"
## [109] "H" "M" "M" "H" "M" "H" "M" "M" "H" "M" "M" "H" "H" "H" "M" "M" "H" "H"
## [127] "H" "M" "H" "M" "H" "M" "M"

On your Own

Number 1

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?

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

summary(sim_streak) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.0000  0.0000  0.0000  0.7867  1.0000  5.0000

The typical streak length is 0. The longest streak length is 5.

Number 2

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.

I would expect it to be somewhat similar because it would be under the same conditions so we would always expect, in the long run, for the simulation to make 45% of its shots. While the longest streak may go up or down a bit, generally they will be very similar.

Number 3

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(kobe_streak))

barplot(table(sim_streak))

Kobe Bryant’s distribution of streak lengths is actually very silimar. Our simulation was lucky and has some long streak lengths, the shape of the graphs were very similar. Being right skewed. Since they are very similar, the hot hand model does not fit Kobe’s shooting patterns