The ffanalytics R Package for Fantasy Football Data Analysis
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Introduction
We are continuously looking to provide users ways to replicate our analyses and improve their performance in fantasy football. To that aim, we are introducing the ffanalytics R package that includes a streamlined version of the scripts used to scrape projections from multiple sources and calculate projected points using the wisdom of the crowd.
What Software You Need
Installation
The package is available through our GitHub repository, and installation requires that you have already installed the devtools
package. You can install the devtools
package in R/RStudio via:
install.packages("devtools")
You can then install the ffanalytics R package via:
devtools::install_github(repo = "dadrivr/FantasyFootballAnalyticsR", subdir = "R Package/ffanalytics")
There is also a tarball available in the GitHub repository that you can download and install with install.packages()
. After the package is installed you can then load the package via:
library("ffanalytics")
Package manual
The package includes a reference manual in standard package format. You can also find this in the help pane in RStudio. The full PDF version of the manual is here.
Addins
The ffanalytics
package includes RStudio addins to help you easily scrape and calculate projections. To use the addins, you will need to run RStudio (v0.99.878 or later). The first addin Run Scrape
will just scrape projections while Run Projections
will scrape projection and calculate projected points. The addins will construct code and return them to the console in RStudio to be executed. Because the Run Projections
addin contains functionality of the Run Scrape
addin, we will just focus on the projections addin here.
Run Projections addin
The Run Projections
addin consists of three tabs that you will need to review before executing the function to scrape and calculate projections.
1. Scrape Settings
When you start the projections addin, you should see the tab where you can select which season, week, sources, and positions you want to scrape. Select the season and week you want to scrape (week=0
for seasonal projections). Then select the analysts and positions you want to scrape. The function has the ability to include subscription based sources, but you will need to either download subscription projections separately or provide a user name and password for those sites. Note that historical data scrapes are nearly impossible to do as sites usually don’t store their historical projections.
2. Scoring Settings
Review and set the scoring settings for the calculations on the scoring settings tab. There is a panel for each position with the names of the variables to score. These settings are similar to the ones in our Projections tool. Use the scoring setting that match your league’s.
3. Calculation Settings
On the calculations tab, select which average you want to use for aggregating the sources and calculating projected points. Then, select which sources of ADP values to use. It also allows you to select which MFL drafts types to use when getting the ADP data. Tiers are calculated using effect size thresholds based on Cohen’s d. Smaller d values result in more tiers (fewer players per tier).
Execute R code
You can also execute the code to run directly from R or RStudio. If you want to run a data scrape then you can execute, e.g.:
runScrape(week = 0, season = 2016, analysts = c(-1, 5, 7, 18, 27), positions = c("QB", "RB", "WR", "TE", "K", "DST"))
This scrapes seasonal projections for the 2016 season for 5 different analysts for the Non-IDP positions. Refer to the analysts
table in the package to identify the analysts you want to use.
If you want to calculate projections from R or RStudio, you will need the output from the runScrape()
function. Then you can execute:
getProjections(scrapeData, avgMethod = "average", leagueScoring = userScoring, teams = 12, format = "standard", mflMocks = -1, mflLeagues = -1, adpSources = c("CBS", "ESPN", "FFC", "MFL", "NFL"))
where scrapeData
is the output from the runScrape()
function and userScoring
is your defined scoring rules. See scoringRules
in the package for how to define scoring rules.
Troubleshooting
If you run into errors or issues, feel free to let us know in the comments or to open a GitHub issue on our GitHub repo. If you are able to find and fix an issue, please share the fix with the community (for more info how to share your scripts with the community, see here).
Downloading Our R Scripts
In addition to the ffanalytics R Package, we also have R scripts that accompany posts on the site. To download and run our R scripts, see here. If you’d rather calculate projections using our webapps without the R package, see here. We encourage people to use and improve our scripts, and to share them with the community so everyone benefits. For info on how to share your scripts with the community, see here.
The post The ffanalytics R Package for Fantasy Football Data Analysis appeared first on Fantasy Football Analytics.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.