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
compute_expected_runs <- function(events){ | |
# function computes expected runs for event table | |
# obtained via statsapi.mlb.com | |
require(dplyr) | |
# find the total runs scored and number of outs each half-inning | |
events |> | |
group_by(game_id, inning, half_inning) |> | |
summarize(max_runs = sum(runs_on_event), | |
total_outs = sum(post_outs - pre_outs), |
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_standings <- function(s_date, e_date){ | |
require(sabRmetrics) | |
require(dplyr) | |
Teams <- c("Chicago White Sox", "Cleveland Guardians", | |
"Detroit Tigers", "Kansas City Royals", | |
"Minnesota Twins", "Baltimore Orioles", | |
"Boston Red Sox", "New York Yankees", | |
"Tampa Bay Rays", "Toronto Blue Jays", | |
"Houston Astros", "Los Angeles Angels", |
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
fit_norm_mix_model <- function(pname, statcast){ | |
require(dplyr) | |
require(LearnBayes) | |
library(magrittr) | |
logpost <- function(theta, y){ | |
mu1 <- theta[1] | |
sigma1 <- exp(theta[2]) | |
mu2 <- theta[3] | |
sigma2 <- exp(theta[4]) | |
p <- exp(theta[5]) / (1 + exp(theta[5])) |
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_normal <- function(S, games, f_games){ | |
# data frame S contains batter, BIP, HR for | |
# first part of season | |
# games - average number of games already played | |
# f_games - number of future games played | |
# need to have the JAGS software installed | |
# https://mcmc-jags.sourceforge.io/ | |
library(readr) |
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: "Count Effects Model" | |
format: html | |
editor: visual | |
--- | |
Illustration of Bayesian fitting of a multilevel model for situational data using JAGS software. | |
Read in Statcast data from the first half of the 2023 season. | |
Reference: Albert, Jim (2024). Bayesian Workflow of a Situational Random Effects Model |
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 some packages | |
library(dplyr) | |
library(ggplot2) | |
library(mgcv) | |
library(janitor) | |
library(metR) | |
# have Statcast data through games of April 5, 2024 |
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: "Retrosheet Package - Comparing Count Rates for Two Seasons" | |
format: html | |
editor: visual | |
--- | |
Load packages for this particular run. | |
```{r} | |
#| message: FALSE | |
library(abdwr3edata) |
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
# live version of Shiny app | |
# https://bayesball.shinyapps.io/fg2023_discipline/ | |
library(shiny) | |
library(mlbplotR) | |
library(dplyr) | |
library(ggplot2) | |
library(readr) | |
# data work |
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: "Zach Wheeler 2023 NCS" | |
format: html | |
editor: visual | |
--- | |
Load in necessary packages: | |
```{r} | |
library(baseballr) |
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) |
NewerOlder