Wednesday, March 21, 2012

BA/OBA/SLG Calculus, pt. 2

The ease of figuring OPS given OBA and SLG, along with the fact that the metrics are reasonably well-accepted by the general baseball community and the fact that, when taken alone, they do at least approximate fundamental baseball values (especially in the case of OBA), has made equations of the form a*OBA + b*SLG common in sabermetrics. OPS is the most obvious example, with a = b = 1.

The way OPS+ does its weighting is a little different; rather than placing a fixed coefficient on OBA and SLG, it adds relative OBA and SLG, which essentially makes the league SLG/OBA ratio the weighting for OBA. For any given league OBA and SLG:

x = 1/LgOBA
y = 1/LgSLG
OPS+ = x*OBA + y*SLG - 1
dOPS+ = x*dOBA + y*dSLG = x*1 + y*TBw/AB% = x + y*TBw/AB%

For the 2010 majors taken as a whole, OBA was .3421 and SLG was .4028, so x = 2.923 and y = 2.483. The subtraction of one is a constant, and thus has no derivative and has no effect on the intrinsic weight of each event. It still needs to be subtracted at the end of the process, though.

Given the x and y values for the 2010 majors and the 88.59 AB%, OPS+ can be written as:

OPS+ = (2.92W + 5.73S + 8.53D + 11.3T + 14.1HR)/(AB + W) - 1

Just as with the derivatives for standard OPS, the coefficients vary for each possible AB%. The extreme AB%s in the 2010 AL were turned in by AJ Pierzysnki and Jim Thome:



It is helpful to restate these values relative to each other; I will dispense with using walks as the reference point as I did last time and go straight to singles. Also included are the relative coefficients in wOBA, the most comparable alternate metric, and for OPS with a 88.59 AB% (OPS avg):



As you can see, OPS+ values walks more highly than OPS, and also reduces the extent to which extra base hits are valued relative to singles. However, the adjustment is fairly small in magnitude (usually equivalent to a weight of around 1.2 on OBA), and thus doesn't significantly improve the relative weights.

It is only natural, then, that other constructs of the form a*OBA + b*SLG have put additional weight on OBA. A typical value, like that used in GPA, is 1.8; there are various other similar OBA weights in use, generally established through regression against team run scored or attempts to match linear weight values. I'll refer to the general form as mOPS. The differentiation is cleaner than for OPS+:

mOPS = a*OBA + b*SLG
d(mOPS) = a*dOBA + b*dSLG = a(1) + b(TBw/AB%) = a + b(TBw/AB%)

If a = 1.8 and b = 1, then the weight for any event is 1.8 + TBw/AB%. For the 2010 average AB%, this is the resulting equivalent equation:

mOPS = (1.8W + 2.93S + 4.06D + 5.19T + 6.32HR)/(AB + W)

Here are the values for the extremes, and the relative weights:





The relative weights for mOPS match wOBA fairly closely, except for the walk. The difference in weighting caused by extreme AB%s is also reduced greatly, since more weight is given to OBA which uses PA as the denominator. Unfortunately, the match for the hit weights is so close that it would be difficult to keep the form a*OBA + b*SLG and get much improvement...which of course speaks to why sabermetricians have settled on an OBA multiplier around 1.8.

If you are hellbent on matching the wOBA weights, one can get pretty close by introducing a third statistic into the mix--batting average. Including BA allows the intrinsic weight of each hit to vary by a fixed amount without having any effect on the BA rate. To get a rough estimate of the optimal weights, I ran a regression of dBA, dOBA, and dSLG for each event against the coefficient from the pared-down wOBA version discussed in part one:

wOBA = (.62W + .77S + 1.08D + 1.37T + 1.70HR)/(AB + W)

I've already discussed how to find the derivatives for OBA and SLG, but not BA:

dBA = Hw/AB%, where Hw = 1 if a hit, 0 otherwise
= 1/AB% for a hit, 0 otherwise

I ran this regression only on the results at one particular AB% (the 2010 major league average). Obviously it would be preferable to examine the function across the range of observed AB%s, but I'm just doing this as a demonstration--I certainly don't actually to propagate the usage of OPS and OPS-like metrics. The regression to fit a function to x*OBA + y*SLG + z*BA gave this result:

.620(OBA) + .273(SLG) - .160(BA)

