Probability

Getting Started

Our 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. Let’s load some data from those games and look at the first several rows.

download.file("http://www.openintro.org/stat/data/kobe.RData", destfile = "kobe.RData")
load("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"

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: The length of a shooting streak is the number of consecutive baskets made until a miss occurs. A streak of 1 is that 1 hit was folowed by a miss. In a streak of 0 it means that a miss was made with no hits before.

The custom function calc_streak, which was loaded in with the data, may be used to calculate the lengths of all shooting streaks and then look at the distribution.

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?

Answer: His typical streak length was of 0 baskets and his longest streak length was of 4 baskets before missing on the fifth shot.

Simulations in R

While we don’t have any data from a shooter we know to have independent shots, that sort of data is very easy to simulate in R. In a simulation, you set the ground rules of a random process and then the computer uses random numbers to generate an outcome that adheres to those rules. As a simple example, you can simulate flipping a fair coin with the following.

outcomes <- c("heads", "tails")
sample(outcomes, size = 1, replace = TRUE)
## [1] "tails"

If you wanted to simulate flipping a fair coin 100 times, you could either run the function 100 times or, more simply, adjust the size argument, which governs how many samples to draw (the replace = TRUE argument indicates we put the slip of paper back in the hat before drawing again). Save the resulting vector of heads and tails in a new object called sim_fair_coin.

sim_fair_coin <- sample(outcomes, size = 100, replace = TRUE)

To view the results of this simulation, type the name of the object and then use table to count up the number of heads and tails.

sim_fair_coin
##   [1] "heads" "heads" "tails" "tails" "heads" "tails" "tails" "tails"
##   [9] "tails" "tails" "tails" "tails" "tails" "heads" "tails" "tails"
##  [17] "tails" "tails" "tails" "heads" "heads" "tails" "tails" "heads"
##  [25] "tails" "tails" "tails" "heads" "heads" "tails" "heads" "tails"
##  [33] "heads" "tails" "heads" "tails" "tails" "heads" "tails" "heads"
##  [41] "tails" "tails" "tails" "tails" "tails" "heads" "tails" "heads"
##  [49] "tails" "tails" "heads" "tails" "heads" "heads" "heads" "heads"
##  [57] "heads" "heads" "tails" "tails" "tails" "tails" "heads" "tails"
##  [65] "heads" "heads" "heads" "heads" "heads" "tails" "heads" "heads"
##  [73] "tails" "tails" "heads" "tails" "tails" "heads" "heads" "tails"
##  [81] "tails" "heads" "tails" "tails" "heads" "tails" "heads" "tails"
##  [89] "tails" "heads" "heads" "heads" "tails" "heads" "heads" "heads"
##  [97] "heads" "tails" "tails" "tails"
table(sim_fair_coin)
## sim_fair_coin
## heads tails 
##    44    56

Say we’re trying to simulate an unfair coin that we know only lands heads 20% of the time. We can adjust for this by adding an argument called prob, which provides a vector of two probability weights.

sim_unfair_coin <- sample(outcomes, size = 100, replace = TRUE, prob = c(0.2, 0.8))
table(sim_unfair_coin)
## sim_unfair_coin
## heads tails 
##    15    85

prob=c(0.2, 0.8) indicates that for the two elements in the outcomes vector, we want to select the first one, heads, with probability 0.2 and the second one, tails with probability 0.8. Another way of thinking about this is to think of the outcome space as a bag of 10 chips, where 2 chips are labeled “head” and 8 chips “tail”. Therefore at each draw, the probability of drawing a chip that says “head”" is 20%, and “tail” is 80%.

Exercise 3:

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

Answer: 18 flips came up heads.

If you want to learn more about sample or any other function, recall that you can always check out its help file.

?sample

Simulating the Independent Shooter

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

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

To make a valid comparison between Kobe and our simulated independent shooter, we need to align both their shooting percentage and the number of attempted shots.

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.

Answer:

sim_basket <- sample(outcomes, size = 133, replace = TRUE, prob =c(0.45, 0.55))
sim_basket
##   [1] "M" "H" "M" "H" "H" "H" "M" "M" "M" "M" "H" "H" "H" "M" "M" "M" "M"
##  [18] "H" "M" "H" "H" "H" "M" "M" "H" "H" "M" "M" "H" "M" "M" "H" "H" "M"
##  [35] "M" "M" "M" "M" "H" "H" "M" "H" "M" "H" "M" "M" "M" "M" "M" "M" "H"
##  [52] "M" "M" "M" "M" "M" "H" "M" "H" "M" "H" "M" "M" "H" "M" "M" "H" "M"
##  [69] "H" "M" "M" "H" "M" "H" "H" "M" "M" "M" "H" "M" "M" "M" "H" "M" "H"
##  [86] "H" "H" "M" "M" "M" "M" "H" "H" "M" "M" "M" "M" "M" "M" "M" "H" "H"
## [103] "M" "M" "M" "H" "M" "M" "H" "H" "M" "H" "H" "M" "M" "H" "M" "M" "M"
## [120] "H" "H" "M" "H" "M" "H" "H" "H" "M" "H" "M" "H" "H" "H"

With the results of the simulation saved as sim_basket, we have the data necessary to compare Kobe to our independent shooter. We can look at Kobe’s data alongside our simulated data.

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"
sim_basket
##   [1] "M" "H" "M" "H" "H" "H" "M" "M" "M" "M" "H" "H" "H" "M" "M" "M" "M"
##  [18] "H" "M" "H" "H" "H" "M" "M" "H" "H" "M" "M" "H" "M" "M" "H" "H" "M"
##  [35] "M" "M" "M" "M" "H" "H" "M" "H" "M" "H" "M" "M" "M" "M" "M" "M" "H"
##  [52] "M" "M" "M" "M" "M" "H" "M" "H" "M" "H" "M" "M" "H" "M" "M" "H" "M"
##  [69] "H" "M" "M" "H" "M" "H" "H" "M" "M" "M" "H" "M" "M" "M" "H" "M" "H"
##  [86] "H" "H" "M" "M" "M" "M" "H" "H" "M" "M" "M" "M" "M" "M" "M" "H" "H"
## [103] "M" "M" "M" "H" "M" "M" "H" "H" "M" "H" "H" "M" "M" "H" "M" "M" "M"
## [120] "H" "H" "M" "H" "M" "H" "H" "H" "M" "H" "M" "H" "H" "H"

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.

table(kobe$basket)
## 
##  H  M 
## 58 75
table(sim_basket)
## sim_basket
##  H  M 
## 55 78

On your own

Comparing Kobe Bryant to the Independent Shooter

Using calc_streak, compute the streak lengths of sim_basket.

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

  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?

Answer: The typical streak length for the simulated independent shooter with a 45% shooting percentage is 0 baskets. The longest streak length is 6 baskets.

  1. 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: The second simulation would be somewhat similar because the sample size is 133 and the law of large numbers states that the simulations will be close to the expected value of 45% / 55% ratio but each simulation will not be exactly the same.

  1. 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: Looking at Kobe Bryant and our simulated shooter´s distribution tables and their respective bar plots, we can see that they both very similar. In this comparison we can argue that Kobe Bryant´s distribution is the same of an independent shooter and proves wrong the hot hand model assumption.