Skip to content

Instantly share code, notes, and snippets.

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"
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'
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),]
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)
@sangamc
sangamc / simulation_half_inning.R
Created August 10, 2016 19:18 — forked from bayesball/simulation_half_inning.R
Functions to Simulate a Half-Inning of Baseball
# 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",
@sangamc
sangamc / parse.retrosheet2.pbp.R
Created August 9, 2016 03:09 — forked from bayesball/parse.retrosheet2.pbp.R
R function for downloading, upzipping, and appending Retrosheet play-by-play data
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(