Lab 3 Probability

Author

Rachel Saidi

Published

September 13, 2020

Probability

Hot Hands

Data

Your investigation will focus on the performance of one player: Kobe Bryant of the Los Angeles Lakers. His performance against the Orlando Magic in the 2009 NBA Finals earned him the title Most Valuable Player and many spectators commented on how he appeared to show a hot hand. The data file we’ll use is called kobe_basket.

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.3     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.3     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(openintro)
Loading required package: airports
Loading required package: cherryblossom
Loading required package: usdata

To verify this use the following command:

str(kobe_basket)
tibble [133 × 6] (S3: tbl_df/tbl/data.frame)
 $ vs         : Factor w/ 1 level "ORL": 1 1 1 1 1 1 1 1 1 1 ...
 $ game       : int [1:133] 1 1 1 1 1 1 1 1 1 1 ...
 $ quarter    : Factor w/ 5 levels "1","1OT","2",..: 1 1 1 1 1 1 1 1 1 3 ...
 $ time       : Factor w/ 116 levels "00:00.0","00:00.5",..: 114 109 102 100 96 85 64 21 11 91 ...
 $ description: Factor w/ 80 levels "Bryant 3pt Shot: Made (16 PTS) Assist: Bynum (1 AST)  ",..: 40 78 75 27 44 78 52 62 79 45 ...
 $ shot       : chr [1:133] "H" "M" "M" "H" ...

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?

Answer: A streak length of 1 means hit then miss, then hit the miss, etc. A streak length of 0 means miss then miss then miss then miss, etc.

kobe_streak <- calc_streak(kobe_basket$shot)
ggplot(data = kobe_streak, aes(x = length)) +
  geom_bar(fill = "lightblue")

table(kobe_streak)
length
 0  1  2  3  4 
39 24  6  6  1 

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?

Answer: His biggest streaks were 0’s or 1’s.

Simulations in R

[1] "heads"
sim_fair_coin <- sample(coin_outcomes, size = 100, replace = TRUE)
sim_fair_coin
  [1] "heads" "heads" "heads" "tails" "tails" "tails" "heads" "heads" "heads"
 [10] "heads" "heads" "tails" "heads" "tails" "tails" "tails" "heads" "tails"
 [19] "tails" "tails" "heads" "tails" "heads" "heads" "tails" "heads" "tails"
 [28] "heads" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails"
 [37] "tails" "tails" "tails" "heads" "heads" "tails" "heads" "heads" "tails"
 [46] "tails" "heads" "tails" "tails" "tails" "heads" "tails" "heads" "heads"
 [55] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "heads" "heads"
 [64] "tails" "tails" "heads" "heads" "heads" "tails" "heads" "tails" "heads"
 [73] "heads" "tails" "tails" "tails" "tails" "heads" "heads" "heads" "heads"
 [82] "heads" "tails" "tails" "tails" "tails" "heads" "heads" "tails" "tails"
 [91] "heads" "tails" "tails" "heads" "heads" "tails" "heads" "tails" "heads"
[100] "tails"
table(sim_fair_coin)
sim_fair_coin
heads tails 
   44    56 
set.seed(35797) 
sim_unfair_coin <- sample(coin_outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
sim_unfair_coin
  [1] "tails" "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails"
 [10] "tails" "tails" "heads" "heads" "tails" "heads" "heads" "heads" "tails"
 [19] "tails" "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails"
 [28] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
 [37] "tails" "tails" "tails" "tails" "tails" "tails" "tails" "tails" "heads"
 [46] "heads" "tails" "tails" "tails" "heads" "heads" "tails" "tails" "heads"
 [55] "heads" "tails" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
 [64] "heads" "tails" "tails" "heads" "tails" "tails" "tails" "tails" "heads"
 [73] "heads" "tails" "tails" "tails" "tails" "tails" "heads" "heads" "tails"
 [82] "heads" "tails" "tails" "heads" "tails" "tails" "tails" "tails" "tails"
 [91] "tails" "heads" "heads" "tails" "tails" "tails" "heads" "tails" "tails"
[100] "tails"
table(sim_unfair_coin)
sim_unfair_coin
heads tails 
   26    74 

Exercise 3

** A note on setting a seed: Setting a seed will cause R to select the same sample each time you knit your document. This will make sure your results don’t change each time you knit, and it will also ensure reproducibility of your work (by setting the same seed it will be possible to reproduce your results). You can set a seed like this:

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

Answer: 26

Simulating the Independent Shooter

Simulating a basketball player who has independent shots uses the same mechanism that you used to simulate a coin flip. To simulate a single shot from an independent shooter with a shooting percentage of 50% you can type.

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

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.

set.seed(35797)
coin_outcomes2 <- c("H", "M")
sim_basket2 <- sample(coin_outcomes2, size = 133, replace = TRUE, prob = c(0.45, 0.55))

Answer: This simulation reflecting a shooting percentage of 45% gave 36/133 hits

kobetable <- table(kobe_streak$basket)
kobetable
< table of extent 0 >
simbasket2Table <-table(sim_basket2)
simbasket2Table 
sim_basket2
 H  M 
63 70 
prop.table(simbasket2Table)
sim_basket2
        H         M 
0.4736842 0.5263158 

Answer : It seems that Kobe’s results are similar to the simulated shooter without the hot hand.

More Practice

Comparing Kobe Bryant to the Independent Shooter

Exercise 5

Using calc_streak, compute the streak lengths of sim_basket, and save the results in a data frame called sim_streak.

sim_streak<-calc_streak(sim_basket2)

Exercise 6

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? Make sure to include a plot in your answer.

ggplot(data = sim_streak, aes(x = length)) +
  geom_bar(fill = "lightblue")

table(sim_streak)
length
 0  1  2  3  4  5  6 
40 14  9  4  2  1  1 

Answer: The typical streak length is 0. The longest streak of baskets was 6, but that was only 1 time

Exercise 7

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.

Answer: I would expect the distribution to be somewhat similar rather than identical. The number of misses will always be higher than the number of hits due to the shooting percentage being below 50%. The probability of making successive shots or hits will always be very low in relation to the probability of missing a single shot (e.g. P(streak of 2) = P(.45 and .45) = .2025 < P(streak of 1) = P(.45 and .55) = .2475 < P(streak of 0) = .55). In other words, the longer the streak, the lower the probability or frequency of occurences. Thus, the shape will essentially always be the same. What will vary is basically the extremity of outliers as a function of the fact that this is a random simulation. Another simulation might yield outliers of just 4 and 15, for example.

Exercise 8

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.

Answer: The distribution of streaks for the simulated independent shooter are similar to that of Kobe. If we were to run it multiple times, we will likely find similar results each time. Just like the distribution of Kobe’s streak lengths, the distribution of the simulated shooter’s streak lengths is highly skewed to the right and the majority of streaks are clumped between 0 and 1. Therefore, the hot-hands theory seems to be false.

The question of whether shots are dependent of one another still seems to be difficult to confirm. The real question then seems to be: are the streaks of hits merely the effect of random, independent shots or do they demonstrate that shots are dependent upon prior shots?