Using R to improve your fantasy football team

So I’ve started playing around with R and this week decided to see if I could more intelligently add a player to my team from the ranks of free agency.  The position I needed to fill?  The kicker.

The first thing I did was to grab the YTD data for kickers and store it into a space delimited text file in the /tmp directory called kickers:

sgost 12 6 14 14 7 14 10 10 13 
nfolk 12 4 10 9 13 6 13 13 16
mprat 7 13 17 12 18 5 10 9 4
mcros 4 8 13 20 15 6 15 8 5
dbail 13 14 6 2 12 5 17 11 5
shaus 7 9 9 13 16 13 2 9 19
rsucc 4 5 13 9 15 6 5 12 12
avina 3 7 10 14 10 13 16 6 0
dcarp 3 12 13 11  8 11 4 7 4
nnova 4 18 5 13 4 15 6 6 8
ahenr 8 12 3 7 20 2 1 7 9
gcano 1 11 10 8 5 14 7 12 5
mnuge 3 9 2 7 9 10 11 10 4
pdaws 9 3 1 3 10 13 8 6 12
cstur 13 8 12 5 11 2 5 8 8

Next, I opened R.  I am running this on Linux – so I simply typed ‘R’ to launch the client.

First things first, we need to load the data into a list.

kickers <- read.table('/tmp/kickers', col.names=c('kicker','week1','week2','week3','week4','week5','week6','week7','week8','week9'))

This produces a list with the aforementioned column names.  But this is doesn’t really give us any idea as to how consistent a kicker is or how their averages may have been affected by weeks where they significantly outperformed their typical performance.  I decided to use a boxplot to visualize the data for this purpose.

To do that, I needed to transpose the data so that each kicker had their own column with YTD results.  R has the ‘t’ function for this very purpose.

tkicker = t(kickers[,-1])

This creates a new list with all of the data values – but excludes the first column which contained the kicker’s name; we have plans for that:

      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
week1   12   12    7    4   13    7    4    3    3     4     8     1     3
week2    6    4   13    8   14    9    5    7   12    18    12    11     9
week3   14   10   17   13    6    9   13   10   13     5     3    10     2
week4   14    9   12   20    2   13    9   14   11    13     7     8     7
week5    7   13   18   15   12   16   15   10    8     4    20     5     9
week6   14    6    5    6    5   13    6   13   11    15     2    14    10
week7   10   13   10   15   17    2    5   16    4     6     1     7    11
week8   10   13    9    8   11    9   12    6    7     6     7    12    10
week9   13   16    4    5    5   19   12    0    4     8     9     5     4
      [,14] [,15]
week1     9    13
week2     3     8
week3     1    12
week4     3     5
week5    10    11
week6    13     2
week7     8     5
week8     6     8
week9    12     8

Next, let’s add the kicker’s name as a column header:

colnames(tkicker) <- kickers$kicker

Now we have something we can boxplot:

boxplot(tkicker)

This produces the following graphic:

Screenshot from 2013-11-15 11:27:02

Good – but it doesn’t stand out.  Let’s add some color to this graphic:

boxplot(tkicker, col=colors())

Screenshot from 2013-11-15 11:35:28

From this, we can see Stephen Gostkowski is by far the most consistent kicker with a narrow IQR and a higher than most median average.  Unfortunately – if your league is like my league – he isn’t available.  From the list, however, I could see Nick Folk was a good choice.  His median is also quite high though he has some outlying performances that brought that value up.  His IQR was still relatively narrow – and he did have some poor performances against the Steelers and Patriots.  I picked him up based on this visual; I’ll let you know how I made out next week.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Using R to improve your fantasy football team

  1. dbanetezza says:

    Nick Folk only scored 1 point…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s