## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

# Calculate Expected Runs

Calculate the expected number of runs, given the number of outs and the number of players on base.

One of the most frequent decisions a manager makes during a game is to tell the batter what to do. Should the batter have discretion to do what he thinks is best? Should the batter be told not to swing, hoping for a ball outside the strike zone? Should the batter bunt? This hack shows you how to figure out what is most likely to happen in different situations, helping you to judge a manager’s decisions.

## The Code

To understand managers’ decisions better, we’re going to answer a simple question: if your team has a certain number of outs and a certain number of men on base, how many runs can you expect your team to score in that inning?

To answer this question, we need to use detailed, play-by-play data. (To learn where to get this data, see “Get Recent Play-by-Play Data” [Hack #28] . To learn how to turn this data into a database table, see “Make Box Scores or Database Tables from Play-by-Play Data with Retrosheet Tools” [Hack #15] and “Make a Historical Play-by-Play Database” [Hack #22] . Or, you can download preprocessed files from this book’s web site: http://www.oreilly.com/catalog/baseballhks.)

Here is a simple strategy for calculating how many runs you expect a team to score in an inning. For each play, we can figure out the state of the game: the score before the play, the number of outs before the play, and the set of men on base. We can also determine ...

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required