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, in this lab we’ll apply one approach to answering questions like this. The goals for this lab are 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.

Loading the data

## Rows: 133
## Columns: 6
## $ vs          <fct> ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ORL, ...
## $ game        <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1...
## $ quarter     <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3...
## $ time        <fct> 9:47, 9:07, 8:11, 7:41, 7:03, 6:01, 4:07, 0:52, 0:00, 6...
## $ description <fct> Kobe Bryant makes 4-foot two point shot, Kobe Bryant mi...
## $ shot        <chr> "H", "M", "M", "H", "H", "M", "M", "M", "M", "H", "H", ...
## # A tibble: 133 x 6
##    vs     game quarter time  description                                   shot 
##    <fct> <int> <fct>   <fct> <fct>                                         <chr>
##  1 ORL       1 1       9:47  Kobe Bryant makes 4-foot two point shot       H    
##  2 ORL       1 1       9:07  Kobe Bryant misses jumper                     M    
##  3 ORL       1 1       8:11  Kobe Bryant misses 7-foot jumper              M    
##  4 ORL       1 1       7:41  Kobe Bryant makes 16-foot jumper (Derek Fish~ H    
##  5 ORL       1 1       7:03  Kobe Bryant makes driving layup               H    
##  6 ORL       1 1       6:01  Kobe Bryant misses jumper                     M    
##  7 ORL       1 1       4:07  Kobe Bryant misses 12-foot jumper             M    
##  8 ORL       1 1       0:52  Kobe Bryant misses 19-foot jumper             M    
##  9 ORL       1 1       0:00  Kobe Bryant misses layup                      M    
## 10 ORL       1 2       6:35  Kobe Bryant makes jumper                      H    
## # ... with 123 more rows
##    vs           game       quarter       time    
##  ORL:133   Min.   :1.000   1  :36   0:00   :  3  
##            1st Qu.:1.000   1OT: 7   0:04   :  2  
##            Median :3.000   2  :25   11:00  :  2  
##            Mean   :2.902   3  :34   1:20   :  2  
##            3rd Qu.:4.000   4  :31   2:17   :  2  
##            Max.   :5.000            3:33   :  2  
##                                     (Other):120  
##                                    description      shot          
##  Bryant 3pt Shot: Missed                 :  5   Length:133        
##  Kobe Bryant misses layup                :  5   Class :character  
##  Kobe Bryant makes 11-foot two point shot:  4   Mode  :character  
##  Kobe Bryant makes 20-foot jumper        :  4                     
##  Kobe Bryant misses 19-foot jumper       :  4                     
##  Kobe Bryant misses 20-foot jumper       :  4                     
##  (Other)                                 :107
## # A tibble: 9 x 6
##   vs     game quarter time  description                                    shot 
##   <fct> <int> <fct>   <fct> <fct>                                          <chr>
## 1 ORL       1 1       9:47  Kobe Bryant makes 4-foot two point shot        H    
## 2 ORL       1 1       9:07  Kobe Bryant misses jumper                      M    
## 3 ORL       1 1       8:11  Kobe Bryant misses 7-foot jumper               M    
## 4 ORL       1 1       7:41  Kobe Bryant makes 16-foot jumper (Derek Fishe~ H    
## 5 ORL       1 1       7:03  Kobe Bryant makes driving layup                H    
## 6 ORL       1 1       6:01  Kobe Bryant misses jumper                      M    
## 7 ORL       1 1       4:07  Kobe Bryant misses 12-foot jumper              M    
## 8 ORL       1 1       0:52  Kobe Bryant misses 19-foot jumper              M    
## 9 ORL       1 1       0:00  Kobe Bryant misses layup                       M
## # A tibble: 9 x 6
##   vs     game quarter time  description                                    shot 
##   <fct> <int> <fct>   <fct> <fct>                                          <chr>
## 1 ORL       1 1       9:47  Kobe Bryant makes 4-foot two point shot        H    
## 2 ORL       1 1       9:07  Kobe Bryant misses jumper                      M    
## 3 ORL       1 1       8:11  Kobe Bryant misses 7-foot jumper               M    
## 4 ORL       1 1       7:41  Kobe Bryant makes 16-foot jumper (Derek Fishe~ H    
## 5 ORL       1 1       7:03  Kobe Bryant makes driving layup                H    
## 6 ORL       1 1       6:01  Kobe Bryant misses jumper                      M    
## 7 ORL       1 1       4:07  Kobe Bryant misses 12-foot jumper              M    
## 8 ORL       1 1       0:52  Kobe Bryant misses 19-foot jumper              M    
## 9 ORL       1 1       0:00  Kobe Bryant misses layup                       M
## # A tibble: 9 x 1
##   shot 
##   <chr>
## 1 H    
## 2 M    
## 3 M    
## 4 H    
## 5 H    
## 6 M    
## 7 M    
## 8 M    
## 9 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? Within the nine shot attempts, there are six streaks, which are separated by a “|” above. Their lengths are one, zero, two, zero, zero, zero (in order of occurrence)