I fiddled with this a little bit to 1) force the SLG coefficient to 1 so that it is the form of mOPS and 2) make the OBA and BA coefficients multiples of .05:

bOPS = 2.25(OBA) + SLG - .5(BA)
d(bOPS) = 2.25(dOBA) + dSLG - .5(dBA)

or generally bOPS = x(OBA) + y(SLG) + z(BA)
d(bOPS) = x(dOBA) + y(dSLG) + z(dBA)

For the 2010 average AB%, this differentiation results in:

(2.25W + 2.81S + 3.94D + 5.07T + 6.20HR)/(AB + W)

Here are the intrinsic weights relative to a single, with Pierzynski and Thome-level AB% as well:



Now the weights are pretty good matches for wOBA, although introducing BA, yet another metric with a different denominator, has apparently pushed the values for extreme AB%s further away from each other than was the case with mOPS.

While I find the "linear weight test" a more compelling way to evaluate a metric than a test on aggregate seasonal team batting stats, I'll throw in the correlation with R/(AB - H) for OPS, mOPS, and bOPS in 1955-2008:



This goes to show that just about any reasonable metric will give acceptable results when applied to team-seasons. bOPS performs a little worse than mOPS, which performs a little better than OPS. Whatever added accuracy comes from using mOPS or bOPS will be at the player level, where the distribution of outcomes is more extreme, and will be most evident for players with high walk rates.

It is tempting to look at the bOPS formula, see the negative coefficient for BA, and make a statement about the merits of BA as a metric. While we could all spend the rest of our lives taking potshots at BA (and rightly so), that should not be the takeaway from this exercise. The introduction of BA here allows us to improve the intrinsic weights by changing each hit weight by an equal amount while leaving walks untouched; the alternative of changing the weight on SLG affects all hit types differently (based on how many bases they are worth, of course).

In doing so, the OBA weight has been raised above its optimum level (around 1.8), but this has been offset by removing .5*BA so that walks can get an extra boost. It is therefore much more of a statement about how metrics based only on linear combinations of OBA and SLG are incapable of valuing walks properly without distorting the relationship between intrinsic weights for the other events.

The writing in the last two posts has been dry and choppy even by my usual standards, which is largely because the material is math-y without telling us much about baseball. In writing them, it was not my intention to in anyway encourage the use of OPS-type metrics for anything other than quick-and-dirty uses. Hopefully, looking at the mathematical properties of OPS in a slightly different manner than I have before will add to the body of evidence of why OPS fails when it is used for more involved purposes.

Wednesday, March 14, 2012

BA/OBA/SLG Calculus, pt. 1

I wrote a series of posts about OPS four years ago entitled "Beating a Dead Horse". Among serious sabermetricians, there is a consensus that OPS is flawed, and the only disagreement is whether the consequence of its flaws should be banishment to the dustbin of history or mere consignment to back of the envelope computations. In writing about the odd construction of OPS again, it may look as if I'm trying to rebuke someone. That is not the case--while it's more math than baseball, I find what follows interesting and perhaps some of you will too.

The easiest way to examine how a non-linear metric values each event is to take the partial derivative of the metric with respect to each event. I have gone through this exercise for OPS in the past, but in doing so have focused on looking at OPS from the perspective of a complete counting stat line. This time, I am looking at it from a rate perspective while holding the ratio of at bats to plate appearances constant.

