NFL Statistics: An Exploratory Data Analysis

Posted on Aug 29, 2017


The mission: making more informed, “better” decisions when placing wagers on NFL football games.

In order to accomplish this mission, an interactive R Shiny Dashboard (link)  was created so that the user can select a specific team-opponent combination to obtain historical matchup performance trends in addition to variables correlated with beating the team’s user specified opponent.  

Once the user is able to gain information on how the selected team performs against the selected opponent, better gambling decisions based on statistical analysis can be made.  


R is an open-source computer programming language widely used for statistical analyses.  R is bundled with visualization packages that easily allows the programmers to display their statistical findings.  

R Shiny is a web application framework which allows users to interact with the data set being analyzed to produce visualizations as per the input parameters set by the user.  R Shiny is a package bundled with the RStudio integrated development environment (IDE).  


There are 2 main types of wagers when betting on NFL games: the point spread and the point total.  The R Shiny Dashboard was tailored to present the data with the point spread and point total betting types in mind, but the data can be applied to other NFL wagers.

The Point Spread

Sportsbooks formulate a point spread (aka “line”) for each NFL game.  If the “line” is negative, the team mentioned preceding the line is favored by the amount of the line.  For example, if the New Orleans Saints are -9 vs the Atlanta Falcons and a gambler places a point spread wager on the Saints, the gambler needs the Saints to beat the Falcons by 10 or more points in order to win the bet (aka “cover”).  

If the Atlanta Falcons are +9 vs the New Orleans Saints and a gambler places a point spread wager on the Falcons, the gambler needs the Falcons to lose the game by 8 or less points in order to “cover” the bet.  If New Orleans wins by exactly 9 points, the bet is a draw (aka “push”); and no money is exchanged.  

In reality, sportsbooks charge the gambler a percentage (aka “vig”) of the bet to take the bet.  The gambler loses the percentage in a push bet, but that concept is outside the scope of the topics covered.

The Point Total

Sportsbooks also formulate a point total (aka “over/under”) for each NFL game.  A gambler can bet over or under on the combined points of both teams.  For example, if the “Over/Under” is set at 46 points and  a gambler bets the over, he can win if the two teams’ combined score is above that amount.

For example, if the Saints scored 34 points and the Falcons scored 20 points, the gambler wins the wager since a combined 54 points were scored in the game.  Just as in the point spread bet, if the combined score totals 46 points, the bet is a draw and no money is exchanged.


