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
devtools::install_github("stattleship/stattleship-r") | |
library(stattleshipR) | |
## Sign up for one of these from www.stattleship.com | |
set_token('your-API-token') | |
## Set the parameters according to | |
## playbook.stattleship.com | |
league <- "nba" | |
sport <- "basketball" |
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
devtools::install_github("stattleship/stattleship-r") | |
library(stattleshipR) | |
## Get a free Stattleship API token from www.stattleship.com | |
set_token('set-your-token') | |
sport <- 'football' | |
league <- 'nfl' | |
ep <- 'game_logs' |
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
library(lpSolve) | |
preds$team <-as.character(preds$team) | |
obj = preds$prediction | |
con <- rbind(t(model.matrix(~ FD.Position + 0,preds)), t(model.matrix(~ team + 0, preds)), rep(1,nrow(preds)), preds$Salary) | |
dir <- c(">=",">=",">=",">=",">=",rep('<=',length(unique(preds$team))),"<=","<=") | |
rhs <- c(1,2,2,2,2,rep(4,length(unique(preds$team))),9,60000) | |
result = lp("max", obj, con, dir, rhs, all.bin = TRUE) | |
preds[which(result$solution == 1),] |
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
install.packages("devtools") | |
devtools::install_github("stattleship/stattleship-r") | |
install.packages('dplyr') | |
install.packages('ggplot2') | |
## Load the stattleshipR package | |
library(stattleshipR) | |
library(dplyr) | |
library(ggplot2) |
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
# to simulate the number of runs in one half-inning | |
# st <- runs_setup() | |
# simulate_half_inning(st) | |
runs_setup <- function(){ | |
# based on 2015 season data | |
Prob_Single <- matrix(0, 8, 8) | |
dimnames(Prob_Single)[[1]] <- c("000", "100", "010", "001", | |
"110", "101", "011", "111") | |
dimnames(Prob_Single)[[2]] <- c("000", "100", "010", "001", |
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
parse.retrosheet2.pbp = function(season){ | |
# ADJUSTED FOR MAC -- function will work for WINDOWS and MAC | |
# download, unzip, append retrosheet data | |
# assume current directory has a folder download.folder | |
# download.folder has two subfolders unzipped and zipped | |
# program cwevent.exe is in unzipped folder (for windows) | |
download.retrosheet <- function(season){ | |
# get zip file from retrosheet website | |
download.file( |