liveBook · Manning

Streak_run() function

As explained in Statistics Slam Dunk

The streak_run() function computes the lengths of consecutive runs of equal or otherwise defined sequential elements.

streak_run() computes the running length of consecutive elements, making it useful for tracking streaks within grouped sequential data. In a free-throw analysis, group_by(date) keeps one game from carrying a streak into the next; mutate(streak = streak_run(lag(points))) calculates the streak from the previous points value. section 16.4.1

Tracking free-throw streaks

For Giannis Antetokounmpo’s free throws, streak equals 0 when the date changes and equals 1 after the first attempt. Subsequent values increase across consecutive outcomes. Filtering records where lag(points) == 1 and summarizing makes and misses by streak produces shooting percentages after one or more consecutive makes. section 16.4.1

How Statistics Slam Dunk covers it

How deep it goes
Explains grouped inputs, lagged values, reset behavior, and downstream summaries without detailing the function’s internals.
Examples
Uses Giannis Antetokounmpo free throws, make and miss tables, shooting percentages, and a simulated coin-flip sequence.
What it assumes
Assumes basic R piping and data manipulation while demonstrating lagged sequences and grouped calculations.
What you can do after
Apply it via the runner package and dplyr to calculate and summarize sequential streaks.
How it connects
Connects streak_run() with dplyr, group_by(), mutate(), lag(), streak analysis, and Laplace’s rule of succession.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.