Function Repository Resource:

BaseballWOBA

Source Notebook

Calculate a batter's weighted on-base average (wOBA)

Contributed by: Bob Sandheinrich

ResourceFunction["BaseballWOBA"][stats]

computes a batter's weighted on-base average (wOBA) for the counting statistics stats.

ResourceFunction["BaseballWOBA"]["player"]

computes wOBA for the specified player.

ResourceFunction["BaseballWOBA"][stats,y]

computes a batter's weighted on-base average (wOBA) for the counting statistics stats based on the year y.

Details and Options

The "player" identifier can be given as a Baseball-Reference id or a plain name. Both are resolved to statistics using the Bob/BaseballReferenceData paclet. Plain names are resolved using the first search result from Baseball-Reference.
Weighted On-Base Average uses linear weights to combine the positive outcomes a batter can create and divides by the number of opportunities to create a rate statistic. A description of FanGraphs wOBA is available here.
The weights are recalculated by FanGraphs each year. By default, 2021 weights are used. The option Weights can be used to specify a year or directly specify weights.
Fangraphs weights are available here.
ResourceFunction["BaseballWOBA"] takes the option Weights. Supported values include a year given as an integer or an association of weights for each statistic.

Examples

Basic Examples (1) 

Compute Tyler O'Neill's 2021 wOBA using his counting stats:

In[1]:=
ResourceFunction["BaseballWOBA"][<|
  "HR" -> 34, "3B" -> 2, "2B" -> 26, "1B" -> 76, "BB" -> 38, "HBP" -> 13, "SF" -> 4, "AB" -> 482
  |>]
Out[1]=

Scope (3) 

Get Paul Goldschmidt's 2021 wOBA:

In[2]:=
ResourceFunction["BaseballWOBA"]["Goldschmidt"]
Out[2]=

Get Nolan Arenado's 2021 wOBA using his Baseball-Reference player id:

In[3]:=
ResourceFunction["BaseballWOBA"]["arenano01"]
Out[3]=

Calculate Albert Pujols' wOBA in 2005:

In[4]:=
ResourceFunction["BaseballWOBA"]["Pujols", 2005]
Out[4]=

Options (3) 

Use custom weights. Statistics without weights are treated like zero:

In[5]:=
ResourceFunction["BaseballWOBA"][<|
  "HR" -> 34, "3B" -> 2, "2B" -> 26, "1B" -> 76, "BB" -> 38, "HBP" -> 13, "SF" -> 4, "AB" -> 482
  |>, Weights -> <|"HR" -> 10., "1B" -> 1.|>]
Out[5]=

Use FanGraphs weights from a specific year:

In[6]:=
ResourceFunction["BaseballWOBA"][<|
  "HR" -> 34, "3B" -> 2, "2B" -> 26, "1B" -> 76, "BB" -> 38, "HBP" -> 13, "SF" -> 4, "AB" -> 482
  |>, Weights -> 1985]
Out[6]=

See what wOBA Mike Trout's 2018 season statistics would have generated in other seasons:

In[7]:=
DateListPlot[({#1, ResourceFunction["BaseballWOBA"]["Trout", 2018, Weights -> DateValue[#1, "Year"]]} & ) /@ DateRange[DateObject[{2000}, "Year"], DateObject[{2022}, "Year"], "Year"]]
Out[7]=

Applications (1) 

Plot Babe Ruth's yearly wOBA:

In[8]:=
DateListPlot[{#, ResourceFunction["BaseballWOBA"]["ruthba01", #]} & /@
   DateRange[DateObject[{1914}, "Year"], DateObject[{1935}, "Year"], "Year"]]
Out[8]=

Publisher

Bob

Version History

  • 1.1.0 – 18 July 2022
  • 1.0.0 – 13 July 2022

Related Resources

Author Notes

Exact matches in names currently are not working because the Bob/BaseballReferenceData paclet does not handle the special case response from the Baseball-Reference search page.

License Information