Monday, April 25, 2016

Cracking the Ball-In-Play Nut

A bit over a week ago, I pulled the ball-in-play data from the first 10 or so games off of Baseball Savant and started toying with it in R.  In particular, I was looking to confirm some intuitions I (and other people I know who are frustrated with some of the common attitudes towards balls in play in baseball analytics) have about ball trajectory and batted-ball outcome.  The results were surprisingly promising, and after showing them to some friends and family (and having those friends and family bug me about putting this stuff online), I now have a blog and will be sharing them with the yawning chasm of the internet.

For years, balls in play have been a sort of black hole for baseball statistics - a sort of fluke-y quagmire of unexplained variance into which the data simply could not provide all that much meaningful insight.  What little characterization could be done relied much on vague (and inherently subjective) bucketing, classifying hits as "fly balls" or "line drives."  Since little could be done to explain ball-in-play numbers, much of baseball analytics has grown around the notion that they are "unreliable" - pointing to an inflated BABIP when predicting that a player who's had a hot month will regress has become a fairly ubiquitous trope.  In fact, some of the currently-popular metrics (e.g. FIP) simply ignore balls in play entirely!

The rub is, of course, that ball-in-play results are not truly random.  Even FIP's most vehement supporters are forced to, on occasion, accept this fact.  Nor should we, in particular, expect ball-in-play results to be random: that some balls are well-hit and others are poorly-hit is a fact that's self-evident to even the most casual observer, and it is obvious to anyone who has actually watched the sport that Miguel Cabrera tends more towards the former than does Omar Infante.

Unfortunately, the obvious intuition for ball-in-play results ("players who tend to hit the ball well will have good results") might do well for identifying the obvious (we expect Miguel Cabrera to have better ball-in-play results than Omar Infante), but they don't go much further than that.  And, until recently, we simply did not have many numbers that could go much further than that, either.

(Of course, this is only true for us mere fans - teams have had access to HitF/X for years, which means that all of the analysis I'm about to outline has probably already been done but is proprietary.  Oh, well.)

Well, that was the case.  Now we have Statcast, and while MLB.com seems interested in little more than using it to quote pitch velocities and home run exit velocities to dubious significance (I'm sure Chris Davis' home run off of Craig Kimbrel was traveling precisely 111.2 mph), a whole wealth of new approaches is open to us.  Let's look at a few of them.  All data are through April 15 - I'd re-do these plots again with more recent data, but I'm lazy and none of this is going to have decent sample size for a long while yet anyway.  This is all purely exploratory, and I don't suggest we draw any conclusions until we have a full season (or several) of numbers to pick through.

First, let's take a look at what we used to be doing.  As mentioned earlier, stats like xBABIP have, historically (if one can use that term for a stat that hasn't existed for all that long to begin with) been based off of crude bucketing of batted balls into subjective categories: "line drives," "ground balls," "fly balls," and "pop-ups."  Until now, we've had no way of knowing how well-defined these categories are, or where they lie in trajectory-space.  Well, wonder no longer:

(Here, and for the rest of this post, I am characterizing "trajectory-space" by vertical launch angle and exit velocity.  We are, obviously, throwing out a whole lot of information by doing this: horizontal angle and spin are the obvious ones, but not-so-obvious ones include wind speed and air temperature and, for batted-ball results later on, any number of things that impact whether or not a ball is caught.  Consider this caveat-ed).

Percentage of balls hit on a given trajectory that were classified as, from the top, a pop-up, fly ball, line drive, or ground ball.


A few things are immediately apparent (aside from the few wacky outliers, like that "ground ball" at the 50+ degree launch angle - I wonder who goofed on that one, Statcast or the human?).  Firstly, the only one of these categories that doesn't have an extremely fuzzy boundary is ground balls.  That makes perfect sense, as it's a lot easier to tell if a ball hits the ground (at least, to my sensibilities) than to judge whether or not it was "fly ball-ish enough" to qualify as a low fly ball rather than a high liner.  Secondly, following from this, "line drives" are a supremely messy category.  Thirdly, the "fly ball/pop-up" distinction is not purely an angle-off-bat thing - there's clearly a pretty big dependence on exit velocity, too.

While the finer points of this might be interesting from a cognitive science standpoint ("what makes an observer think of a trajectory as a 'pop-up?'"), the main take-away is that this is a pretty crude and inconsistent bucketing of trajectory-space, and as we will see is not really capable of capturing the most important (and immediately-visible) trends of the ball-in-play data.  We now can (and should) do a whole lot better.

