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 12 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 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
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
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 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
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 York Mets 26 = Philadelphia Phillies 27 = Pittsburgh Pirates 28 = St. Louis Cardinals 29 = San Diego Padres 30 = San Francisco Giants
Value
Returns a dataframe with park factors
Author(s) Peter Xenopoulos References http://www.fangraphs.com/guts.aspx?type=pfh&teamid=0&season=2014 See Also parkfactors Examples
## To get all of 2014 Park Factors # handedparkfactors(2014)
## To get all of the Angels' Park Factors # handedparkfactors(2014,1)
iso Isolated Power
Description
lgwSB 13 Usage
iso(slg, avg) Arguments
slg Slugging Percentage
avg Batting Average
Value
Returns a numerical value equal to SLG-AVG Author(s) Peter Xenopoulos References http://www.fangraphs.com/library/offense/iso/ See Also opsplus,ops Examples
## Let's calculate Mike Trout's isolated power in 2014 ## He had a SLG = .561 and an AVG = .287
## We should get .274 iso(.561,.287)
## The function is currently defined as function (slg, avg) { iso <- slg - avg return(iso) } lgwSB League wSB Description
This function helps find the League wSB Usage
14 linearWeights Arguments
year Season
SB League Stolen Bases
CS League Caught Stealing
single Singles
bb Walks
hbp Hit By Pitches
ibb Intentional Walks Value
Returns a value equal to (SB * runSB + CS * runCS) / (single + bb + hbp - ibb) Author(s) Peter Xenopoulos References http://www.fangraphs.com/library/offense/wsb/ See Also wsb Examples
## The function is currently defined as function (year, SB, CS, single, bb, hbp, ibb) {
runSB <- linearWeights$runSB[which(linearWeights$Season == year)]
runCS <- linearWeights$runCS[which(linearWeights$Season == year)]
lgwSB <- (SB * runSB + CS * runCS)/(single + bb + hbp - ibb) }
linearWeights Linear Weights Dataset
Description
This is a dataset containing useful yearly metrics from FanGraphs. Usage
linearWeights 15 Format
A data frame with seasonal data going back to 1871. Contains 14 variables. Season 1871-Present
wOBA Season Average wOBA
wOBAScale Season wOBA Scaling Factor wBB Weight of an walk
wHBP Weight of a hit by pitch w1B Weight of a single w2B Weight of a double w3B Weight of a triple wHR Weight of a home run runSB Weight of a stolen base
runCS Weight of being caught stealing RPerPA Runs Per Plate Appearance RPerW Runs Per Win
cFIP Season FIP constant Details
This dataset is useful for calculating season-dependent metrics such as wOBA and FIP.
Source
http://www.fangraphs.com/guts.aspx?type=cn
References
http://www.fangraphs.com/
Examples
## Give the last 5 years head(linearWeights, 5)
16 log5
log5 Log5
Description
Log5 is a way to estimate the probability that Team A will win a game given the true winning probabilities of Team A and Team B
Usage
log5(pA, pB, order = 0) Arguments
pA Probability that A wins pB Probability that B wins order 0 = A over B and 1 = B over A Value
Returns a value equal to (pA-pA*pB)/(pA+pB-2*pA*pB) Author(s)
Fernando Crema, Peter Xenopoulos References
https://en.wikipedia.org/wiki/Log5 See Also
pyth
Examples
## Let's assume team A has a .60 true probability of winning ## Let's assume team B has a .40 true probability of winning ## We should get an output of 0.6923
log5(.60,.40)
## The function is currently defined as function (pA, pB, order = 0)
{
if (order) { aux = pB pB = pA pA = aux
obp 17
}
log5 <- (pA - pA * pB)/(pA + pB - 2 * pA * pB) return(log5)
}
obp On-Base Percentage
Description
The OBP function calculates how often a player gets on base.
Usage
obp(H, BB, HBP, AB, SF) Arguments
H Number of Hits
BB Number of bases on balls (walks) HBP Number of hit by pitches
AB Number of at bats
SF Number of sacrifice flies Value
Returns a numerical value equal to ((H+BB+HBP)/(AB+BB+SF+HBP))
Author(s) Peter Xenopoulos References https://en.wikipedia.org/wiki/On-base_percentage See Also ops
18 ops Examples
## Let's calculate Mike Trout's OBP for the 2014 season
## He had 173 hits, 83 bases on balls, 10 hit by pitches, 602 at bats, and 10 sacrifice flies ## We should get 0.377 as our output
obp(173,83,10,602,10)
## The function is currently defined as function (H, BB, HBP, AB, SF)
{
onbase <- ((H + BB + HBP)/(AB + BB + SF + HBP)) return(onbase)
}
ops On-Base Plus Slugging
Description
A metric that protrays a hitter’s ability to get on base and to hit for power.
Usage
ops(slg, obp) Arguments
slg Slugging Percentage obp On-Base Percentage Value
Returns a numerical value equal to (OBP)+(SLG)
Author(s) Peter Xenopoulos References http://www.fangraphs.com/library/offense/ops/ https://en.wikipedia.org/wiki/On-base_plus_slugging See Also opsplus,obp
opsplus 19 Examples
## Let's calculate Mike Trout's OPS for the 2014 season ## He had an OBP = .377 and a SLG = .561
## We should get .938 as our output ops(.561,.377)
## The function is currently defined as function (slg, obp) { ops <- slg + obp return(ops) } opsplus OPS+ Description
A useful metric to describe a hitter’s ability in terms of the league. Usage
opsplus(obp, slg, lgOBP, lgSLG) Arguments
obp On-base percentage slg Slugging percentage
lgOBP League OBP
lgSLG League Slugging Percentage Value
Returns a numerical value equal to ((obp/lgOBP)+(slg/lgSLG)-1)*100
100 = League Average 90 = 10 percent BELOW League Average 110 = 10 percent ABOVE League Average Author(s) Peter Xenopoulos References http://sports.yahoo.com/mlb/blog/big_league_stew/post/Everything-you-always-wanted-to-know-about-OPS-?urn=mlb,204667 http://www.fangraphs.com/library/offense/ops/
20 parkfactors See Also
ops,slg,obp
Examples
## Let's calculate Mike Trout's 2014 OPS+ ## He had an OBP = .377 and a SLG = .561 ## League OBP = .316 and League SLG = .404 ## We should get 158.1652 as our output opsplus(.377,.561,.316,.404)
## The function is currently defined as function (obp, slg, lgOBP, lgSLG) {
opsplus <- ((obp/lgOBP) + (slg/lgSLG) - 1) * 100 return(opsplus)
}
parkfactors Park Factors
Description
A function used to generate the park factors for a given season/team Usage parkfactors(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
parkfactors 21 12 = Tampa Bay Rays
13 = Texas Rangers 14 = Toronto Blue Jays 15 = Arizona Diamondbacks 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 York Mets 26 = Philadelphia Phillies 27 = Pittsburgh Pirates 28 = St. Louis Cardinals 29 = San Diego Padres 30 = San Francisco Giants
Value
Returns a data frame with the respective park factors
Author(s) Peter Xenopoulos References http://www.fangraphs.com/guts.aspx?type=pf&teamid=0&season=2014 See Also handedparkfactors Examples
## To get all of 2014 Park Factors # parkfactors(2014)
## To get all of the Angels' Park Factors # parkfactors(2014,1)
22 pyth
pyth Pythagorean Expectation
Description
Pythagorean expectation portrays what a team’s winning percentage "should" be given it’s runs scored and allowed.
Usage
pyth(rs, ra, alpha = 2) Arguments
rs Runs Scored
ra Runs Allowed
alpha Exponent to use Details
2 and 1.83 are the most common exponents used. 1.83 is the exponent baseball-reference uses in its calculations.
Value
Returns a value equal to (rs^alpha)/(rs^alpha + ra^alpha)
Note
Pythagorean expectation can be used in a multitude of sports like basketball and football
Author(s) Peter Xenopoulos References http://www.fangraphs.com/library/principles/expected-wins-and-losses/ https://en.wikipedia.org/wiki/Pythagorean_expectation See Also log5
raweqa 23 Examples
## Let's calculate the Angels 2014 Pythagorean Expectation ## The Angels had 773 Runs Scored and 630 Runs Allowed ## We should get an output close to .600
pyth(773,630,2)
## The function is currently defined as function (rs, ra, alpha = 2)
{
pyth <- (rs^alpha)/(rs^alpha + ra^alpha) return(pyth)
}
raweqa Raw Equivalent Average
Description
Raw Equivalent Average is used to calculate Equivalent Average Usage raweqa(AB, H, TB, BB, IBB, HBP, CS, SB, SH, SF) Arguments AB At Bats H Hits TB Total Bases BB Unintentional Walks IBB Intentional Walks
HBP Hit By Pitches CS Caught Stealing SB Stolen Bases SH Sacrifice Hits SF Sacrifice Flies Value
Returns a numerical value equal to (H+TB+1.5*(BB+HBP+SB)+SH+SF-IBB/2)/(AB+BB+HBP+SH+SF+CS+SB) Author(s)
24 secavg References
https://www.baseballprospectus.com/glossary/index.php?mode=viewstat&stat=61 See Also
ops,slg,obp,iso,babip
Examples
## The function is currently defined as
function (AB, H, TB, BB, IBB, HBP, CS, SB, SH, SF) {
raweqa <- (H + TB + 1.5 * (BB + HBP + SB) + SH + SF - IBB/2)/(AB + BB + HBP + SH + SF + CS + SB)
return(raweqa) }
secavg Secondary Average
Description
Secondary average measure the sum of extra bases gained on hits, walks and stolen bases. Usage secavg(ab, bb, tb, h, sb, cs) Arguments ab At Bats bb Walks tb Total Bases h Hits sb Stolen Bases cs Caught Stealing Details
SecAvg shares no correlation with batting average although overall league averages are inclined to correspond with league batting averages.
Value
slg 25 Author(s) Peter Xenopoulos References https://en.wikipedia.org/wiki/Secondary_average See Also ops,slg,iso Examples
## The function is currently defined as function (ab, bb, tb, h, sb, cs) { SecA <- (bb + tb - h + sb - cs)/ab return(SecA) } slg Slugging Percentage Description
Slugging percentage is a measure of a hitter’s power.
Usage slg(TB, AB) Arguments TB Total Bases AB At Bats Value
Returns a numerical value equal to (TB/AB)
This is also equivalent to ((singles) + (2 x doubles) + (3 x triples) + (4 x homeruns))/(AB)
Author(s)
26 whip References https://en.wikipedia.org/wiki/Slugging_percentage See Also opsplus,ops Examples
## Let's calculate Mike Trout's SLG for the 2014 season ## He had 338 TB's and 602 AB's
## We should get .561 as our output slg(338,602)
## The function is currently defined as function (TB, AB) { slugging <- (TB/AB) return(slugging) } whip WHIP Description
WHIP (Walks + Hits Per Innings Pitched) describes how many base runners a pitcher gives up an inning. Usage whip(h, bb, ip) Arguments h Hits bb Walks ip Innings Pitched Details
WHIP is not a perfect indicator of pitcher skill. It is highly defense dependent. Hit rates are largely outside of pitcher control and have high fluctuations.
Value
woba 27 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/whip/
https://en.wikipedia.org/wiki/Walks_plus_hits_per_inning_pitched
See Also
era,fip,dice,xfip
Examples
## Let's look at Clayton Kershaw's WHIP for the 2014 season ## He gave up H = 139 and BB = 31 and pitched 198.33 innings ## We should get an output of 0.857
whip(139,31,198.33)
## The function is currently defined as function (h, bb, ip)
{
whip <- (h + bb)/ip return(whip) }
woba Weighted On-Base Average (wOBA)
Description
wOBA is a statistic which attempts to credit a batter for each outcome. It is reported as a rate.
Usage
28 woba Arguments
year Season to use as context
AB At Bats
BB Unintentional Walks IBB Intentional Walks
HBP Hit By Pitches single Singles double Doubles triple Triples HR Home Runs SF Sacrifice Flies Details
The linear weights used for this equation are in thelinearWeightsdataframe. Value
Returns a numeric value equal to ((wBB*BB)+(wHBP*HBP)+(w1B*single)+(w2B*double)+(w3B*triple)+(wHR*HR))/(AB+BB-IBB+SF+HBP) where wXX means weight of XX
Note
wOBA is regarded as a better representation of a hitter’s skill than batting average or obp. Author(s) Peter Xenopoulos References http://www.fangraphs.com/library/offense/woba/ See Also obp,wraa Examples
## Let's calculate Mike Trout's 2014 wOBA ## He had 602 AB's, 83 BB's, 6 IBB's, 10 HBP's,
## 89 singles, 39 doubles, 9 triples, 36 homeruns, and 10 sac-flies ## We should get .408 as our output
woba(2014,602,83,6,10,89,39,9,36,10) ## The function is currently defined as
wraa 29 SF) { wBB <- linearWeights$wBB[which(weights$Season == year)] wHBP <- linearWeights$wHBP[which(weights$Season == year)] w1B <- linearWeights$w1B[which(weights$Season == year)] w2B <- linearWeights$w2B[which(weights$Season == year)] w3B <- linearWeights$w3B[which(weights$Season == year)] wHR <- linearWeights$wHR[which(weights$Season == year)] woba <- ((wBB * BB) + (wHBP * HBP) + (w1B * single) + (w2B *
double) + (w3B * triple) + (wHR * HR))/(AB + BB - IBB + SF + HBP)
return(woba) }
wraa Weighted Runs Above Average
Description
wRAA measure the number of offensive runs a player contributes compared to an average player. Usage
wraa(woba, year, PA) Arguments
woba Weighted On Base Percentage. Seewoba
year Season
PA Plate Appearances
Details
wRAA is league adjusted, meaning you can use it to compare players from different leagues and years.
Value
Returns a value equal to ((wOBA - league wOBA) / wOBA scale) x PA Note
Usually, Ten wRAA is equivalent to +1 win. Author(s)
30 wrc References http://www.fangraphs.com/library/offense/wraa/ See Also woba Examples
## Let's calculate Mike Trout's 2014 wRAA ## He had a wOBA of .402 and 705 PA's ## We should return 49.74
wraa(.402,2014,705)
## The function is currently defined as function (woba, year, PA)
{
wraa <- ((woba - linearWeights$wOBA[which(linearWeights$Season == year)])/weights$wOBAScale[which(linearWeights$Season == year)]) * PA
return(wraa) }
wrc Weighted Runs Created
Description
Weighted Runs Created is a statistic which attempts to credit a hitter for the value of each outcome. Usage
wrc(wOBA, PA, year) Arguments
wOBA Weighted On Base Average
PA Plate Appearances
year Season
Details
wRC is reported with runs as the units Value
Returns a value equal to (((wOBA-linearWeights$wOBA[which(linearWeights$Season == year)])/linearWeights$wOBAScale[which(linearWeights$Season == year)])+weights$RPerPA[which(linearWeights$Season == year)])*PA
wrcplus 31 Note
wRC is considered a better representation of offensive value than something likeops
Author(s)
Peter Xenopoulos
References
http://www.fangraphs.com/library/offense/wrc/
See Also
woba,wraa,wrcplus
Examples
## Let's calculate Mike Trout's 2014 wRC ## He had a wOBA of .402 and 705 PA's ## We should return 125.879
wrc(.402,705,2014)
## The function is currently defined as function (wOBA, PA, year)
{ wrc <- (((wOBA - linearWeights$wOBA[which(linearWeights$Season == year)])/linearWeights$wOBAScale[which(linearWeights$Season == year)]) + weights$RPerPA[which(linearWeights$Season == year)]) * PA return(wrc) } wrcplus wRC+ Description
wRC+ is a statistic which attempts to credit a hitter for the value of each outcome.
Usage
32 wrcplus Arguments
wRAA Weighted Runs Above Average (seewraa)
PA Plate Appearances
year Season
parkfactor Park Factor leaguewRC League wRC Details
wRC+ is scaled so that league average is 100, and each point above or below 100 is 1 percentage point better or worse than league average
Value
Returns a value equal to (((wRAA/PA + leaguerpa)+(leaguerpa-parkfactor*leaguerpa))/leaguewRC)*100
Note
wRC+ is a commonly used offensive statistic
Author(s) Peter Xenopoulos References http://www.fangraphs.com/library/offense/wrc/ See Also wraa,woba,wrc Examples
## The function is currently defined as
function (wRAA, PA, year, parkfactor, leaguewRC) {
leaguerpa <- linearWeights$RPerPA[which(linearWeights$Season == year)]
wrcplus <- (((wRAA/PA + leaguerpa) + (leaguerpa - parkfactor * leaguerpa))/leaguewRC) * 100
wsb 33
wsb wSB
Description
wSB is the estimated number of runs a player contributes by stealing bases as compared to the average player.
Usage
wsb(year, SB, CS, lgwSB, single, bb, hbp, ibb) Arguments year Season SB Stolen Bases CS Caught Stealing lgwSB League wSB single Singles bb Walks hbp Hit By Pitches
ibb Intentional Walks Details
wSB is useful because it attaches a value to a player’s SB count
Value
Returns a value equal to (SB * runSB) + (CS * runCS) - (lgwSB * (single + bb + hbp - ibb))
Author(s) Peter Xenopoulos References http://www.fangraphs.com/library/offense/wsb/ See Also lgwSB
34 xfip Examples
## The function is currently defined as
function (year, SB, CS, lgwSB, single, bb, hbp, ibb) {
runSB <- linearWeights$runSB[which(linearWeights$Season == year)]
runCS <- linearWeights$runCS[which(linearWeights$Season == year)]
wsb <- (SB * runSB) + (CS * runCS) - (lgwSB * (single + bb + hbp - ibb))
}
xfip xFIP
Description
xFIP is a statistic that estimates a pitcher’s expected run prevention independent of the performance of the defense.
Usage
xfip(flyballs, lgHRFB, BB, HBP, K, ip, year) Arguments
flyballs Fly balls allowed
lgHRFB League HR/FB Percentage
BB Balls Allowed
HBP Hit By Pitches Allowed
K Strikeouts
ip Innings Pitched
year Season
Details
xFIP is almost exactly like FIP, except it uses the expected number of home runs taking the pitcher’s fly balls allowed times the league average home run per fly ball rate.
Value
xfipminus 35 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/xfip/ See Also fip,xfipminus Examples
## The function is currently defined as
function (flyballs, lgHRFB, BB, HBP, K, ip, year) { constant <- linearWeights$cFIP[which(linearWeights$Season == year)] xfip <- (13 * (flyballs * lgHRFB) + (3 * (BB + HBP)) - (2 * K))/(ip) + constant return(xfip) } xfipminus xFIP-Description
xFIP- is a park-adjusted version of xFIP
Usage
xfipminus(xFIP, ParkFactor, LeaguexFIP) Arguments
xFIP Player xFIP
ParkFactor Park Factor
36 xfipminus 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 (xFIP+(xFIP-(xFIP*(ParkFactor/100))))/(LeaguexFIP)*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
xfip,fipminus,eraminus
Examples
## The function is currently defined as function (xFIP, ParkFactor, LeaguexFIP) {
xfipminus <- (xFIP + (xFIP - (xFIP * (ParkFactor/100))))/(LeaguexFIP) * 100
return(xfipminus) }
Index
∗Topic\textasciitildekwd1
log5,16 ∗Topic\textasciitildekwd2
log5,16 ∗Topicbabip
babip,3∗Topic
baseball analytics
sabermetrics-package,2∗Topic
baseball
sabermetrics-package,2
∗Topic
batting average
babip,3∗Topic
datasets
linearWeights,14∗Topic
defense independent pitching
dice,4∗Topic
defense
fp,10∗Topic
dice
dice,4∗Topic
earned run average
era,5∗Topic
eqa
raweqa,23∗Topic
era minus
eraminus,6∗Topic
era-eraminus,6∗Topic
era
era,5∗Topic
expected fip
xfip,34∗Topic
fielding independent
fip,7∗Topic
fielding percentage
fp,10∗Topic
fip minus
fipminus,8∗Topic
fip-fipminus,8
∗Topic
fip
fip,7∗Topic
handed park factors
handedparkfactors,11∗Topic
isolated power
iso,12 ∗Topiciso
iso,12 ∗Topicleague wsb
lgwSB,13 ∗Topicobp
obp,17∗Topic
on base percentage
obp,17∗Topic
on base plus slugging
ops,18∗Topic
ops plus
opsplus,19∗Topic
ops+
opsplus,19∗Topic
ops
ops,18∗Topic
park factors
handedparkfactors,11 parkfactors,20 ∗Topicpythagorean
pyth,22 ∗Topicpyth
pyth,22 ∗Topicraa
wraa,29∗Topic
raw eqa
raweqa,23∗Topic
runs above average
wraa,29∗Topic
sabermetrics
sabermetrics-package,2∗Topic
secavg
38 INDEX secavg,24
∗Topic
secondary average
secavg,24∗Topic
slg
slg,25∗Topic
slugging percentage
slg,25∗Topic
sports analytics
sabermetrics-package,2∗Topic
stolen bases
wsb,33∗Topic
wSB
wsb,33∗Topic
walks plus hits per inning
pitched
whip,26
∗Topic
weighted on base
woba,27∗Topic
weighted runs created
wrc,30 ∗Topicwhip
whip,26 ∗Topicwoba
woba,27 ∗Topicwraa
wraa,29 ∗Topicwrc plus
wrcplus,31 ∗Topicwrc+
wrcplus,31 ∗Topicwrc
wrc,30∗Topic