Estimating Baseball Event Probabilities With log5

December 03, 2020 #baseball#probability#math

In his 1981 and 1983 Baseball Abstracts, pioneering sabermetrician Bill James proposed the log5 method for mixing event probabilities, which is similar to metrics used in other fields. Here are two motivating scenarios:

  • Team A has winning percentage PAP_A. Team B has winning percentage PBP_B. What is the expected winning percentage of Team A against Team B?
  • A pitcher strikes out 20% of batters he faces. A batter strikes out 10% of the time. What is the expected strikeout rate in this matchup?

Winning Percentages

Let’s start with the Team A vs. Team B scenario. We can derive the log5 formula easily. First, we observe that the winning percentages are essentially probabilities:

p(A)=probability that A winsp(B)=probabilties that B wins\begin{aligned} p(A) &= \text{probability that A wins} \\ p(B) &= \text{probabilties that B wins} \\ \end{aligned}

For convenience, we also can define the complement of each:

p(Aˉ)=probability that A loses=1p(A)p(Bˉ)=probabiltiy that B loses=1p(B)\begin{aligned} p(\bar A) &= \text{probability that A loses} = 1 - p(A) \\ p(\bar B) &= \text{probabiltiy that B loses} = 1 - p(B) \end{aligned}

Obviously, there are only two outcomes:

  1. A wins & B loses (AA and Bˉ\bar B occur together)
  2. B wins & A loses (Aˉ\bar A and BB occur together)

Next we ask, what’s the chance that A wins a game and B loses a game? That would be

p(A,Bˉ)=p(A)p(Bˉ)p(A,\bar B) = p(A)p(\bar B)

And what’s the chance that A loses a game and B also wins a game? Simply

p(Aˉ,B)=p(Aˉ)p(B)p(\bar A, B) = p(\bar A)p(B)

This essentially tells us, given that A and B both play a game on the same day not necessarily against each other, what is the chance of them achieving opposite outcomes? For example, if A wins 55% of games, and B wins 60% of games, the probability they play independent games on the same day, and A wins, but B loses is:

p(A,Bˉ)=0.55×(10.6)=0.22p(A, \bar B) = 0.55 \times (1 - 0.6) = 0.22

On the flip side, the chance that they play independent games on the same day, and A loses, but B wins is:

p(Aˉ,B)=(10.55)×0.6=0.27p(\bar A, B) = (1 - 0.55) \times 0.6 = 0.27

Here’s the twist. If we know that A is playing B on this day, we know the events are not independent. Specifically, we know that these are the only two possible outcomes. A and B can’t both win or both lose. To make this a valid probability distribution then, the two outcomes must add up to one, which we can guarantee by dividing each probability by their sum. So for A we could write:

p(AA plays B)=p(A,Bˉ)p(A,Bˉ)+p(Aˉ,B)p(A \mid \text{A plays B}) = \frac {p(A,\bar B)} {p(A, \bar B) + p(\bar A, B)}

Continuing the example, the probability of A winning is 0.22/(0.22+0.27)=0.450.22 / (0.22 + 0.27) = 0.45. Of course, we can substitute in our previous definitions to get

p(AA plays B)=p(A)p(Bˉ)p(A)p(Bˉ)+p(Aˉ)p(B)=p(A)(1p(B))p(A)(1p(B))+(1p(A))p(B)\begin{aligned} p(A \mid \text{A plays B}) &= \frac{p(A)p(\bar B)}{p(A)p(\bar B) + p(\bar A)p(B)} \\ &= \frac{p(A)(1 - p(B))}{p(A)(1 - p(B)) + (1 - p(A))p(B)} \end{aligned}

I find this a more understandable formulation of the core log5 idea. You could come across the equivalent expression on some websites:

p(AA plays B)=p(A)p(A)p(B)p(A)+p(B)2p(A)p(B)p(A \mid \text{A plays B}) = \frac{p(A) - p(A)p(B)}{p(A) + p(B) - 2 p(A) p(B)}

but this is make no intuitive sense when looking at it.

Pitcher vs. Batter Matchups

