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
################################################## | |
# collect all pitches of Cliff Lee for 2013 season | |
# using pitchRx package | |
################################################### | |
# create database of 2013 pitches | |
# library(dplyr) | |
# my_db <- src_sqlite("pitchRx.2013", create = TRUE) | |
# library(pitchRx) |
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
# Cliff Lee's pitches in first game of 2014 season | |
# March 31, 2014 | |
# scrape all Gameday data for that day | |
library(pitchRx) | |
d <- scrape("2014-03-31", "2014-03-31") | |
# pick out the Cliff Lee pitch data | |
library(dplyr) |
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
########################################## | |
# the first pitch effect | |
# preview of Chapter 7 material in ABDWR | |
########################################## | |
# load in Retrosheet 2013 play-by-play data | |
# (have to download Retrosheet data and add run values) | |
load("pbp2013.Rdata") |
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
# Cubs / White Sox attendance study | |
# assume that Retrosheet game log files | |
# gl1900.txt, gl1901.txt, ... are | |
# contained in folder gamelogs | |
# the files gl1954.txt through gl2013.txt are used in this code | |
get.data <- function(team, Seasons){ | |
data <- NULL | |
for (year in Seasons){ | |
filename <- paste("gamelogs/gl",year,".txt", sep="") |
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
#---------------------------------------------- | |
# R code for Bayesian Computation Webinar | |
# Jim Albert - June 12, 2014 | |
# albert@bgsu.edu | |
#---------------------------------------------- | |
#---------------------------------------------- | |
# PART I: Bayesian Robust Regression Modeling | |
# Require packages foreign, LearnBayes, coda, ggplot2 | |
#---------------------------------------------- |
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
#---------------------------------------------- | |
# R code for Bayesian Computation Webinar | |
# Jim Albert - June 12, 2014 | |
# albert@bgsu.edu | |
#---------------------------------------------- | |
#---------------------------------------------- | |
# PART II: Posterior-Predictive Model Checking | |
# Require packages pscl, arm, MASS | |
#---------------------------------------------- |
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
#---------------------------------------------- | |
# R code for Bayesian Computation Webinar | |
# Jim Albert - June 12, 2014 | |
# albert@bgsu.edu | |
#---------------------------------------------- | |
#--------------------------------------------------------------------- | |
# PART III: INTRODUCTION TO JAGS | |
# Negative binomial regression | |
# Example from Jackman, 2009 |
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
#---------------------------------------------- | |
# R code for Bayesian Computation Webinar | |
# Jim Albert - June 12, 2014 | |
# albert@bgsu.edu | |
#---------------------------------------------- | |
################################################## | |
# PART IV: JAGS for Multilevel Modeling | |
# Require R packages Lahman, rjags, ggplot2 | |
################################################## |
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 variable names for game log dataset | |
Headers <- c("Date", "DoubleHeader", | |
"DayOfWeek", "VisitingTeam", | |
"VisitingTeamLeague", "VisitingTeamGameNumber", | |
"HomeTeam", "HomeTeamLeague" , | |
"HomeTeamGameNumber", "VisitorRunsScored" , | |
"HomeRunsScore", "LengthInOuts", | |
"DayNight", "CompletionInfo", | |
"ForfeitInfo", "ProtestInfo" , |
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(Lahman) | |
library(dplyr) | |
fielding.2b <- filter(Fielding, POS=="2B", yearID >= 1960) | |
rf.season.2b <- summarize(group_by(fielding.2b, yearID), | |
RF.9 = 9 * (sum(PO, na.rm=TRUE) + | |
sum(A, na.rm=TRUE)) / | |
(sum(InnOuts / 3, na.rm=TRUE))) |