The data set used for the R Shiny web application was obtained from Pro Football Reference, which is an NFL statistic aggregating website (  Quarterback (QB), running back (RB) and wide receiver (WR) statistics from each game of the past five (5) NFL seasons--2012 through 2016--were compiled into a CSV file so that it could be loaded into the R Studio IDE.  

Reference the snapshot below for the QB statistics collected:

Reference the snapshot below for the WR statistics collected:

Reference the snapshot below for the RB statistics collected:



The Home page is meant to illustrate that teams generally do not have very big swings in win total from season to season.  Also, the line graphs illustrate total wins (y-axis) by season (x-axis) with each color representing a team.  The graphs are separated by conference and division.  

The user can select a number for the win difference from year to year, and the table below will display the teams with a win total swing greater than the value selected.  For example, if the user selects 6 as the input, the table will update to display the 8 teams over the last 5 years that had a swing in total wins of 7 games or more.  


The matchup tables sub-menu page under the betting menu is a way for the user to easily see tables containing the statistics of prior matchups between the selected team and the selected opponent.  The user can select the team for analysis and the opponent via the sidebar.  Reference the table below for a legend explaining the variable names in the tables:

Variable Dictionary Table:

Season: NFL season in which game occurred Week:  Week of game Team: Team for analysis X: Home or Away
Opponent: Upcoming opponent Result: Win, Lose or Tie ptsFor: Points scored by Team ptsAgst: Points scored by Opponent or defensive points allowed by Team
psYds: Team passing yards psTDs: Team passing TDs psInt: Interceptions thrown by Team QBR: Quarterback Rating (QB efficiency metric)
psYds: Team sacks allowed rsYds: Team rushing yards rsTD: Team rushing TDs

Receiving statistics were excluded from team analysis since the receiving statistics mirror the passing statistics.  For example, receiving yards for each team is equal to passing yards.


To analyze what variables are correlated to beating a specific opponent, a “Winning” variable  was created.  A value of 1 or 0 was assigned so that correlations could be determined.  

Then a variable correlation matrix was created/plotted so that the user can visualize how the variables are correlated to one another, specifically to beating the selected opponent.  

Additionally, the correlations (values) to the “Winning” variable were extracted and presented in a table so that the user would readily have access to that information.  See below for an example:



The final feature of this Shiny web application allows the user to analyze the current season performance of the selected team and opponent.  In the preceding features historical statistical information was analyzed, and the variable(s) most correlated to beating a specific opponent were obtained.  

This feature presents how the selected team is performing and how the defense of the selected opponent is performing for a specific variable that the user can select.  

Since the 2017 football season has not yet started, Week 12 of the 2016 season was arbitrarily selected and used in this example to present how the feature will operate.  


There is room for improvement for this Shiny Web application.  The following items will be addressed:

  • Load more years
    • 5 years of historical data was limited.  This provided for some missing and inaccurate correlations.
  • Missing values
    • Addressing missing values fell outside the scope of this project but will be addressed in the near future.  
  • Load more variables
    • There are other variables that are likely correlated to performance/winning such as indoor vs outdoor, early season vs late season performance, etc.

The path forward for this web application would be to input sportsbook betting lines and predict scores of future games based on historical performance (both current season and prior seasons) via machine learning techniques.  

Once betting line information is received and scores of games are predicted, the predicted score can be compared against the betting lines to determine which wagers have positive expected value (EV).    

The skills the author demonstrated here can be learned through taking Data Science with Machine Learning bootcamp with NYC Data Science Academy.

About Author

Andre Toujas

“Why?” The question “why” has always intrigued Andre. That simple question is what made Andre pursue his degree in mechanical engineering, and answering “why” is what drives him as a data scientist. Two of his four NYCDSA projects...
View all posts by Andre Toujas >

Related Articles

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 2020 Revenue 3-points agriculture air quality airbnb airline alcohol Alex Baransky algorithm alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus ames dataset ames housing dataset apartment rent API Application artist aws bank loans beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep boston safety Bundles cake recipe California Cancer Research capstone car price Career Career Day citibike classic cars classpass clustering Coding Course Demo Course Report covid 19 credit credit card crime frequency crops D3.js data data analysis Data Analyst data analytics data for tripadvisor reviews data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization database Deep Learning Demo Day Discount disney dplyr drug data e-commerce economy employee employee burnout employer networking environment feature engineering Finance Financial Data Science fitness studio Flask flight delay gbm Get Hired ggplot2 googleVis H20 Hadoop hallmark holiday movie happiness healthcare frauds higgs boson Hiring hiring partner events Hiring Partners hotels housing housing data housing predictions housing price hy-vee Income Industry Experts Injuries Instructor Blog Instructor Interview insurance italki Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter las vegas airport lasso regression Lead Data Scienctist Lead Data Scientist leaflet league linear regression Logistic Regression machine learning Maps market matplotlib Medical Research Meet the team meetup methal health miami beach movie music Napoli NBA netflix Networking neural network Neural networks New Courses NHL nlp NYC NYC Data Science nyc data science academy NYC Open Data nyc property NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time performance phoenix pollutants Portfolio Development precision measurement prediction Prework Programming public safety PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R Data Analysis R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn seafood type Selenium sentiment analysis sentiment classification Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau teachers team team performance TensorFlow Testimonial tf-idf Top Data Science Bootcamp Top manufacturing companies Transfers tweets twitter videos visualization wallstreet wallstreetbets web scraping Weekend Course What to expect whiskey whiskeyadvocate wildfire word cloud word2vec XGBoost yelp youtube trending ZORI