But this doesn’t always make sense, especially for pitcher and hitter matchups. We’ll look at strikeout rates. Notice that in this case, the stats we have for pitchers and batters refer to the same event, so we don’t have to invert one. A basic implementation would be

p(SOpitcher vs. batter)=ppitcher(SO)pbatter(SO)ppitcher(SO)pbatter(SO)+ppitcher(SO)pbatter(SO)p(\text{SO} \mid \text{pitcher vs. batter}) = \frac{p_\text{pitcher}(\text{SO}) p_\text{batter}(\text{SO})}{p_\text{pitcher}(\text{SO}) p_\text{batter}(\text{SO}) + p_\text{pitcher}(\overline{\text{SO}}) p_\text{batter}(\overline{\text{SO}})}

What if the pitcher’s strikeout rate is 20% and the batter’s is 15%?

p(SO)=0.20.150.20.15+0.80.85=0.042p(\text{SO}) = \frac{0.2\cdot0.15}{0.2 \cdot 0.15 + 0.8 \cdot 0.85} = 0.042

Hmm. That doesn’t seem right. To find out why, think about what information the stats are actually telling us. The pitcher’s strikeout rate says, that on average, he strikes out 20% of batters. “On average,” means that we assume if he faced an average batter, the strikeout rate would be 20%. Similarly, the batter’s strikeout rate of 15% means that, if facing an average pitcher, the batter would strikeout 15% of the time. Thus, what we really need to do is normalize the stats by the league average (which represents both the average pitcher and average batter). Let’s see how this changes our equation:

p(SOpitcher vs. batter)=ppitcher(SO)pbatter(SO)/pleague(SO)ppitcher(SO)pbatter(SO)/pleague(SO)+ppitcher(SO)pbatter(SO)/pleague(SO)p(\text{SO} \mid \text{pitcher vs. batter}) = \frac{p_\text{pitcher}(\text{SO})p_\text{batter}(\text{SO})/p_\text{league}(\text{SO})}{p_\text{pitcher}(\text{SO}) p_\text{batter}(\text{SO})/p_\text{league}(\text{SO}) + p_\text{pitcher}(\overline{\text{SO}}) p_\text{batter}(\overline{\text{SO}})/p_\text{league}(\overline{\text{SO}})}

This equation is unwieldy. For convenience, let P=ppitcher(SO)P = p_\text{pitcher}(\text{SO}), B=pbatter(SO)B = p_\text{batter}(\text{SO}), L=pleague(SO)L = p_\text{league}(\text{SO}). Then we have:

SO%=PB/LPB/L+(1P)(1B)/(1L)\text{SO\%} = \frac{PB/L}{PB/L + (1-P)(1-B)/(1-L)}

Notice that we only divide by LL, not L2L^2, because we only need to normalize one of the rates (pitcher or batter). To see how this works, assume the league average rate is 15%, the same as the batter’s. Then we get:

SO%=0.20.15/0.150.20.15/0.15+0.80.85/0.85=0.20.2+0.8=0.2\begin{aligned} \text{SO\%} &= \frac{0.2 \cdot 0.15/0.15}{0.2 \cdot 0.15/0.15 + 0.8 \cdot 0.85 / 0.85} \\ &= \frac{0.2}{0.2 + 0.8} \\ &= 0.2 \end{aligned}

Which is exactly what we expect! The pitcher strikes out 20% of average batters. The batter, with a rate of 15%, is average. Thus, we should get a strikeout rate of 20% for the matchup. What if the batter is better than league average, with a rate of 10%?

SO%=0.20.10/0.150.20.10/0.15+0.80.9/0.85=0.136\begin{aligned} \text{SO\%} &= \frac{0.2 \cdot 0.10/0.15}{0.2 \cdot 0.10/0.15 + 0.8 \cdot 0.9 / 0.85} \\ &= 0.136 \end{aligned}

A rate of 13.6% once again lines up with expectations. The batter is better than average, so the pitcher’s strikeout rate is brought down. Alternatively, the pitcher’s strikeout rate is higher than average, so the batter’s strikeout rate is brought up.

