Measure Pitching with ERA

Calculate earned run average, the most popular statistic for comparing pitchers.

Earned run average (ERA) is a pitcher’s counterpart to batting average. Like batting average, it’s an old statistic (originating in the 19th century), it’s familiar to most fans, and it has some serious faults.

Earned run average is the number of “earned runs” scored against a pitcher for every 27 outs pitched (there are 27 outs—3 outs per inning times 9 innings—in a game):

	ERA = ER / IPOuts * 27

Earned runs are a funny concept, the counterpart to errors in batting and fielding. If a player makes it on base through a hit, walk, or fielder’s choice and scores without any errors from the pitching team, that’s considered an earned run. If the player reaches base on an error, or was not put out later because of an error, and later scores, that’s considered an unearned run. Just like errors (in fact, because of errors), unearned runs are subjective.

There’s another problem with earned run average: pitchers don’t actually have much control over what happens once a ball is put in play. I explain more about this problem in “Measure Pitching with DIPS” [Hack #51]

The Code

Just like batters, pitchers can move between teams. This means we need to do some aggregation before looking at pitchers (we need to calculate full-season statistics for each pitcher). The following code does this. Besides this aggregation, ERA is simple.

 -- assumes indexes from "Measure Batting with Batting Average" ...

Get Baseball Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.