H M | M | H H M | M | M | M = Within the nine shot attempts, there are six streaks, which are separated by a “|” above. Their lengths are one, zero, two, zero, zero, zero (in order of occurrence)

## # A tibble: 133 x 6
##    vs     game quarter time  description                                   shot 
##    <fct> <int> <fct>   <fct> <fct>                                         <chr>
##  1 ORL       1 1       9:47  Kobe Bryant makes 4-foot two point shot       H    
##  2 ORL       1 1       9:07  Kobe Bryant misses jumper                     M    
##  3 ORL       1 1       8:11  Kobe Bryant misses 7-foot jumper              M    
##  4 ORL       1 1       7:41  Kobe Bryant makes 16-foot jumper (Derek Fish~ H    
##  5 ORL       1 1       7:03  Kobe Bryant makes driving layup               H    
##  6 ORL       1 1       6:01  Kobe Bryant misses jumper                     M    
##  7 ORL       1 1       4:07  Kobe Bryant misses 12-foot jumper             M    
##  8 ORL       1 1       0:52  Kobe Bryant misses 19-foot jumper             M    
##  9 ORL       1 1       0:00  Kobe Bryant misses layup                      M    
## 10 ORL       1 2       6:35  Kobe Bryant makes jumper                      H    
## # ... with 123 more rows
##    length
## 1       1
## 2       0
## 3       2
## 4       0
## 5       0
## 6       0
## 7       3
## 8       2
## 9       0
## 10      3
## 11      0
## 12      1
## 13      3
## 14      0
## 15      0
## 16      0
## 17      0
## 18      0
## 19      1
## 20      1
## 21      0
## 22      4
## 23      1
## 24      0
## 25      1
## 26      0
## 27      1
## 28      0
## 29      1
## 30      2
## 31      0
## 32      1
## 33      2
## 34      1
## 35      0
## 36      0
## 37      1
## 38      0
## 39      0
## 40      0
## 41      1
## 42      1
## 43      0
## 44      1
## 45      0
## 46      2
## 47      0
## 48      0
## 49      0
## 50      3
## 51      0
## 52      1
## 53      0
## 54      1
## 55      2
## 56      1
## 57      0
## 58      1
## 59      0
## 60      0
## 61      1
## 62      3
## 63      3
## 64      1
## 65      1
## 66      0
## 67      0
## 68      0
## 69      0
## 70      0
## 71      1
## 72      1
## 73      0
## 74      0
## 75      0
## 76      1

Exercise 2

Describe the distribution of Kobe’s streak lengths from the 2009 NBA finals. What was his typical streak length? mostly zero (too many misses, I am shocked) hit…but he has a lot of one. How long was his longest streak of baskets? just 1 count where he had at least 4 hit (H ) in a row Make sure to include the accompanying plot in your answer.

##   kobe_streak Freq
## 1           0   39
## 2           1   24
## 3           2    6
## 4           3    6
## 5           4    1
## [1] "tails"
##   [1] "heads" "tails" "tails" "tails" "heads" "tails" "tails" "heads" "tails"
##  [10] "tails" "heads" "tails" "heads" "heads" "heads" "tails" "tails" "tails"
##  [19] "heads" "tails" "heads" "heads" "heads" "heads" "heads" "heads" "tails"
##  [28] "heads" "heads" "heads" "tails" "heads" "heads" "tails" "tails" "tails"
##  [37] "tails" "heads" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
##  [46] "heads" "tails" "tails" "tails" "tails" "heads" "tails" "heads" "heads"
##  [55] "heads" "tails" "heads" "heads" "heads" "heads" "tails" "tails" "heads"
##  [64] "tails" "tails" "tails" "tails" "tails" "heads" "heads" "tails" "heads"
##  [73] "tails" "heads" "tails" "heads" "tails" "tails" "heads" "tails" "tails"
##  [82] "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails" "heads"
##  [91] "heads" "tails" "tails" "heads" "tails" "tails" "tails" "heads" "tails"
## [100] "heads"
## sim_fair_coin
## heads tails 
##    43    57
##   [1] "heads" "tails" "tails" "tails" "heads" "tails" "tails" "heads" "tails"
##  [10] "tails" "heads" "tails" "heads" "heads" "heads" "tails" "tails" "tails"
##  [19] "heads" "tails" "heads" "heads" "heads" "heads" "heads" "heads" "tails"
##  [28] "heads" "heads" "heads" "tails" "heads" "heads" "tails" "tails" "tails"
##  [37] "tails" "heads" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
##  [46] "heads" "tails" "tails" "tails" "tails" "heads" "tails" "heads" "heads"
##  [55] "heads" "tails" "heads" "heads" "heads" "heads" "tails" "tails" "heads"
##  [64] "tails" "tails" "tails" "tails" "tails" "heads" "heads" "tails" "heads"
##  [73] "tails" "heads" "tails" "heads" "tails" "tails" "heads" "tails" "tails"
##  [82] "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails" "heads"
##  [91] "heads" "tails" "tails" "heads" "tails" "tails" "tails" "heads" "tails"
## [100] "heads"
## sim_fair_coin
## heads tails 
##    43    57

