Package 'Sabermetrics'
Total Page:16
File Type:pdf, Size:1020Kb
Package ‘Sabermetrics’ January 26, 2016 Type Package Title Sabermetrics Functions for Baseball Analytics Version 2.0 Date 2016-01-25 Author Peter Xenopoulos, Fernando Crema <www.peterxeno.com> Maintainer Peter Xenopoulos <[email protected]> Description A collection of baseball analytics functions for sabermetrics purposes. Among these functions include popular metrics such as FIP, wOBA, and runs created and other advanced metrics. License GPL-3 Imports XML NeedsCompilation no Repository CRAN Date/Publication 2016-01-26 14:14:00 R topics documented: sabermetrics-package . .2 babip . .3 dice .............................................4 era..............................................5 eraminus . .6 fip..............................................7 fipminus . .8 fp .............................................. 10 handedparkfactors . 11 iso.............................................. 12 lgwSB . 13 linearWeights . 14 log5............................................. 16 obp ............................................. 17 ops.............................................. 18 1 2 sabermetrics-package opsplus . 19 parkfactors . 20 pyth............................................. 22 raweqa . 23 secavg . 24 slg.............................................. 25 whip............................................. 26 woba............................................. 27 wraa............................................. 29 wrc ............................................. 30 wrcplus . 31 wsb ............................................. 33 xfip ............................................. 34 xfipminus . 35 Index 37 sabermetrics-package Sabermetrics Functions For Baseball Analytics Description A collection of baseball analytics functions for sabermetrics purposes. Among these functions include popular metrics such as wOBA, runs created functions as well as enhanced pitching metrics. Details Package: Sabermetrics Type: Package Version: 2.0 Date: 2016-01-25 License: GPL-3 Author(s) Peter Xenopoulos, Fernando Crema References Wikipedia: http://en.wikipedia.org/wiki/Sabermetrics#Examples | Reddit: http://www.reddit.com/r/Sabermetrics | Peter Xenopoulos Website: www.peterxeno.com babip 3 babip Batting Average on Balls in Play (BABIP) Description BABIP is a statistic which measures how often a non-home run batted ball falls for a hit. Usage babip(h, hr, ab, k, sf) Arguments h Hits hr Home Runs ab At Bats k Strikeouts sf Sacrifice Flies Value Returns a numerical value equal to (h-hr)/(ab-hr-k-sf) Author(s) Fernando Crema, Peter Xenopoulos References http://www.fangraphs.com/library/pitching/babip/ See Also obp,ops Examples ## Let's Calculate Mike Trout's BABIP for the 2014 season ## He had 173 Hits, 36 HR's, 602 AB's, 184 K's, and 10 SF's ## We should get .368 as our output babip(173,36,602,184,10) ## The function is currently defined as function (h, hr, ab, k, sf) { babip <- (h-hr)/(ab-hr-k-sf) return(babip) } 4 dice dice Defense-Independent Component ERA Description DICE represents a way to measure a pitcher’s performance on the ERA scale using only events a pitcher can "control" Usage dice(hr, bb, hbp, k, ip) Arguments hr Home Runs bb Walks hbp Hit By Pitches k Strikeouts ip Innings Pitched Details DICE uses the typical ERA scale. Value Returns a value equal to (13*hr+3*bb+3*hbp-2*k)/ip + 3.0 Note Innings Pitched (IP) is commonly reported with .1 indicating 1/3 of an inning and .2 indicating 2/3 of an inning. In order for this function to be accurate, please change the decimal to .333 for 1/3 of an inning and .666 for 2/3 of an inning. Author(s) Peter Xenopoulos References https://en.wikipedia.org/wiki/Defense-Independent_Component_ERA See Also era,fip,xfip,whip era 5 Examples ## The function is currently defined as function (hr, bb, hbp, k, ip) { dice = (13 * hr + 3 * bb + 3 * hbp - 2 * k)/ip + 3 return(dice) } era Earned-Run Average (ERA) Description ERA is a basic metric used to describe a pitchers ability to prevent runs. Usage era(er, ip) Arguments er Earned Runs ip Innings Pitched Details ERA is not a perfect indicator of pitcher skill. It is highly defense dependent. Value Returns a numerical value equal to (9*er)/ip Note Innings Pitched (IP) is commonly reported with .1 indicating 1/3 of an inning and .2 indicating 2/3 of an inning. In order for this function to be accurate, please change the decimal to .333 for 1/3 of an inning and .666 for 2/3 of an inning. Author(s) Fernando Crema, Peter Xenopoulos References http://www.fangraphs.com/library/pitching/era/ 6 eraminus See Also whip,fip,xfip Examples ## Let's calculate Clayton Kershaw's ERA for the 2014 Season ## He had 39 ER's and 198.333 IP ## We should get an ERA = to 1.77 era(39,198.333) ## The function is currently defined as function (er, ip) { era <- (9 * er)/ip return(era) } eraminus ERA- Description ERA- is a park-adjusted version of ERA Usage eraminus(ERA, ParkFactor, LeagueERA) Arguments ERA Player ERA ParkFactor Park Factor LeagueERA League Average ERA Details League Average is set to 100 each season. Each point below or above 100 is one percentage point better or worse than league average. Value Returns a value equal to (ERA+(ERA-(ERA*(ParkFactor/100))))/(LeagueERA)*100 Note Park Factors can be found in the references section fip 7 Author(s) Peter Xenopoulos References http://www.fangraphs.com/library/pitching/era-fip-xfip/ http://www.fangraphs.com/guts.aspx?type=pf&teamid=0&season=2014 See Also era,fipminus,xfipminus Examples ## The function is currently defined as function (ERA, ParkFactor, LeagueERA) { eraminus <- (ERA + (ERA - (ERA * (ParkFactor/100))))/(LeagueERA) * 100 return(eraminus) } fip Field Independent Pitching (FIP) Description FIP is a statistic that measure a pitcher’s performance independent of defense. FIP uses outcomes that do not take into account a team’s defense. Usage fip(HR, BB, HBP, K, IP, year) Arguments HR Homeruns given up BB Walks given up HBP Hit by pitches given up K Strikeouts IP Innings Pitched year Season Details While FIP is not a complete representation of a pitcher’s performance, it is regarded as a better representation of performance than ERA. 8 fipminus Value Returns a numerical vector equal to ((13*HR)+(3*(BB+HBP))-(2*K))/IP + constant Constant = Season FIP Constant Note Innings Pitched (IP) is commonly reported with .1 indicating 1/3 of an inning and .2 indicating 2/3 of an inning. In order for this function to be accurate, please change the decimal to .333 for 1/3 of an inning and .666 for 2/3 of an inning. Author(s) Peter Xenopoulos References http://www.fangraphs.com/library/pitching/fip/ See Also era, whip, xfip, fipminus Examples ## Let's calculate Clayton Kershaw's 2014 FIP ## He had 9 HR's, 31 BB's, 2 HBP's, 239 K's, and 198.333 IP's ## We should get 1.81 as our output fip(9,31,2,239,198.333,2014) ## The function is currently defined as function (HR, BB, HBP, K, IP, year) { constant <- weights$cFIP[which(weights$Season == year)] fip <- ((13 * HR) + (3 * (BB + HBP)) - (2 * K))/IP + constant return(fip) } fipminus FIP- Description FIP- is a park-adjusted version of FIP Usage fipminus(FIP, ParkFactor, LeagueFIP) fipminus 9 Arguments FIP Player FIP ParkFactor Park Factor LeagueFIP League Average FIP Details League Average is set to 100 each season. Each point below or above 100 is one percentage point better or worse than league average. Value Returns a value equal to (FIP+(FIP-(FIP*(ParkFactor/100))))/(LeagueFIP)*100 Note Park Factors can be found in the references section Author(s) Peter Xenopoulos References http://www.fangraphs.com/library/pitching/era-fip-xfip/ http://www.fangraphs.com/guts.aspx?type=pf&teamid=0&season=2014 See Also fip,eraminus,xfipminus Examples ## The function is currently defined as function (FIP, ParkFactor, LeagueFIP) { fipminus <- (FIP + (FIP - (FIP * (ParkFactor/100))))/(LeagueFIP) * 100 return(fipminus) } 10 fp fp Fielding Percentage Description A measure that reflects the percentage of times a player successfully handles a batted or thrown ball. Usage fp(po, a, e) Arguments po Putouts a Assists e Errors Details Fielding percentage is not a particularly sought after defensive metric, especially with the advent of more comprehensive metrics such as UZR and DRS. Value Returns a value equal to (po+a)/(po+a+e) Note Fielding percentage is misleading in the fact that it does not account for a player’s range – that is, if a player that cannot get to a ball gives up a hit instead of having an opportunity to make an out or error. Author(s) Fernando Crema, Peter Xenopoulos References https://en.wikipedia.org/wiki/Fielding_percentage handedparkfactors 11 Examples ## Let's calculate Mike Trout's fielding percentage for 2014 ## He had PO = 383, A = 4, E = 3 ## We should get an output of .992 fp(383,4,3) ## The function is currently defined as function (po, a, e) { fp <- (po + a)/(po + a + e) return(fp) } handedparkfactors Park Factors with Handedness Description Returns hitting park factors based on handedness Usage handedparkfactors(year, team) Arguments year Season team Team Details 0 = All Teams 1 = Los Angeles Angels 2 = Orioles 3 = Boston Red Sox 4 = Chicago White Sox 5 = Cleveland Indians 6 = Detroit Tigers 7 = Kansas City Royals 8 = Minnesota Twins 9 = New York Yankees 10 = Oakland Athletics 11 = Seattle Mariners 12 = Tampa Bay Rays 13 = Texas Rangers 14 = Toronto Blue Jays 15 = Arizona Diamondbacks 12 iso 16 = Atlanta Braves 17 = Chicago Cubs 18 = Cincinnati Reds 19 = Colorado Rockies 20 = Florida Marlins 21 = Houston Astros 22 = Los Angeles Dodgers 23 = Milwaukee Brewers 24 = Washington Nationals 25 = New