If you look at the totals and attempt to differentiate, you have to account for the fact that every change in an offensive event also changes the PA total and (unless it is a walk) the AB total. By treating AB/PA (which I'll call AB%) as a constant, we can focus solely on how the change in rates of positive events effect OPS. In doing so, we'll be able to restate OPS for a given AB% as a mathematically equivalent PA-weighted metric.

Let me define s, d, t, hr, and w as the respective rates of singles, doubles, triples, homers, and walks per PA. For the purpose of this post PA = AB + W. One could easily include hit batters and sacrifice flies if they were so inclined.

Given these new definitions, we can write:

OBA = (H + W)/(AB + W) = s + d + t + hr + w
SLG = TB/AB = (s + 2d + 3t + 4hr)/AB%

Then we can differentiate each of these equations with respect to s, d, t, hr, and w. In the case of OBA, the derivative is 1 for each event. For SLG, the derivative is equal to AB% (remember, AB% is being treated as a constant) times the total base weight of the event (1 for a single, 2 for a double, etc.). Let me call the total base weight of an event TBw:

dOBA (s, d, t, hr, w) = 1
dSLG (s, d, t, hr, w) = TBw/AB%

So it follows that dOPS = 1 + TBw/AB%, and using this formula we can write OPS in the form of (coeff*S + coeff*D + coeff*T + coeff*HR + coeff*W)/PA where coeff is each event's respective dOPS.

The practical implication of this is that the sole variable factor in determining the OPS weight of an event is the player's AB%. Or, put another way, his walk rate (since 1 = AB% + w). To put this in practice, let's consider the OPS weights for three AB%s--the player with the highest AB% in the 2010 AL (AJ Pierzynski, 96.93%), the player with the lowest (Jim Thome, 82.14%), and the major league average for 2010 (88.59%).

First, the OPS weights for the major league average:
W coeff = 1 + 0/.8859 = 1
S coeff = 1 + 1/.8859 = 2.129
D coeff = 1 + 2/.8859 = 3.258
T coeff = 1 + 3/.8859 = 4.387
HR coeff = 1 + 4/.8859 = 5.515

As mentioned above, this means that a precise alternate formula for OPS given a fixed AB% of 88.59% is:

OPS = (W + 2.129S + 3.258D + 4.387T + 5.515HR)/(AB + W)

This table gives the coefficients for the AB% level represented by Thome and Pierzynski. It also includes calculations of what each player's OPS would be if the weights from the other AB% level were applicable:



The calculation of OPS using weights for a different AB% is a misleading exercise, since AB% is not actually a constant. I include it to illustrate that each possible AB% results in a different set of intrinsic event weights.

There is nothing inherently wrong with different weights for a different set of inputs. It can be a very useful property of a metric, as is the case with Base Runs, or with a Markov model of run scoring, or other dynamic estimators. However, I believe that it is crucial that if there is dynamism at work in a metric, it must serve some purpose. What could be called a "false dynamism" adds nothing and requires metrics to be employed with additional caveats.

An example of false dynamism was the old Clay Davenport Equivalent Runs methodology. EqR is fully linear if a player attempts no steals, but stolen base attempts alter the intrinsic weights of all events.

The false dynamism of EqR was of a much lesser magnitude than the OPS case, and thus was more of an annoyance than a damning flaw. In the case of OPS, the damning flaw of the metric is a failure to properly weight OBA, but the false dynamism caused by the different denominators is another serious black mark against it.

Given the intrinsic weights of OPS, we can compare OPS' relative weighting of each event to the weighting used by a good linear weights-based metric. This is a tricky subject because one must first determine what purpose OPS will be used for. If you plan to convert OPS into an estimate of runs scored, then you should perform this type of analysis after the conversion has been made, and the comparison should be to standard linear weight values (this is the type of OPS analysis I have published previously). However, if you plan to use straight OPS as a measure of overall batter productivity, it makes more sense to contrast it to a metric that similarly attempts to measure overall batter productivity with a denominator of plate appearances.

Tangotiger's wOBA is such a metric. The relative weights of events look a little different than those procured from standard linear weights, but that is a result of re-casting the value of each event as the standard linear weight value plus the absolute value of an out. As such, it uses a R+/PA perspective on the ultimate batter rate stat rather than the more common R/O approach. The differences between the two schools of thought is a series of posts unto itself, but suffice it to say that this is the necessary approach if you'd like to express overall productivity with a denominator of PA and without making any debits for outs in the numerator. Since that is the construction of the alternate OPS derivation here, wOBA is the proper comparison.

A basic wOBA formula (without the 15% boost to match the OBA scale) is:

(.62W + .77S + 1.08D + 1.37T + 1.70HR)/PA

The chart below recasts those weights as relative to that of a walk (.62) and compares it to the three different 2010 OPS results discussed above (average, Pierzynski high AB% extreme, Thome low AB% extreme):



This chart makes what we've observed already stick out like a sore thumb--OPS severely undervalues walks. Unfortunately, that makes the relationships between the hit types harder to see at a glance, so allow me to recast the chart as each event's weight relative to that of a single:



This chart suggests that while the most egregious weighting centers around walks, OPS still overvalues extra base hits, and thus slugging average. This is of course a common criticism of the metric and one that is addressed by a number of fixes. Also note that while a lower AB% results in even higher weighting for power, it results in lower relative weighting for walks. In this manner, the pro-power and anti-walk biases of OPS offset each other to some extent for players with high secondary averages. The players that really have the potential to lose out are those that draw walks without hitting for power. The players that stand to benefit the most are those that hit for power but do not draw walks (I'm going to refrain from naming names, but there is a certain, much-debated, recent inductee to the Hall of Fame that fits this description nicely).

In re-reading this a year after I originally wrote it, I think I need to repeat myself a little bit to emphasize something. The formulas in this post are not estimates of OPS. They are precise, equivalent formulas to calculate OPS given that AB% is held constant. In the past, the work I’ve done with OPS derivatives has always attempted to capture the dynamic nature of AB%. Every plate appearance (excluding sacrifices) moves AB% one way or the other--down with a walk/hit batter/interference, up with anything else, and thus the equivalent formula for OPS is never constant for any entity. But at any moment in time, the equations in this post are mathematically equivalent formulas for OPS.

Frankly, I’m amazed I never thought of differentiating OPS this way before. It results in a much more easily explained and useful in practice result, and the math is actually easier (although none of the calculus I’ve ever posted on this blog is hard if you know what you’re doing).

So keep in mind that the intrinsic weight OPS places on each event changes every plate appearance. Unlike a dynamic run estimator that changes intrinsic weights continuously in an attempt to model the dynamics of the run scoring process, OPS changes weights just because someone draws a walk or doesn’t.

In the next installment, I will apply this differentiation approach to a couple of the OPS variants (such as OPS+ and GPA) which attempt to address these issues by weighting OBA more heavily.

Wednesday, March 07, 2012

BA/OBA/SLG Algebra, pt. 2

OPS

OPS = OBA + SLG = (H + W)/(AB + W) + TB/AB = ((H+W)*AB + TB*(AB + W))/(AB*(AB + W))

I believe the technical term for that is gobbledy-gook.

The only argument in OPS favor is that it is easy to calculate, given that you already have OBA and SLG. The argument that it is simple in theory is only true to math simpletons, who don’t bother to ask why two statistics with different denominators should be added and what the algebraic result of doing so looks like.

Suppose that OBA and SLG did not exist in their present forms as commonly used statistics. Would anyone ever propose

((H + W)*AB + TB*(AB + W))/(AB*(AB + W))
as a measure of a hitter’s productivity?

Or, alternatively, assume that when you were first introduced to OPS, you were not told it was OBA + SLG. Rather, it was introduced to you as the mess above. How long would it have taken you to do the algebra that would pull it apart until into OBA + SLG? Wouldn’t you have asked, “Why are times on base weighted by at bats while total bases are weighted by plate appearances? What is the reasoning behind it?”


OTS/Basic Runs Created

On Base Times Slugging (OBA*SLG) has gone by a few different names (BRA and SLOB) the most frequent, but it’s most easily recognizable when it’s multiplied by at bats:

(H + W)/(AB + W)*(TB/AB)*AB = (H + W)*TB/(AB + W)

Which of course is Bill James’ basic Runs Created formula, which means that OTS is equal to Runs Created/At Bat. We can convert it to Runs Created/PA by multiplying by AB% (since RC/AB*AB/PA = RC/PA), which we have already seen is (1 - OBA)/(1 - BA):

RC/AB*AB% = OBA*SLG*(1 - OBA)/(1 - BA) = RC/PA

We can also endeavor to figure RC/Out from BA/OBA/SLG. Since OBA*SLG is RC/AB:

(RC/AB)*(AB/Out) = RC/Out

Since we’re only considering batting outs, AB/Out is AB/(AB - H) = 1/(1 - BA), leading to:

RC/Out = (RC/AB)*(AB/Out) = OBA*SLG*(1/(1 - BA)) = OBA*SLG/(1 - BA)

I have a lengthier post I want to write about this equation, comparing it to Euler’s identity (in elegance only). It captures the three most commonly used rate statistics and relates them elegantly to the fundamental (at least on the team level) measure of offensive productivity (run/out). It would be perfect if not for the fact that it doesn’t hold up theoretically (minor details, you know).

Bases per Plate Appearance

Bases/PA (which I’ll call BPA) and Bases/Out are intuitive enough ideas for an overall offensive statistic that they have been “invented” many times over. Leaving aside baserunning events, BPA = (TB + W)/(AB + W), which can easily be calculated from BA/OBA/SLG:

(TB + W)/(AB + W) = TB/(AB + W) + W/(AB + W)

We already know the formula for W/(AB + W), so:

TB/(AB + W) = (TB/AB)*(AB/(AB + W))

The second term is AB%, so:

BPA = SLG*(1 - OBA)/(1 - BA) + (OBA - BA)/(1 - BA)
= (SLG*(1 - OBA) + OBA - BA)/(1 - BA)

I’m not sure which of those equations looks better, but take your pick.

Bases per Out

The batting-events version of bases/out is (TB - H)/(AB - H). That of course can be split into TB/(AB - H) + W/(AB - H), and we can start with TB/AB and W/AB and convert to per (AB - H) by multiplying by AB/(AB - H). Again, AB/(AB - H) is 1/(1 - BA), so:

TB/(AB - H) = (TB/AB)*((AB - H)/AB) = SLG*1/(1 - BA) = SLG/(1 - BA)
W/(AB - H) = (W/AB)*((AB - H)/AB) = ((OBA - BA)/(1 - OBA))*1/(1 - BA) = (OBA - BA)/((1 - OBA)*(1 - BA))

Bases/Out = SLG/(1 - BA) + (OBA - BA)/((1 - OBA)*(1 - BA)) = (1/(1 - BA))*(SLG + (OBA - BA)/(1 - OBA)) = (SLG + (OBA - BA)/(1 - OBA))/(1 - BA)

Estimated Runs Produced

If you’re still awake, you should be starting to realize that BA, OBA, and SLG can be converted into just about any components that rely only on some combination of AB, H, TB, and W. This means that it’s quite possible to get some pretty decent linear run estimators from the slash stats; you just have to avoid those that break out doubles, triples, and homers rather than treating all extra bases equally. This constraint does reduce the possible accuracy a bit, but still leaves you with some pretty decent options.

A quick skeleton-style linear weight formula I use a lot is essentially Paul Johnson’s Estimated Runs Produced:

ERP = (TB + .8H + W - .3AB)*.324

It is easiest to start by writing this in its per AB form:

ERP/AB = (TB + .8H + W - .3)*.324/AB

Which can be rewritten as:

ERP/AB = (SLG + .8*BA + (OBA - BA)/(1 - OBA) - .3)*.324

Runs/at bat is not a particularly useful form if you intend to just use the result as a rate; per plate appearance or per out are much more meaningful, and of course we can convert:

(ERP/AB)*(AB/PA) = ERP/PA = (SLG + .8*BA + (OBA - BA)/(1 - OBA) - .3)*(1 - OBA)/(1 - BA)

= (SLG*(1 - OBA)/(1 - BA) + .8*BA*(1 - OBA)/(1 - BA) + (OBA - BA)/(1 - BA) - .3*(1 - OBA)/(1 - BA))*.324

= ((OBA - BA + .8*BA*(1 - OBA) + SLG*(1 - OBA) - .3*(1 - OBA))/(1 - BA) * .324

ERP/PA = ((OBA - BA) + (1 - OBA)*(.8*BA + SLG - .3))/(1 - BA)*.324

These formulas are certainly less elegant than their RC counterparts when expressed in terms of the slash stats, but they are much more sound, and arguably just as easy to calculate when using their components rather than the slash stats.

To get ERP/Out, it’s easiest to start with ERP/AB and multiply by (AB - H)/AB. There’s not much simplification to be had:

ERP/Out = (ERP/AB)*((AB - H)/AB) = (SLG + .8*BA + (OBA - BA)/(1 - OBA) - .3)*.324*1/(1 - BA)

= (SLG + .8*BA + (OBA - BA)/(1 - OBA) - .3)/(1 - BA)*.324

If you’d like that in a convenient R/G format, you can multiply by 25.2, which would leave you with:

ERP/G = (SLG + .8*BA + (OBA - BA)/(1 - OBA) - .3)/(1 - BA)*8.16

Please remember that it’s much more straightforward to just figure ERP or other similar linear weight methods from the inputs and not to bother with BA/OBA/SLG at all. I certainly wouldn’t want these more complex equations to encourage the usage of “simple” formulas like OBA + SLG.