Exercice 3

In your simulation of flipping the unfair coin 100 times, how many flips came up heads? Answers: 21, 22, 23 , 23, 28 , 18 heads Include the code for sampling the unfair coin in your response. Since the markdown file will run the code, and generate a new sample each time you Knit it, you should also “set a seed” before you sample. Read more about setting a seed below.

##   sim_fair_coin Freq
## 1         heads   43
## 2         tails   57
## sim_unfair_coin
## heads tails 
##    18    82
##   [1] "heads" "tails" "tails" "tails" "heads" "tails" "tails" "heads" "tails"
##  [10] "tails" "heads" "tails" "heads" "heads" "heads" "tails" "tails" "tails"
##  [19] "heads" "tails" "heads" "heads" "heads" "heads" "heads" "heads" "tails"
##  [28] "heads" "heads" "heads" "tails" "heads" "heads" "tails" "tails" "tails"
##  [37] "tails" "heads" "tails" "tails" "tails" "tails" "tails" "heads" "tails"
##  [46] "heads" "tails" "tails" "tails" "tails" "heads" "tails" "heads" "heads"
##  [55] "heads" "tails" "heads" "heads" "heads" "heads" "tails" "tails" "heads"
##  [64] "tails" "tails" "tails" "tails" "tails" "heads" "heads" "tails" "heads"
##  [73] "tails" "heads" "tails" "heads" "tails" "tails" "heads" "tails" "tails"
##  [82] "tails" "tails" "tails" "heads" "tails" "tails" "tails" "tails" "heads"
##  [91] "heads" "tails" "tails" "heads" "tails" "tails" "tails" "heads" "tails"
## [100] "heads"
## starting httpd help server ... done

Exercice 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

## sim_fair_coin
## heads tails 
##    43    57
##   sim_fair_coin Freq
## 1         heads   43
## 2         tails   57
##   [1] "M" "M" "M" "M" "H" "H" "M" "M" "M" "M" "H" "H" "H" "H" "H" "M" "H" "M"
##  [19] "M" "M" "M" "H" "M" "M" "M" "M" "M" "M" "M" "H" "H" "M" "M" "M" "M" "M"
##  [37] "M" "H" "H" "H" "H" "H" "M" "H" "H" "H" "M" "M" "H" "M" "H" "H" "M" "H"
##  [55] "M" "H" "M" "M" "M" "H" "H" "H" "M" "M" "M" "H" "M" "H" "H" "M" "M" "H"
##  [73] "H" "M" "H" "M" "H" "H" "H" "H" "H" "M" "M" "H" "M" "H" "M" "H" "H" "H"
##  [91] "M" "H" "H" "M" "H" "M" "H" "H" "M" "M" "H" "M" "M" "M" "M" "M" "H" "M"
## [109] "H" "H" "M" "H" "H" "M" "M" "M" "H" "H" "H" "M" "M" "M" "H" "H" "H" "H"
## [127] "M" "M" "M" "M" "M" "M" "H"
## sim_basket
##  H  M 
## 62 71

Exercice 5

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

