A streak counts consecutive events with the same outcome or property. In free-throw analysis, it measures how many prior attempts formed an uninterrupted run of makes, while resetting at each game. section 16.4.1
A practical R workflow builds and analyzes streaks:
- Group attempts by date so a run cannot carry from one game into the next. section 16.4.1
- Use dplyr::lag() with runner::streak_run() inside mutate() to calculate the running streak. section 16.4.1
- Group by streak length, count makes and misses, and calculate the percentage of makes for each run length. section 16.4.1
Giannis Antetokounmpo’s free throws
A 707-record data set contains 442 made free throws. After grouping by game and calculating streaks, the first attempt receives a streak value of 1, the next attempt reflects the preceding result, and the streak resets when the date changes. Percentages can then be plotted against consecutive makes to investigate a possible hot-hand pattern. section 16.4.1
giannis %>% group_by(date) %>% mutate(streak = streak_run(lag(points))) -> giannis_final head(giannis_final, n = 10) ## # A tibble: 10 × 7 ## # Groups: date [1] ## date event_type player points result ## <date> <fct> <chr> <dbl> <fct> ## 1 2019-10-24 free throw Giannis Antetokounmpo 0 missed ## 2 2019-10-24 free throw Giannis Antetokounmpo 1 made ## 3 2019-10-24 free throw Giannis Antetokounmpo 0 missed ## 4 2019-10-24 free throw Giannis Antetokounmpo 0 missed ## 5 2019-10-24 free throw Giannis Antetokounmpo 0 missed ## 6 2019-10-24 free throw Giannis Antetokounmpo 1 made ## 7 2019-10-24 free throw Giannis Antetokounmpo 1 made ## 8 2019-10-24 free throw Giannis Antetokounmpo 1 made ## 9 2019-10-24 free throw Giannis Antetokounmpo 1 made ## 10 2019-10-24 free throw Giannis Antetokounmpo 1 made ## type streak ## <fct> <int> ## 1 Free Throw 1 of 2 0 ## 2 Free Throw 2 of 2 1 ## 3 Free Throw 1 of 2 1 ## 4 Free Throw 2 of 2 1 ## 5 Free Throw 1 of 2 2 ## 6 Free Throw 2 of 2 3 ## 7 Free Throw 1 of 1 1 ## 8 Free Throw 1 of 2 2 ## 9 Free Throw 2 of 2 3 ## 10 Free Throw 1 of 2 4
Inspect the grouped mutate() pipeline and its first ten calculated observations. section 16.4.1
