Flow and Dynamics in NBA games – Part III

June 28, 2015
By

(This article was first published on StatOfMind, and kindly contributed to R-bloggers)

In part I and II of this post series on NBA game dynamics, I explored both the average score differential and proportion of time spent in the lead for each NBA team. Interestingly, this proved to not be a very reliable proxy for overall performance and number of wins accrued over an entire season. To continue, I decided to look at scoring streaks patterns. Here, I simply extracted and averaged the maximal scoring streaks that teams achieved during the course of a full season. Given that my data was stored in a datatable in the following format:

 
GAME_ID      YEAR HOME    AWAY    QUARTER TIME   SCORE seconds away  home   score
                  TEAM    TEAM                         (in s)  score score  diff
201310290IND 2014 Indiana Orlando 1       11:39.0 0-0   21     0     0      0
201310290IND 2014 Indiana Orlando 1       11:30.0 0-2   30     0     2      2
201310290IND 2014 Indiana Orlando 1       11:15.0 0-2   45     0     2      2
201310290IND 2014 Indiana Orlando 1       11:14.0 0-2   46     0     2      2
201310290IND 2014 Indiana Orlando 1       11:03.0 0-2   57     0     2      2

The actual function that I used to find the longest streak was:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
'find_longest_streak' <- function(vec) {
  streaks <- c()
  current <- 0
  for(i in 2:length(vec)) {
    if(abs(vec[i]) >= abs(vec[i-1])) {
      current <- current + (abs(vec[i]) - abs(vec[i-1]))
    }
    else{
      streaks <- c(streaks, current)
      current <- 0
    }
  }
  return(max(streaks))

Using the above, I looked at scoring streaks for teams playing at home and away over the course of the 2001-2014 seasons. The heatmap below, generated using the d3heatmap R library shows the average maximal scoring streak per game for teams playing at home. This shows that the LA Clippers is the team that goes on the longest scoring streaks. What is most intriguing is that scoring streaks appear to be longer now than they were perhaps 10 years ago.

Average maximal scoring streak per game for teams playing at home


The same observation holds for lead propensity scores of teams playing away: scoring streaks appear to be longer now than they were perhaps 10 years ago.

Average maximal scoring streak per game teams playing away


Finally, we can look at the differential in average maximal scoring streak per game when teams play at home or away.

Difference in maximal scoring streaks per game when playing at home and away


To leave a comment for the author, please follow the link and comment on their blog: StatOfMind.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)