So, about those "immediately-visible and important trends."  The obvious thing to do now is to look at actual results of balls in play, and how those results vary over trajectory space.  For want of more clever ideas of how to do this, I simply assigned to each outcome its corresponding wOBA weight and plotted the average value over trajectory space.  The resulting "wOBABIP" (now there's a name for a stat - I don't know if we'll be able to say this one in real life too often without laughing) graph is below:


Again, some things are immediately apparent, and in ways that are quite pleasing to the intuitions of anyone who's watched baseball.  That nice, big blob of red corresponds to the home runs, and is more or less where we'd expect it to be.  We see a nice streak of good results along a ~20-degree launch angle, confirming that, as we all knew, Line Drives Are Good.  Interestingly, though, the window for a "good line drive" is not only quite narrow, but has a pretty clear dependence on exit velocity - harder-hit balls need to be lower in order to avoid staying up long enough to be caught.  Conversely, softer-hit balls need to be higher to make it over the infield.  In fact, this trend carries smoothly right into the most satisfying part of all - the nice big blob of "bloop singles:" the wimpy-exit-velocity counterpart of the home run blob, the pitcher's worst nightmare in graphical format.  Here, we see exactly what all of us knew - if you're going to hit a fly ball, you either want to hit it out of the park, or dink it just over the infield, driving opposing pitchers (and fans) mad.  Anything in-between is an easily-fielded fly-out.

Also of note is the relative lack-of-worth of ground balls.  As we might expect, the results on grounders does get better with increased exit velocity (you can see this even more clearly on the following BABIP chart), but the vast majority of grounders are bad.  Want to know which pitchers can sustain a low wOBABIP?  There's an obvious place to start.

For the sake of completeness, here's the same chart, but with BABIP instead of wOBABIP:

I wholly expect (or hope?) that a lot of this noise will clean itself up once we have a larger sample, though for now it can really be entertaining to look at a few of those singles and wonder how they got through.

One last (not-all-that-exciting) plot - here's the raw sample size per bin:


I don't find this one earth-shatteringly insightful, myself, but it does give us a notion of what potential "batted ball profile" plots might look like for individual players.

So, I've spoken mostly about how these figures confirm our intuitions, but what can we do with them?  Well, quite a few things, it seems to me.  Let me list a few things I'd like to dig into in the future (or see someone else dig into):

1)  Development of new "xBABIP" and "xwOBABIP" stats (because "wOBABIP" isn't already funny enough to say).  Take a player's ball-in-play events, assign each a weight based on the league-average BABIP/wOBABIP in some bin around its position in trajectory-space, then average.  Obvious complication: proper sizing/shaping of bins (especially the proper relative scaling of exit angle and exit velocity, which does not appear obvious to me).  I'm fairly sure that even naive, suboptimal binning will do better than the batted-ball classifications seen above, though.  It would be nice to finally ditch the "inflated babip -> regression" trope, which I've never found particularly convincing - It seems to me a much stronger argument that a player is bound for a drop in performance if we can show that he's been getting on base in spite of hitting the ball poorly, rather than just noting that his balls in play have fallen in for hits.  Of course, to what extent hitting the ball "well" in this "xwOBABIP" sense is repeatable is also a question, which leads us to...

2)  Investigating the stabilization rates of said stats - or, more fundamentally, the stabilization rates of individual players' batted-ball profiles (as measured in this trajectory-space).  This is all of limited utility unless we can figure out over what sample size we'd expect to see real effects.  This obviously requires the development of some easy way of calculating a "variance" from these plots - it could be as simple as some sort of moving-window average error summed over the whole plot, or perhaps it will need to be more complicated than that.  I don't know!  I guess we'll have to just try stuff and see.  It will also be interesting to see if there are any repeatable time-dependent trends over the course of a season (obviously we'll see more home runs in warm weather, and that should show up), though we'll probably need lots more data for that.

3)  Net team defensive metrics.  There is no way that team defense will not show up on these plots.  Obviously, it will show up confounded by myriad other effects - ballpark effects, weather effects, "luck," anything that could possibly go into whether or not a ball hit at a given vertical angle at a given speed will end up in a player's glove.  But, confounded or not, they should be there - and with larger sample sizes we could probably block our data for a few of the confounding variables.  We could probably even look at infield and outfield defense separately, since we should be able to guess pretty well by a ball's location in trajectory-space whether or not it reached the outfield.  Of course, a huge portion of what shows up will also be shifts and general defensive positioning, but that's as much a part of team defensive value as is the actual physical ability of the players.  It will be interesting to see how defensive metrics formulated this way compare to UZR and the like.

4)  Better investigation of what actually goes into contact-management skills for a pitcher.  I recall an article on FanGraphs a year or so ago that investigated wOBABIP versus pitch location, and found quite clearly that low-and-away and high-and-inside pitches fare far better than anything else.  We could now do similar investigations by looking at the pitch location heatmaps of pitchers who manage a consistently below-average xwOBABIP.

This is an exciting new (well, for fans - again, I'd be surprised if this hasn't all been done already with HitF/X) frontier of baseball analytics, and I can't wait to see what comes of it.  I'll eventually be posting more stuff as I dig through the numbers more.

Sunday, April 24, 2016

First post!

Welcome to all of my (nonexistent) readers.  This is going to be a blog where I talk about baseball.  And baseball statistics.  And math.  And whatever else my brain decides is a good idea to spew into the void of the internet, to bounce around from server to server for the rest of time...

So, a little about me, I guess.  I'm a 23-year-old soon-to-be Ph.D. student with a B.Sc. in mathematics from the University of Maryland.  I enjoy watching (and overthinking) baseball.  I also enjoy doing and teaching math, cooking and eating food, building robots, playing guitar, and a large number of other things.  Some of these will likely be the subject of future posts.

I'm going to cut this off here, since (in case it wasn't clear already) I don't exactly have much to say.  There will be some content, soon!  I promise!