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
# load in required packages | |
library(dplyr) | |
library(ggplot2) | |
library(CalledStrike) | |
library(janitor) | |
library(ShinyBaseball) | |
library(readr) | |
# collect mlb ids from two pitchers |
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
# load in required packages | |
library(purrr) | |
library(ggplot2) | |
library(tidyr) | |
library(dplyr) | |
# read in modeling functions | |
source("fit_model.R") |
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(dplyr) | |
library(ggplot2) | |
library(geomtextpath) | |
library(readr) | |
# datasets are read from a Github respository | |
fg_batting <- read_csv("https://raw.githubusercontent.com/bayesball/HomeRuns2021/main/fgbatting_complete.csv") | |
hof <- read_csv("https://raw.githubusercontent.com/bayesball/HomeRuns2021/main/hofdata.csv") | |
hof_candidates <- read_csv("https://raw.githubusercontent.com/bayesball/HomeRuns2021/main/hofdata_candidates.csv") | |
hof_cand_batting <- filter(hof_candidates, |
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
estimate_batting <- function(retro_final_PA_1990_2020d, | |
season, | |
s_woba = 0.5){ | |
require(dplyr) | |
require(LearnBayes) | |
retro_final_PA_1990_2020d %>% | |
filter(YEAR == season) -> retroseason | |
retroseason %>% | |
group_by(BAT_ID) %>% | |
summarize(PA = n(), |
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
get_hr_data <- function(pred_season, | |
retro_data, | |
n_prev_seasons = 4, | |
mPA = 1000, | |
mPA_season = 200){ | |
# n_prev_seasons is number of previous seasons | |
# mPA is the minimum number of cumulative PA | |
# retrodata - Retrosheet data for current season | |
# mPA_season - minimum number of PA in both |
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
prediction_work <- function(seasons, | |
mPA = 1000, | |
retrodata, | |
mPA_season = 200){ | |
# seasons is a vector of previous seasons | |
# mPA is the minimum number of cumulative PA | |
# retrodata - Retrosheet data for current season | |
# mPA_season - minimum number of PA in both | |
# halves of current season |
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
sac_fly_work <- function(sc, season){ | |
# load required packages | |
require(dplyr) | |
require(ggplot2) | |
require(metR) | |
require(mgcv) | |
require(CalledStrike) | |
# define location, distance, and spray angle vars |
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
# load in Retrosheet pbp data frames | |
# for seasons 2011 through 2021 | |
library(Lahman) | |
library(dplyr) | |
library(ggplot2) | |
# get Mike Trout's retro id from the People | |
# data frame in Lahman package |
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
data_work <- function(){ | |
require(readr) | |
require(dplyr) | |
require(lubridate) | |
sc_2021 <- read_csv("https://raw.githubusercontent.com/bayesball/HomeRuns2021/main/statcast2021.csv") | |
sc_2022 <- read_csv("https://raw.githubusercontent.com/bayesball/HomeRuns2021/main/statcast_2022.csv") | |
sc_old <- read_csv("https://raw.githubusercontent.com/bayesball/HomeRuns2021/main/SC_BB_mini.csv") | |
names(sc_old)[2] <- "Game_Date" |
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
# using Statcast data for the 2021 season | |
# two functions plot_xb_contour_work() and | |
# plot_woba_contour_work() implement the | |
# logistic and ordinal fitting algorithms | |
# ggplot2 code is used to show the barrel | |
# region over the (launch speed, launch angle) | |
# space |