This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
This file contains hidden or 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
| # read in three packages | |
| library(readr) | |
| library(dplyr) | |
| library(ggplot2) | |
| # helper ggplot2 function | |
| helper_ggplot <- function(){ | |
| theme(text=element_text(size=18)) + |
This file contains hidden or 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 packages | |
| library(readr) | |
| library(dplyr) | |
| library(lme4) | |
| library(ggplot2) | |
| library(posterior) | |
| library(gridExtra) | |
| library(Lahman) |
This file contains hidden or 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 packages | |
| library(readr) | |
| library(dplyr) | |
| library(brms) | |
| library(ggplot2) | |
| library(posterior) | |
| library(gridExtra) | |
| library(Lahman) |
This file contains hidden or 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
| # preparation work for FanGraphs leaderboard data | |
| # collected FanGraphs Leaderboard batting data | |
| # choose Multiple Seasons (all), Split Seasons | |
| # minimum 100 PA in each season | |
| # download data and saved as "fgbatting.csv" | |
| library(dplyr) | |
| library(readr) | |
| library(Lahman) |
This file contains hidden or 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(shiny) | |
| library(ggplot2) | |
| library(dplyr) | |
| library(readr) | |
| # read in Retrosheet data for two seasons | |
| d <- read_csv("retro_2seasons_ip.csv") | |
| # main drawing function |