View player_function_lb.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
player_function_lb <- function(player_id){ | |
# uses LearnBayes package to simulate from | |
# multilevel model | |
library(dplyr) | |
library(ggplot2) | |
library(Lahman) | |
library(LearnBayes) |
View blog_code_example.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
# 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", |
View blog_code.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(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 |
View plot_bivar_norm.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
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]) |
View ChatGPT_examples.qmd
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
--- | |
title: "ChatGPT Examples" | |
format: html | |
editor: visual | |
--- | |
## Collecting Cards | |
_Write R function to illustrate baseball card collection problem._ |
View baseballr_examples.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
# 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 |
View two_astros.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
# load in required packages | |
library(dplyr) | |
library(ggplot2) | |
library(CalledStrike) | |
library(janitor) | |
library(ShinyBaseball) | |
library(readr) | |
# collect mlb ids from two pitchers |
View RunMe.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
# load in required packages | |
library(purrr) | |
library(ggplot2) | |
library(tidyr) | |
library(dplyr) | |
# read in modeling functions | |
source("fit_model.R") |
View app.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, |
View estimate_batting.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
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(), |
NewerOlder