Baseball is probably the one major sporting event where there is no shame in leaving a little early. For starters, the games typically range from long to comically long. The average nine-inning Major League Baseball game in 2017 took three hours and five minutes, setting an all-time record. With a new rule to limit mound visits, the average 2018 game is hovering at an even three hours, which is still longer than “The Godfather” start to finish and would tie for the third longest mark in history.

And unlike the current marathon affairs in college football, baseball is not exactly packing the extra minutes with scoring and excitement — unless pitchers jogging in from the bullpen is exciting to you. Plus, the stakes are low. They play 162 of these things. Add it all up and you understand why lines of fans hit the exits to beat the traffic home.

Of course, as any purist will tell you, a fan who leaves a ballpark early risks missing out on heart-pumping late-inning action: Just ask the owner of the car whose taillights were visible just outside Dodger Stadium as Kirk Gibson’s walk-off homer to win Game 1 of the 1988 World Series landed in the right-field stands.

We can’t advocate ever leaving early from the World Series. But at an average, middle-of-the-season, low-stakes game, exceptions can be made. The decision of when to exit is delicate: You want to leave games in which the outcomes are more or less predictable given the current score, but you don’t want to miss out on late-inning heroics. This decision is the kind of problem that data scientists are equipped to solve.

Our analysis is inspired by research into sequential decision-making problems initiated by Columbia University statistician Abraham Wald in the 1940s. Wald described a problem of accepting or rejecting a shipment of products based on sequentially inspecting random samples from the lot. After each sample is examined, the inspector can accept the shipment, reject it or defer the decision until after the next sample. Wald’s sequential probability ratio test (SPRT) establishes upper and lower bounds for the “likelihood” ratio computed from the current set of samples. If the ratio does not breach either bound, the inspector continues to request new samples. Whenever the ratio crosses one of the two bounds, the inspector makes the corresponding decision to accept or reject the lot.

For our purposes, we regard each inning as a new sample. After each inning, we inspect the run differential to decide whether to leave the stadium or stay for the next inning. The decision depends on the magnitude, but not the direction, of the lead. When the game is effectively over, we wish to disappear before the roads clog up. For this reason, our adapted SPRT involves only a lower bound on the run differential.

The early exit cheat sheet Leave after the If the leader is up 1st inning 6 runs 2nd 6 3rd 5 4th 5 5th 4 6th 4 7th 3 8th 2

According to our statistical model, based on 2010-2015 regular season inning-by-inning scoring data, you should leave after the sixth inning if the leading team is ahead by four or more runs. There is a less than 5 percent chance that the other team will deliver a miracle comeback. If the run differential exceeds two at the top of the ninth, it’s safe to head to the exits. What about blowouts in the first inning? If your time is that precious — and you’re willing to view the money spent on tickets as a sunk cost — our advice is to rev up your car’s engine if the leading team jumps ahead by six runs or more.

In developing the cheat sheet, we tolerate a 5 percent false positive error rate. Take the 2016 season as an example. The impatient fan who took our advice would have left early in 1,750 games, but in 61 of those games, the eventual winner came from behind to win, and so the fan missed out on some later-inning excitement. For that season, our model attained an accuracy rate of 97 percent.

If you follow our cheat sheet, you will leave early in about eight of 10 baseball games. Typically, the best times to leave are between the bottom of the fifth inning and the top of the ninth inning. A back-of-the-envelope estimate pegs the total amount of time saved at 1,612 hours for the season. The price to pay was the 61 mistakes — dramatic comebacks that were heard on the radio from the parking lot by the fans who left early.

If that tradeoff is attractive to you, bring our cheat sheet to the ballpark. Or, bring it to the living room — since fewer of you seem to be going to games anyway — and it will tell you when to turn the dial.

Check out our latest MLB predictions.