Why Did We Ignore League Averages for Teams?

“Hold on a second,” you may be thinking. “Why didn’t we need league averages for the Team A vs. Team B scenario?” In that situation, we would use the league average winning percentage, which is 0.5. (Think about it. In the whole season, across all teams, the number of wins and losses will be equal. Every win has a corresponding loss by the opponent.) Plugging into the equation, we have:

p(AA plays B)=p(A)p(Bˉ)/Lp(A)p(Bˉ)/L+p(Aˉ)p(B)/(1L)=p(A)p(Bˉ)/0.5p(A)p(Bˉ)/0.5+p(Aˉ)p(B)/0.5=0.50.5p(A)p(Bˉ)p(A)p(Bˉ)+p(Aˉ)p(B)=p(A)p(Bˉ)p(A)p(Bˉ)+p(Aˉ)p(B)\begin{aligned} p(A \mid \text{A plays B}) &= \frac{p(A)p(\bar B)/L}{p(A)p(\bar B)/L + p(\bar A)p(B)/(1-L)} \\ &= \frac{p(A)p(\bar B)/0.5}{p(A)p(\bar B)/0.5 + p(\bar A)p(B)/0.5} \\ &= \frac{0.5}{0.5}\frac{p(A)p(\bar B)}{p(A)p(\bar B) + p(\bar A)p(B)} \\ &= \frac{p(A)p(\bar B)}{p(A)p(\bar B) + p(\bar A)p(B)} \\ \end{aligned}

which is the same as our previous equation for the team vs. team matchup. Notice that this hinges on the fact that L=1LL = 1 - L when L=0.5L = 0.5.

Odds Ratios

We can rework the equation a little more, with some gratuitous algebra, to get something called an odds ratio:

SO%1SO%=PB/LPB/L+(1P)(1B)/(1L)PB/L+(1P)(1B)/(1L)(1P)(1B)/(1L)=PB/L(1P)(1B)/(1L)=PB(1L)(1P)(1B)L=P1Podds from pitcher against league avg×B/L(1B)/(1L)odds from batter, normalized to league avg\begin{aligned} \frac{\text{SO\%}}{1 - \text{SO\%}} &= \frac{PB/L}{PB/L + (1-P)(1-B)/(1-L)} \frac{PB/L + (1-P)(1-B)/(1-L)}{(1-P)(1-B)/(1-L)} \\ &= \frac{PB/L}{(1-P)(1-B)/(1-L)} \\ &= \frac{PB(1-L)}{(1-P)(1-B)L} \\ &= \underbrace{\frac{P}{1-P}}_{\text{odds from pitcher against league avg}}\times\underbrace{\frac{B/L}{(1-B)/(1-L)}}_{\text{odds from batter, normalized to league avg}} \\ \end{aligned}

This conveniently splits our calculation up into independent terms for pitcher and (normalized) batter. We can use this to easily chain new factors. For example, if a pitcher has a homerun rate of 2%, and the batter has a league average homerun rate (roughly 3.5%, according to baseball-reference.com), then typically the matchup rate will be 2%. However, if the ballpark is Coors Field, which has a homerun factor of 1.147 (from ESPN), which means the odds are 1.147 HR to 1 HR in the average ballpark. Combining all this gives:

HR%1HR%=0.020.98×0.035/0.0350.965/0.935×1.1471=0.023\frac{\text{HR\%}}{1 - \text{HR\%}} = \frac{0.02}{0.98} \times \frac{0.035/0.035}{0.965/0.935} \times \frac{1.147}{1} = 0.023

which corresponds to a rate of 2.3%. Thus, the ballpark causes the pitcher to perform slightly worse than usual against the average batter.

Thus, thanks to Bill James and log5 you can evaluate specific pitcher vs. batter matchups and even include park factors or other environmental conditions. This method is restricted to binary events, but by creating a binary tree, it is possible to simulate all the outcomes of an at bat.


Written by Matthew Russell who follows Jesus, studies machine learning at the University of Kentucky, and interns at NASA. Get to know him or check out his projects on GitHub.