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 two functions | |
source("generate_runs.R") | |
source("retro_game_work.R") | |
library(dplyr) | |
# Phillies game plays on April 16, 2023 | |
plays <- c("HR", "1B", "BB", "BB", "1B", "OUT", "1B", |
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(readr) | |
library(dplyr) | |
library(brms) | |
# read in data from Github site | |
all_data <- read_csv("https://raw.githubusercontent.com/bayesball/HomeRuns2021/main/ten_seasons_retro_hr.csv") | |
# remove all parks that are either dome or retractable |
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
plot_bivar_norm <- function(mx, my, sx, sy, r){ | |
require(ggplot2) | |
logbinorm <- function (x, y, par) { | |
m <- par$m | |
v <- par$v | |
zx <- (x - m[1]) / sqrt(v[1, 1]) | |
zy <- (y - m[2]) / sqrt(v[2, 2]) | |
r <- v[1, 2] / sqrt(v[1, 1] * v[2, 2]) |
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
--- | |
title: "ChatGPT Examples" | |
format: html | |
editor: visual | |
--- | |
## Collecting Cards | |
_Write R function to illustrate baseball card collection problem._ |
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
# reference | |
# https://billpetti.github.io/baseballr/articles/baseballr.html#follow-the-sportsdataverse-on-twitter-and-star-this-repo | |
library(baseballr) | |
# ----------------------------------------------------- | |
# Retrosheet data | |
# ----------------------------------------------------- | |
# acquire retro play-by-play data for seasons 2020:2022 |
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 required packages | |
library(dplyr) | |
library(ggplot2) | |
library(CalledStrike) | |
library(janitor) | |
library(ShinyBaseball) | |
library(readr) | |
# collect mlb ids from two pitchers |
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 required packages | |
library(purrr) | |
library(ggplot2) | |
library(tidyr) | |
library(dplyr) | |
# read in modeling functions | |
source("fit_model.R") |
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(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 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
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 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
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 |