padding: 10px 20px;
margin: 0 0 20px;
border-left: 5px solid #eee;
One of my favorite NBA websites is Cleaning the Glass, created by Ben Falk, a former front office executive for the Portland Trail-Blazers. One of the many reasons why I like it to much is the fact that they filter out garbage time from their stats. It is not unusual for a game to be out hand for a team, leading both coaches to take their starters out of the game.
The number of possessions is one of the most important stats in a basketball game. It is used by most (if not all) advanced stats for teams (e.g.: point per possession), players (e.g.: usage rate) and lineups (e.g.: net rating). In the last post, I wrote about ways to count possessions in the NBA, using data from play-by-play. At first I believed it would be a pretty simple task, seeing that it’s such an important stat, but I ended up finding a few inconsistencies and flaws after comparing the results I thought would be correct to the results from the official NBA.
In this post, I will explain how to add possessions to the NBA play-by-play table. The data we’ll use will be the pbp with the lineups for each team added to every event. I explain in details the steps to get it here and here. Let’s load it:
lineup_game_stats <- read_csv("https://github.com/ramirobentes/NBA-in-R/releases/download/lineup-game-stats-7f61e89/data.csv",
col_types = c(timeQuarter = "c")) %>%
mutate(across(starts_with("description"), ~ coalesce(., "")))
team_logs <- game_logs(seasons = 2022, result_types = "team")
## Acquiring NBA basic team game logs for the 2021-22 Regular Season
A team possession happens when there is:
This is part 4 in our series of posts on NBA lineups data. In the last post we learned how to find the performance of different combinations of lineups. Now, we are going to reproduce some other stats when different players are on or off the court. In this post, the tables used will be the play-by-play with lineups added, and the lineups stats. We are also going to get every shot taken in the regular season until now.
This is part 3 in our series of posts on NBA lineups data. In the last post we extracted lineups stats from the play-by-play. Now, we are going to reproduce some numbers from articles using those outputs. You can find the play-by-play table with lineups added here and the lineups stats table here. Let’s load both of them:
lineup_game <- read_csv("LineupGame0107.csv",
col_types = cols(timeQuarter = "c"))
lineup_stats <- read_csv("https://raw.
This is part 2 in our series of posts on NBA lineups data. In the first post we added the lineups at each point of the game to the play-by-play table. Now, we are going to learn how to extract lineups plus minus and playing time from that table. In part 3, we will look at some stats from articles and show how to reproduce them. The output at the end of part 1 can be found here.
A few months ago, I created an account on Twitter to post code snippets reproducing some stats I saw in NBA-related posts and articles using the programming language R. All of the data came from the nbastatR package, and the stats I posted were often fairly simple to get to. However, I recently decided to try working with something a little more complicated: team lineups stats. It’s complicated because the R package doesn’t provide any lineup data, but it does provide play-by-play data.