Last active
October 6, 2018 05:18
-
-
Save friscojosh/8c22d38d44166ab03c528eed2733993f to your computer and use it in GitHub Desktop.
Testing the year to year stability of snaps for the WR position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################### | |
### Testing the year to year stability of | |
### snaps for the WR position | |
### Josh Hermsmeyer 10-5-18 | |
########################################### | |
### SQL to generate the dataset from Armchair Analysis | |
# SELECT a.player, a.snp, a.trg, b.fname, b.lname, b.pos1, c.seas | |
# FROM offense a | |
# INNER JOIN player b ON a.player = b.player | |
# INNER JOIN game c ON a.gid = c.gid | |
# WHERE pos1 = 'WR' AND a.snp > 0 | |
# data can be found here: https://t.co/hF6Sc4RgHv | |
library(tidyverse) | |
### Read in the csv, create a season2 variable to join on | |
### and group and summarize by season | |
snaps <- read_csv('data/snaps_wr.csv') %>% | |
mutate(season2 = seas + 1) %>% | |
group_by(player, seas, season2) %>% | |
summarize(snp = mean(snp), | |
trg = mean(trg)) | |
### Join the data on itself for a year over year analysis | |
snaps_joined <- snaps %>% | |
left_join(snaps, by = c("season2" = "seas", "player")) %>% | |
na.omit() %>% | |
filter(snp.x >= 30) | |
### Create a simple model using snaps and targets per game predictors in year 1 | |
### and targets per game in year y+1 as the response variable | |
model_snaps_trg <- lm(data = snaps_joined, trg.y ~ trg.x + snp.x) | |
summary(model_snaps_trg) | |
### Same as above just this time with targets per game alone | |
model_trg <- lm(data = snaps_joined, trg.y ~ trg.x) | |
summary(model_trg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment