The Situation:

Suppose you're the manager of a baseball team. How should you order your
lineup? What makes one lineup better than others?

Optimizing the Batting Order:

Conventional wisdom has the pitcher hitting ninth in a
National League lineup. This strategy is aimed at minimizing the number
of plate appearances for the worst hitter, which is certainly a reasonable plan.
However, in most cases, the lineup should be arranged to maximize the
number of plate appearances for the best hitter. Thus, having a slugger bat
cleanup is perhaps less desirable than having him bat second. Suppose you
do decide to bat the slugger second, then it makes sense for the pitcher to bat
7th or 8th (thereby increasing the distance between the pitcher and the best
hitter). Further rationale for not batting the pitcher 9th is the high chance of
pinch hitting late in the game. When the pinch hitter is used, he isn't
necessarily the worst batter in the lineup and therefore minimizing (or
delaying) his plate appearances isn't sensible.

Surrogate Reality:

In an ideal world, you could try each lineup many times and observe which
ones produced the most runs. You can't actually do this, but you can simulate
doing it. All you need is an accurate mathematical representation of how a game
progresses. In addition to finding the single best lineup, simulation
also provides insight into what characteristics good lineups share. For example,
after a few innings of play, the inning's leadoff hitter is almost equally
likely to be any batter. Therefore, the relative order of the batters as
they cycle through the lineup is much more important than the absolute
order given by the manager to start the game. Provided the circular ordering is
good, even a lineup with the pitcher batting leadoff can be productive.

Mathematically Modeling Baseball (Simulation):

You can experiment with different batting orders to
acquire insight into what characteristics good lineups share.
The applet simulates the runs per 9 innings
generated by a specified lineup. This example focuses on the 2005 Pittsburgh
Pirates. The player who logged the most games at each position is listed as well
as a composite batter representing the pitcher's spot.