##     sim_basket
## 1            M
## 2            M
## 3            M
## 4            M
## 5            H
## 6            H
## 7            M
## 8            M
## 9            M
## 10           M
## 11           H
## 12           H
## 13           H
## 14           H
## 15           H
## 16           M
## 17           H
## 18           M
## 19           M
## 20           M
## 21           M
## 22           H
## 23           M
## 24           M
## 25           M
## 26           M
## 27           M
## 28           M
## 29           M
## 30           H
## 31           H
## 32           M
## 33           M
## 34           M
## 35           M
## 36           M
## 37           M
## 38           H
## 39           H
## 40           H
## 41           H
## 42           H
## 43           M
## 44           H
## 45           H
## 46           H
## 47           M
## 48           M
## 49           H
## 50           M
## 51           H
## 52           H
## 53           M
## 54           H
## 55           M
## 56           H
## 57           M
## 58           M
## 59           M
## 60           H
## 61           H
## 62           H
## 63           M
## 64           M
## 65           M
## 66           H
## 67           M
## 68           H
## 69           H
## 70           M
## 71           M
## 72           H
## 73           H
## 74           M
## 75           H
## 76           M
## 77           H
## 78           H
## 79           H
## 80           H
## 81           H
## 82           M
## 83           M
## 84           H
## 85           M
## 86           H
## 87           M
## 88           H
## 89           H
## 90           H
## 91           M
## 92           H
## 93           H
## 94           M
## 95           H
## 96           M
## 97           H
## 98           H
## 99           M
## 100          M
## 101          H
## 102          M
## 103          M
## 104          M
## 105          M
## 106          M
## 107          H
## 108          M
## 109          H
## 110          H
## 111          M
## 112          H
## 113          H
## 114          M
## 115          M
## 116          M
## 117          H
## 118          H
## 119          H
## 120          M
## 121          M
## 122          M
## 123          H
## 124          H
## 125          H
## 126          H
## 127          M
## 128          M
## 129          M
## 130          M
## 131          M
## 132          M
## 133          H
##    length
## 1       0
## 2       0
## 3       0
## 4       0
## 5       2
## 6       0
## 7       0
## 8       0
## 9       5
## 10      1
## 11      0
## 12      0
## 13      0
## 14      1
## 15      0
## 16      0
## 17      0
## 18      0
## 19      0
## 20      0
## 21      2
## 22      0
## 23      0
## 24      0
## 25      0
## 26      0
## 27      5
## 28      3
## 29      0
## 30      1
## 31      2
## 32      1
## 33      1
## 34      0
## 35      0
## 36      3
## 37      0
## 38      0
## 39      1
## 40      2
## 41      0
## 42      2
## 43      1
## 44      5
## 45      0
## 46      1
## 47      1
## 48      3
## 49      2
## 50      1
## 51      2
## 52      0
## 53      1
## 54      0
## 55      0
## 56      0
## 57      0
## 58      1
## 59      2
## 60      2
## 61      0
## 62      0
## 63      3
## 64      0
## 65      0
## 66      4
## 67      0
## 68      0
## 69      0
## 70      0
## 71      0
## 72      1
## sim_basket2
##  0  1  2  3  4  5 
## 42 13  9  4  1  3

Exercice 6

Describe the distribution of streak lengths.

What is the typical streak length for this simulated independent shooter with a 45% shooting percentage? still motly zero, a lot of missed,

How long is the player’s longest streak of baskets in 133 shots? answer: 5

Make sure to include a plot in your answer. Looking at the this independent shooting, it is about the same with Kobe, right skewed if I drawed a line…

##   sim_basket2 Freq
## 1           0   42
## 2           1   13
## 3           2    9
## 4           3    4
## 5           4    1
## 6           5    3

Exercice 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 want to say about the same with independent with no second time. The probability does not change, with 45% shooting percentage and considering what Kobe streak and the independent shooter show, a lot of misses out of 133 shots…

#Exercice 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: I actualy answer this question without knowing. overall the pattern is about the same, a curve line would display a right skewed distribution, the most evidence still the streak of zero, event Kobe_streak shows better streak on one , two and three…I think if I only use Kobe_streak to conclude, the statement would be bias. I think if more dataset is gathered from other players, then there will be enough evidence to conclude.

LS0tDQp0aXRsZTogIkRBVEE2MDZfTGFiM19Qcm9iYWJpbGl0eSINCmF1dGhvcjogIkFsZXhpcyBNZWt1ZWtvIg0KZGF0ZTogImByIFN5cy5EYXRlKClgIg0Kb3V0cHV0OiBvcGVuaW50cm86OmxhYl9yZXBvcnQNCi0tLQ0KDQpgYGB7ciBsb2FkLXBhY2thZ2VzLCBtZXNzYWdlPUZBTFNFfQ0KbGlicmFyeSh0aWR5dmVyc2UpDQpsaWJyYXJ5KG9wZW5pbnRybykNCmxpYnJhcnkocGx5cikNCmxpYnJhcnkoZHBseXIpDQpsaWJyYXJ5KGRpY2UpDQpsaWJyYXJ5KFZlbm5EaWFncmFtKQ0KbGlicmFyeShJU3dSKQ0KI2xpYnJhcnkoaGVscCA9ICJkaWNlIikNCiNsaWJyYX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