Skip to content

Instantly share code, notes, and snippets.

Avatar

Jim Albert bayesball

View GitHub Profile
@bayesball
bayesball / setup_work.R
Created Dec 27, 2020
R function that provides new variables indicating if plate appearance goes through each possible count.
View setup_work.R
setup_work <- function(d2015){
# d2015 is a Retrosheet play by play dataset
# removes all non-pitches from PITCH_SEQ_TX
d2015$pseq <- gsub("[.>123N+*]", "", d2015$PITCH_SEQ_TX)
# create a b and s sequence
d2015$pseq <- gsub("[BIPV]", "b", d2015$pseq)
d2015$pseq <- gsub("[CFKLMOQRST]", "s", d2015$pseq)
one.string3 <- function(ex, count){
@bayesball
bayesball / called_strike_demo.R
Created Nov 27, 2020
R code for illustration of Called Strike package
View called_strike_demo.R
# here are the packages I'm using
# CalledStrike depends on other packages
library(CalledStrike)
library(readr)
library(dplyr)
library(ggplot2)
# read in Statcast data for the 2019 season
@bayesball
bayesball / density_estimates.Rmd
Created Nov 20, 2020
Illustrate of bivariate density estimates on 2019 Statcast data
View density_estimates.Rmd
---
title: "Some Density Estimates"
output:
html_document:
df_print: paged
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
message = FALSE,
@bayesball
bayesball / pitch_selection.Rmd
Created Oct 31, 2020
Using tabyls() function to explore pitch selection in the 2020 World Series
View pitch_selection.Rmd
---
title: "tabyls"
author: "Jim Albert"
date: "10/27/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
warning = FALSE,
@bayesball
bayesball / gist:4302c5309bdd5cb8a307612804d3a41b
Created Oct 19, 2020
Predicting the Number of Home Runs Hit in a Playoff Series
View gist:4302c5309bdd5cb8a307612804d3a41b
---
title: "Home Run Prediction"
author: "Jim Albert"
date: "10/14/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
message = FALSE,
@bayesball
bayesball / statcast_streaky.Rmd
Created Oct 10, 2020
Streaky measures of hitting from Statcast data.
View statcast_streaky.Rmd
---
title: "Statcast Streaky Analysis"
author: "Jim Albert"
date: "10/5/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
message = FALSE,
View app.R
library(shiny)
library(ggplot2)
library(ProbBayes)
library(dplyr)
library(tidyr)
library(gridExtra)
library(runjags)
library(coda)
# Define UI ----
@bayesball
bayesball / baseball_scores.R
Last active Sep 19, 2020
Code to download Retrosheet game log data with the focus on studying game scores.
View baseball_scores.R
# Main function to get Retrosheet game scores
get_scores <- function(season){
require(dplyr)
require(readr)
load_gamelog <- function(season) {
glheaders <- read_csv("https://raw.githubusercontent.com/beanumber/baseball_R/master/data/game_log_header.csv")
remote <- paste0("http://www.retrosheet.org/gamelogs/gl",
season, ".zip")
local <- paste0("gl", season, ".zip")
@bayesball
bayesball / app.R
Created Sep 13, 2020
Shiny app for fitting a binomial-beta multilevel model
View app.R
library(shiny)
library(ggplot2)
library(ProbBayes)
library(metR)
library(dplyr)
library(tidyr)
library(gridExtra)
# Define UI ----
ui <- fluidPage(
@bayesball
bayesball / app.R
Last active Sep 2, 2020
testing a shiny app
View app.R
library(shiny)
library(ggplot2)
library(ProbBayes)
require(metR)
# Define UI ----
ui <- fluidPage(
# titlePanel("Visualizing Posterior of Two Proportions"),
h1(id="big-heading", "Visualizing Posterior of Two Proportions"),
tags$style(HTML("#big-heading{color: red;}")),
You can’t perform that action at this time.