Lab 07 – Basketball and Hot Hands

Instructions

Obtain the GitHub repository you will use to complete the lab, which contains a starter file named lab07.Rmd. This lab shows you how we can use randomized simulations to gain insight into whether or not basketball players can have a “hot hand”. Carefully read the lab instructions and complete the exercises using the provided spaces within your starter file lab07.Rmd. Then, when you’re ready to submit, follow the directions in the How to submit section below.

The Hot Hand

Basketball players who make several baskets in succession are described as having a hot hand. Fans and players have long believed in the hot hand phenomenon, which refutes the assumption that each shot is independent of the next. However, a 1985 paper by Gilovich, Vallone, and Tversky collected evidence that contradicted this belief and showed that successive shots are independent events. This paper started a great controversy that continues to this day, as you can see by Googling hot hand basketball.

We do not expect to resolve this controversy today. However, we’ll apply one approach to answering questions like this, which will allow us to (1) think about the effects of independent and dependent events, (2) learn how to simulate shooting streaks in R, and (3) to compare a simulation to actual data in order to determine if the hot hand phenomenon appears to be real.

About the dataset

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. Accordingly, our dataset is taken from the five games the Los Angeles Lakers played against the Orlando Magic in the 2009 NBA finals.

The table below provides descriptions of the dataset’s 6 variables,

Variable Description
vs ORL if the Los Angeles Lakers played against Orlando
game game in the 2009 NBA finals
quarter quarter in the game, OT stands for overtime
time time of game in seconds at which Kobe took a shot
description description of the shot
shot H if the shot was a hit, M if the shot was a miss

Defining a shooting streak

If you inspect the shot column, you’ll quickly find that inspecting a string of H’s and M’s by eye makes it be difficult to gauge whether or not it seems like Kobe was shooting with a hot hand. To make any progress we will need to define what we mean when we say a player has a hot hand. For the purposes of our investigation, we will base our hot hand definition on the belief that hot hand shooters tend to go on shooting streaks, where the length of a shooting streak is defined as the number of consecutive baskets a player makes until a miss occurs.

For example, in Game 1 Kobe Bryant had the following sequence of hits and misses from his nine shot attempts in the first quarter:

H M | M | H H M | M | M | M

You can verify this by viewing the first 8 rows of the dataset using View(). Within these nine shot attempts there are six streaks, which are separated by a | above. The lengths of each streak are one, zero, two, zero, zero, zero (in order of occurrence).

  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?

Counting streak lengths manually for all 133 of Kobe’s shots would get tedious, so we’ll use the function calc_streak() to calculate them. This function has been loaded automatically for you in your R Markdown report file.

  1. Run the following code to calculate the length of Kobe’s shooting streaks,

    kobe_streak <- calc_streak(kobe_basket)

    then visualize the distribution of the streak lengths.

    ggplot(kobe_streak) +
      geom_bar(
        mapping = aes(x = length)
      )

    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?

Compared to what?

We’ve shown that Kobe had some long shooting streaks, but are they long enough to support the belief that he had a hot hand? What can we compare them to?

To address these questions we will need to make use of the concept of independence. Two processes are independent if the outcome of one process doesn’t affect the outcome of the second. So if each shot that a player takes is an independent process, then that means that making or missing your first shot will not affect the probability that you will make or miss your second shot. Conversely, a shooter with a hot hand will have shots that are not independent of one another. Specifically, if the shooter makes his first shot, the hot hand model says he will have a higher probability of making his second shot.

Let’s suppose for a moment that the hot hand model is valid for Kobe. During his career, the percentage of times that Kobe makes a basket (i.e. his shooting percentage) is about 45%, or in probability notation, \[P(\text{shot 1 = H}) = 0.45\] If he makes the first shot and has a hot hand (remember, this would mean that shots are not independent), then the probability that he makes his second shot would go up to, let’s say, 60%, \[P(\text{shot 2 = H} \, | \, \text{shot 1 = H}) = 0.60\] As a result of these increased probabilites, you’d expect Kobe to have longer streaks.

