Learn R Programming

Sabermetrics (version 2.0)

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

woba(year, AB, BB, IBB, HBP, single, double, triple, HR, SF)

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

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

Details

The linear weights used for this equation are in the linearWeights dataframe.

References

http://www.fangraphs.com/library/offense/woba/

See Also

obp,wraa

Examples

Run this code
## 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
function (year, AB, BB, IBB, HBP, single, double, triple, HR, 
    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)
  }

Run the code above in your browser using DataLab