**Fantasy Football Analytics in R**, and kindly contributed to R-bloggers)

In this post, I use a Shiny app in R to determine the best possible players to pick in a fantasy football auction draft. The app takes projections from FantasyPros, a site that averages across numerous sources of projections. Based on your league settings, it determines which players you should draft to maximize your starting lineup’s projected points. It also allows you to change your risk tolerance to avoid picking risky players. Best of all, the app updates the selections automatically with your inputs, and you can download the data for yourself. So let’s get to it. Here’s a more thorough description:

### How it Works

First, I use a script to scrape player’s projected points from FantasyPros using the XML package in R. FantasyPros is an ideal source of projections because it averages across numerous sources of projections, and is the most accurate source of projections I’ve been able to find. Second, I scrape average auction values from FantasyPros. Third, I calculate players’ risk levels, as defined by the standard deviation (uncertainty) around the players’ ranks and projections across sources. Note that risk is standardized to have a mean of 5 and a standard deviation of 2. Fourth, I take user inputs on league settings to calculate projections that are custom tailored for your league (e.g., based on how many points a passing TD is worth in your league). Fifth, I normalize the players’ costs relative to the cap available.

In line with an unpublished analysis from Harvard on the optimal draft strategy, I apply a 10% premium to the top players and a 10% discount to the lower-tiered players. According to the study, the majority of one’s excess cap should be spent on the starting lineup, and you should spend less on bench players. This is because bench players do not contribute much to the team’s projected points. Although bench players are important in the case of a starter’s injury or under-performance, it is generally best to draft starters with minimal risk to ensure solid, if not superior, performance. On the other hand, one should accept more risk with bench players because such a move has a low risk, high reward potential.

Then, based on how many starters you need for each position, your cap available, the players already drafted, and your maximum risk tolerance, I use the Rglpk package to find your optimal starting lineup by selecting the remaining players available that maximize the starting lineup’s sum of projected points while meeting all of the constraints. For a similar execution using Excel’s Solver function, see here. See below for a description of the possible user inputs.

### User Inputs

League Cap: the cap available for each team at the beginning of the draft.

Total Number of Players on Roster: the total number of players on roster, including bench players. This is used to determine your available cap (it assumes you must spend at least $1 on each bench player).

__Scoring Settings__

Passing Yards Per Point: How many passing yards are worth 1 fantasy point?

Points Per Passing TD: How many points is each passing touchdown worth?

Points Per Passing INT: How many points is each interception worth?

Rushing Yards Per Point: How many rushing yards are worth 1 fantasy point?

Points Per Rushing TD: How many points is each rushing touchdown worth?

Points Per Reception: How many points are receptions worth?

Receiving Yards Per Point: How many receiving yards are worth 1 fantasy point?

Points Per Receiving TD: How many points is each receiving touchdown worth?

Points Per Fumble: How many points is each fumble worth?

Players You Drafted: Select all players you’ve already drafted (hold CTRL to select multiple).

Cap Spent: How much cap you spent on the players you drafted.

Other Players Drafted: Select all players that other teams already drafted (hold CTRL to select multiple).

Maximum Risk Tolerance: Selects the maximum risk allowed for any player to be considered for inclusion in the optimal starting lineup. Players’ risk levels have a mean of 5 and a standard deviation of 2.

__Lineup Settings__

Enter number of starters needed from each position.

### The Shiny App

**leave a comment**for the author, please follow the link and comment on his blog:

**Fantasy Football Analytics in R**.

R-bloggers.com offers

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