Compare this to the skeptical perspective where Kobe does not have a hot hand, where each shot is independent of the next. If he hit his first shot, the probability that he makes the second would still be 0.45, \[P(\text{shot 2 = H} \, | \, \text{shot 1 = H}) = 0.45\] In other words, making the first shot did nothing to affect the probability that he’d make his second shot. If Kobe’s shots are independent, then he’d have the same probability of hitting every shot regardless of his past shots: 45%.

Now that we’ve phrased the situation in terms of independent shots, let’s return to the question: how do we tell if Kobe’s shooting streaks are long enough to indicate that he has a hot hand? We can compare his streak lengths to someone without a hot hand: an independent shooter.

Simulations in R

While we don’t have any data from a shooter we know to have independent shots, this sort of data is easy to simulate in R using a package called infer. 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 let’s simulate 100 flips of a fair coin, which has a 50% chance of coming up heads and a 50% chance of coming up tails. Our infer template for this simulation is as follows,

probability_heads <- 0.5

tibble(outcome = rep(combine("heads", "tails"), each = 50)) %>%
  specify(outcome ~ NULL, success = "heads") %>%
  hypothesize(null = "point", p = probability_heads) %>%
  generate(reps = 1, type = "simulate") %>%
  ungroup() %>%
  count(outcome)
  1. Copy and paste all of the above template code into a single code block within your R Markdown notebook and run it. This will simulate the flipping of a fair coin 100 times. From inspecting the results table and seeing the number of times you flip a heads versus tails, does this seem to behave like a fair coin? Why or why not?

    Next, re-run the same code block a couple more times and watch what happens to the results table. Does it stay the same or does it change? If it changes, why would your result be different each time you run the simulation?

Now, imagine that we wanted to simulate an unfair coin that only lands on heads 20% of the time. How could we do this?

  1. Copy and paste the code block from Exercise 3 and adjust the value for probability_heads from 0.5 to 0.2, which is how we tell R that we want the probability of flipping heads to be 20%. Run the code block. In your simulation of 100 flips of the unfair coin, how many flips came up heads?

    If you wanted the probability of flipping tails to be 45%, what should you set probability_heads equal to?

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,

probability_hit <- 0.5

sim_basket <- kobe_basket %>%
  specify(shot ~ NULL, success = "H") %>%
  hypothesize(null = "point", p = probability_hit) %>%
  generate(reps = 1, type = "simulate") %>%
  ungroup() %>%
  transmute(shot = as.character(shot))

Notice here that the dataset kobe_basket is being piped into specify(). This does two things, (1) it will ensure that our shot outcomes will be labeled as either H or M, and (2) it will ensure that our simulated independent shooter will take 133 shots, the same number of shots that Kobe Bryant takes in this dataset.

  1. To make a valid comparison between Kobe and our simulated independent shooter, we need to align their shooting percentages. What change needs to be made to the code template so that it reflects a shooting percentage of 45%? Make this adjustment, then run a simulation to sample 133 shots. This will assign the output of this simulation to sim_basket.

With the results of the simulation saved as sim_basket, we have the data necessary to compare Kobe to our independent shooter. Both datasets 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.

Additional exercises

  1. Using calc_streak(), compute the streak lengths for the simulated independent shooter saved to sim_basket. Assign the results of calc_streak() to a variable named sim_streak.

  2. Visualize the distribution of simulated streak lengths and discuss it. Based on your results, 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?

  3. 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.

  4. 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.

How to submit

To submit your lab, follow the two steps below. Your lab will be graded for credit after you’ve completed both steps!

  1. Save, commit, and push your completed R Markdown file so that everything is synchronized to GitHub. If you do this right, then you will be able to view your completed file on the GitHub website.

  2. Knit your R Markdown document to the PDF format, export (download) the PDF file from RStudio Server, and then upload it to Lab 7 posting on Blackboard.

Cheatsheets

You are encouraged to review and keep the following cheatsheets handy while working on this lab:

Credits

This lab is a derivative of OpenIntro Lab 4 – Probability by Andrew Bray and Mine Çetinkaya-Rundel, which was adapted from a lab written by Mark Hansen of UCLA Statistics, used under CC BY-SA 3.0. This lab is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Adapted by James Glasbrenner for CDS 102.