Skip to content

Instantly share code, notes, and snippets.

Jim Albert bayesball

Block or report user

Report or block bayesball

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
bayesball / distances2.R
Created Dec 2, 2018
Comparing distances on balls put into play for 2017 and 2018 seasons
View distances2.R
# read in packages and data
sc2018 <- read_csv("../StatcastData/statcast2018new.csv")
sc2017 <- read_csv("../StatcastData/statcast2017.csv")
sc2017ip <- filter(sc2017, type == "X") # 127555 rows
sc2018ip <- filter(sc2018, type == "X") # 126282 rows
bayesball / app.R
Created Nov 2, 2018
Shiny R code to compare home run pitch locations for two batters
View app.R
sc2018 <- read_csv("sc2018_ip.csv") %>%
mutate(Ptype = ifelse(pitch_type %in% c("FC", "FF", "FO", "FS", "FT", "SI"),
"fb", "os"))
sc2018 %>% group_by(player_name) %>% summarize(HR = sum(HR)) -> S
plist <- filter(S, HR >= 30) %>% select(player_name) %>% pluck()
ui = fluidPage(
titlePanel("Locations of 2018 Home Runs: Compare Two 30+ Players"),
bayesball / app.R
Created Oct 31, 2018
Shiny app for displaying baseball history
View app.R
# Define UI for application that draws a histogram
ui <- shinyUI(pageWithSidebar(
# Application title
headerPanel("Offensive Production in Baseball History"),
# Sidebar with controls to select the variable to plot against year
bayesball / app.R
Last active Oct 31, 2018
Data Science Club, November 2, 2018: Some Shiny examples
View app.R
# histogram of some random data
# choose between normal, uniform, exponential distributions
# using radio buttons
# add a select input (sample size)
# ----------------------
# add a slider for the number of bins in histogram
ui <- fluidPage(
selectInput(inputId = "n",
bayesball / swingmiss2018.R
Created Oct 25, 2018
Exploring 2018 swing and miss rates
View swingmiss2018.R
# Load in the necessary packages
# Read in the statcast data for the 2018 season
d <- read_csv("../Statcastdata/statcast2018new.csv")
bayesball / plot_AVGs.R
Last active Oct 24, 2018
Plotting distributions of batting averages
View plot_AVGs.R
# load a few packages
# need to install the BApredict package
# devtools::install_github("bayesball/BApredict")
# the Lahman data frame Batting has most of the batting data
bayesball / Historic.R
Last active Oct 11, 2018
History View of Three Hitting Rates
View Historic.R
## Load Lahman Teams data frame
Teams <- read_csv("~/Dropbox/Google Drive/Lahman/core/Teams.csv")
Teams %>% filter(yearID >= 1913) %>%
group_by(yearID) %>%
summarize(AB = sum(AB),
HR = sum(HR),
SO = sum(SO),
bayesball / retrosheet_gamelog_read.R
Created Aug 25, 2018
R function to read in Retrosheet game logs
View retrosheet_gamelog_read.R
Headers <- c("Date", "DoubleHeader",
"DayOfWeek", "VisitingTeam",
"VisitingTeamLeague", "VisitingTeamGameNumber",
"HomeTeam", "HomeTeamLeague" ,
"HomeTeamGameNumber", "VisitorRunsScored" ,
"HomeRunsScore", "LengthInOuts",
"DayNight", "CompletionInfo",
"ForfeitInfo", "ProtestInfo" ,
"ParkID", "Attendence" ,
"Duration", "VisitorLineScore",
bayesball / threevarwork.R
Last active Dec 4, 2018
Predicting probability of hit from three variables
View threevarwork.R
# see blog post at
# load in tidyverse package
# read in the 2017 statcast data
sc2017 <- read_csv("../StatcastData/statcast2017.csv")
bayesball / shiftwork.R
Created Jun 9, 2018
Work on infield alignment data from Baseball Savant
View shiftwork.R
# load in packages
# read in Statcast data for 2018 season
sc <- read_csv("../StatcastData/statcast2018new.csv")
You can’t perform that action at this time.