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
| # loads in data frame d2015 | |
| # Retrosheet play-by-play data for 2015 season | |
| load(url("http://www-math.bgsu.edu/~albert/retrosheet/pbp.2015.Rdata")) | |
| # function will extract 1/0 data for a specific batter and a particular outcome | |
| get_streak_data <- function(retrodata, batter, outcome){ | |
| require(dplyr) | |
| require(Lahman) |
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
| # Interesting table that presents the number of 2016 MLB players | |
| # from each of 50 US States. | |
| # http://www.baseball-almanac.com/players/birthplace.php?y=2016 | |
| # Interested in mapping the data | |
| # Use XML package to read in data | |
| library(XML) |
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_data <- function(pitcher){ | |
| require(Lahman) | |
| require(dplyr) | |
| get.birthyear <- function(player.id){ | |
| playerline <- filter(Master, playerID == player.id) | |
| birthyear <- playerline$birthYear | |
| birthmonth <- playerline$birthMonth | |
| ifelse(birthmonth >= 7, birthyear + 1, birthyear) | |
| } | |
| names <- unlist(strsplit(pitcher, " ")) |
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
| compare_obp_trajectories <- function(players){ | |
| require(Lahman) | |
| require(dplyr) | |
| require(LearnBayes) | |
| require(ggplot2) | |
| library(ggthemes) | |
| get_data <- function(batter, playerid=FALSE){ | |
| get.birthyear <- function(player.id){ | |
| playerline <- filter(Master, playerID == player.id) |
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: "Adjusting SLG" | |
| author: "Jim Albert" | |
| date: "December 17, 2016" | |
| output: | |
| html_document: default | |
| html_notebook: default | |
| --- | |
| ```{r global_options, include=FALSE} |
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
| # stolen base study | |
| # look at SB and SB Attempts | |
| # downloading Retrosheet data and computing runs values | |
| # using two helper functions | |
| # see https://baseballwithr.wordpress.com/2014/02/10/downloading-retrosheet-data-and-runs-expectancy/ | |
| # for specific instructions on downloading Retrosheet data | |
| library(devtools) |
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
| # game log data available at | |
| # http://www.retrosheet.org/gamelogs/index.html | |
| # csv file with headers available at | |
| # https://github.com/maxtoki/baseball_R/blob/master/data/game_log_header.csv | |
| # my gamelog data for the 2016 season stored in | |
| # data frame d | |
| # this is some theme information that I'll using in | |
| # my ggplot2 plots |
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
| platoon_dist2 <- function(pbpdata, season, data=FALSE){ | |
| require(dplyr) | |
| require(ggplot2) | |
| require(Lahman) | |
| d_PA <- filter(pbpdata, BAT_EVENT_FL==TRUE) | |
| S_left <- summarize(group_by(filter(d_PA, | |
| BAT_HAND_CD=="L"), BAT_ID), | |
| Opp=sum(PIT_HAND_CD=="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
| --- | |
| title: "Is David Ortiz Clutch?" | |
| output: | |
| html_document: default | |
| html_notebook: default | |
| --- | |
| Read in Retrosheet data for the 2000 through the 2013 seasons. | |
| Also read in the compute.runs function. |
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
| model_data_simulation <- function(P_vector, | |
| mystat=sum, | |
| N=100, | |
| N_sim=10000){ | |
| require(ggplot2) | |
| TH <- theme( | |
| plot.title = element_text( | |
| colour = "red", | |
| size = 14, | |
| hjust = 0.5, |