nflfastR Documentation

repository·master·Indexed 19 days ago

https://github.com/nflverse/nflfastr

An R package for scraping and processing NFL play-by-play data. It provides historical data dating back to 1999 and includes built-in models for advanced metrics such as Expected Points (EP), Win Probability (WP), Completion Probability (CP), and Yards After the Catch (YAC).

Tokens
665
Snippets
2
Records
5
Agent score
18%

What's inside nflfastR

  1. Overview of nflfastR features

    master

    nflfastR is a collection of functions designed to efficiently scrape NFL play-by-play data. Key features include:

    • Historical Data: Play-by-play data dating back to 1999.
    • Advanced Metrics: Includes completion probability (cp), completion percentage over expected (cpoe), and expected yards after the catch (xyac_epa and xyac_mean_yardage) for data from 2006 onwards.
    • Contextual Information: Includes drive information (starting position, result) and series information (series number, success).
    • Built-in Models: Provides models for Expected Points (EP), Win Probability (WP), Completion Probability (CP), and Yards After the Catch (YAC).
    • Database Management: Includes the update_db() function to create and update a local database.
  2. Understanding nflfastR models

    master

    nflfastR provides proprietary models for several key NFL metrics:

    • Expected Points (EP): Models the expected points for a given situation.
    • Win Probability (WP): Includes two versions—one that incorporates the pre-game spread and one that does not.
    • Completion Probability (CP): Models the likelihood of a pass completion.
    • Yards After Catch (YAC): Models expected yardage after a catch.

    Detailed documentation for these models can be found on Open Source Football.

  3. Accessing nflfastR data

    master

    While nflfastR can scrape data, for the most efficient access to complete seasons (including regular season and postseason data back to 1999), it is recommended to:

    1. Download datasets directly from the nflverse-data releases.
    2. Use the nflreadr package.

    Postseason games can be identified using the game_type or week columns.

  4. Install the development version of nflfastR

    master

    To access bug fixes or new features not yet in the CRAN release, you can install the development version using pak from GitHub or via the nflverse R-universe repository.

    # Option 1: Install from GitHub using pak
    if (!require("pak")) install.packages("pak")
    pak::pak("nflverse/nflfastR")
    
    # Option 2: Install from the nflverse R-universe
    install.packages("nflfastR", repos = c("https://nflverse.r-universe.dev", getOption("repos")))