Data and code from: Using simulation to optimize batting lineups in Major League Baseball
Data files
Abstract
This dataset supports a study that uses Monte Carlo simulation to evaluate how batting-lineup construction affects run production in Major League Baseball. Using real player data from the 2024 MLB season, a game-level simulation model varies the batting lineup to estimate runs scored across full games and seasons. The package contains three components: (1) player and team inputs — per-player batting splits by pitcher handedness (slugging, average, on-base percentage, isolated power) and advanced metrics (wOBA, wRC+) for the twelve teams and the synthetic rosters analyzed; (2) simulation results — average runs per game with confidence intervals under baseline and optimized (1-D and 2-D) lineup strategies, random-permutation upper bounds, lineup-similarity metrics, cloned-lineup run-expectancy analyses, and supporting summary tables; and (3) the Julia simulation code. The study finds that optimized lineups are worth roughly three to six wins per season depending on the team, though the optimal construction strategy is team-dependent: three of twelve teams show statistically significant improvement over their real-world lineups, while the rest are already near-optimal. The model treats offensive outcomes as independent of pitcher and defensive quality and does not adjust for game situation. All derived metrics and simulation outputs were generated by the authors; the underlying statistics are factual records of the 2024 season.
This dataset accompanies a master's thesis that uses Monte Carlo simulation to evaluate how batting-lineup construction affects run production in Major League Baseball.
General information
- Title of dataset: Data and code from: Using simulation to optimize batting lineups in Major League Baseball
- Associated DOI:
10.5061/dryad.s4mw6m9kf - Creators:
- Andrew Schaeffer — North Carolina State University — ORCID
0009-0009-6690-572X(lead) - John Constantino — North Carolina State University — ORCID
0009-0007-4401-7575 - Brandon M. McConnell — North Carolina State University — ORCID
0000-0003-0091-215X(advisor)
- Andrew Schaeffer — North Carolina State University — ORCID
- Corresponding author: Brandon M. McConnell, bmmcconn@ncsu.edu
- License: CC0 1.0 Universal (Public Domain Dedication)
- Temporal coverage: 2024 Major League Baseball regular season
- Geographic coverage: United States (Major League Baseball)
- Funding: None
- Subject keywords: baseball; batting lineups; sabermetrics; simulation; sports analytics
Methodological information
The simulation represents a half-inning as a Markov-style sequence of plate appearances over 24 base-out states. For each batter, plate-appearance outcome probabilities (strikeout, walk, single, double, triple, home run, ground out, fly out, line out) are derived from that player's 2024 batting line split by the handedness of the opposing pitcher. Baserunning advancement, stolen-base attempts, double plays, wild pitches/passed balls, errors, and a simplified bullpen-management rule are modeled with fixed transition probabilities. Each candidate lineup is simulated for 10,000 games (8 innings per game; a season-weighted mix of right-handed and left-handed starting pitchers), and the mean runs per game is reported with a 95% confidence interval.
Three lineup-construction strategies are compared for each team:
- Baseline — the team's real-world 2024 batting order.
- 1-D — players ordered by a single dimension (wRC+ ranking).
- 2-D — players ordered using a two-dimensional construction that also accounts for run potential vs. run realization.
Lineup strategies are additionally compared against random permutations of each team's nine best hitters to estimate practical upper and lower bounds on run production, and against "cloned" lineups (nine identical copies of one player) to isolate per-player, per-lineup-position run expectancy.
Advanced metrics used as ranking inputs:
- wOBA (weighted on-base average) — a rate statistic that weights each plate-appearance outcome by its average run value.
- wRC+ (weighted runs created plus) — a park- and league-adjusted index of total offensive production where 100 equals league average and each point above/below 100 is one percentage point better/worse than average.
- ISO (isolated power) — slugging percentage minus batting average.
Data provenance and licensing
This dataset consists primarily of values computed by the authors and outputs of an original baseball game-simulation model. Derived metrics — Isolated Power (ISO = SLG − AVG), and handedness-split wOBA and wRC+ — were calculated by the authors from underlying counting statistics; the simulation outputs were generated by the authors' own code. These are the authors' original work product and are released under CC0 1.0 (public-domain dedication).
The underlying raw Major League Baseball batting statistics are factual records of real games. Under U.S. copyright law, facts are not copyrightable, and the labor of compiling them confers no copyright (Feist Publications, Inc. v. Rural Telephone Service Co., 499 U.S. 340 (1991)); courts have likewise affirmed the public's freedom to use publicly available player statistics (C.B.C. Distribution & Marketing, Inc. v. MLB Advanced Media, L.P., 505 F.3d 818 (8th Cir. 2007), cert. denied).
The same factual 2024 per-player handedness splits used here are available from Major League Baseball's own official, free MLB Stats API (for example, https://statsapi.mlb.com/api/v1/people/{playerId}/stats?stats=statSplits&group=hitting&sitCodes=vr,vl&season=2024), and the underlying play-by-play facts are independently available from openly licensed sources including Retrosheet (https://www.retrosheet.org, free use with attribution). The raw inputs used in this study were originally collected from Baseball-Reference.com (Sports Reference LLC) for convenience. Note that MLB Advanced Media and Sports Reference each assert rights over the presentation and arrangement of their compiled databases and restrict bulk redistribution of those compilations; those terms govern access to the source compilations, not the underlying facts. This dataset reproduces neither source's table selection/arrangement nor any materially significant portion of either database — it contains the authors' selected players, the authors' derived metrics, and the authors' simulation outputs. Accordingly, the authors have sufficient rights to dedicate this dataset to the public domain under CC0. Users wishing to cite a canonical source for the underlying facts may reference the MLB Stats API (https://statsapi.mlb.com) and/or Retrosheet (https://www.retrosheet.org).
File overview
This publication contains three ZIP archives plus this README. Before use, unzip each archive — data.zip, excel.zip, and code.zip — keeping each folder's name. After unzipping, the contents are organized as follows:
README.md <- this file
data.zip -> data/ <- machine-readable flat CSVs (primary data)
excel.zip -> excel/ <- values-only Excel companions (convenience copies)
code.zip -> code/ <- Julia simulation code and environment
All paths referenced in this README (e.g. data/players_batting_splits.csv, code/Full_Code.ipynb) assume the archives have been unzipped into folders of the same name, alongside this README.
The CSV files in data/ are the authoritative, archival form of the data. The workbooks in excel/ contain identical values (formulas resolved to static values, merged cells flattened) and are provided only for convenience; each original worksheet is one sheet in the corresponding companion workbook.
Conventions used throughout:
- Character encoding: UTF-8. Field delimiter: comma. First row of every CSV is the header.
- Missing-data code:
NAdenotes a value that was unavailable or not applicable (e.g., a player with no recorded plate appearances against one handedness, or a comparison that does not apply to a given row).NAis used consistently across all CSVs and the convenience workbooks; there are no empty cells. - Rate statistics (AVG, OBP, SLG, ISO, wOBA, all probabilities) are unitless proportions. wRC+ is a unitless index (100 = league average). Run figures are in runs (per game unless a column name indicates per season). Columns named
*_pctare proportions in the range 0–1 unless otherwise noted. - "RHP"/"LHP" denote the handedness of the opposing pitcher (right/left), not the batter.
data/ — input files
players_batting_splits.csv
Per-player, per-pitcher-handedness batting rates for the players appearing in the analyzed lineups; this is the simulation's plate-appearance rate input (one row per player per handedness faced). Derived from the 2024 split lines.
Name— player full name (text).Category— qualitative hitting-style label assigned from the player's rates (one of:Average,Contact,On-base,Power,Contact/Power,On-base/Power; the thesis code can also assignEliteandContact/On-base).Pitcher— handedness of the opposing pitcher these rates apply to (RHPorLHP).Slug— slugging percentage vs. the specified handedness (proportion).Avg— batting average vs. the specified handedness (proportion).OBP— on-base percentage vs. the specified handedness (proportion).ISO— isolated power =Slug−Avg(proportion).
players_woba_wrcplus_master.csv
Master league-wide table of advanced metrics by handedness (one row per player; a small number of distinct players share an identical name).
Name— player full name (text).RHP_wOBA— wOBA vs. right-handed pitching (proportion).RHP_wRC_plus— wRC+ vs. right-handed pitching (index; 100 = average).LHP_wOBA— wOBA vs. left-handed pitching (proportion).LHP_wRC_plus— wRC+ vs. left-handed pitching (index).
players_vs_lhp.csv and players_vs_rhp.csv
Single-handedness advanced-metric tables (the vs-LHP and vs-RHP views of the master table; row counts differ because not every player faced both handednesses enough to qualify).
Name— player full name (text).wOBA— wOBA vs. the file's handedness (proportion).wRC_plus— wRC+ vs. the file's handedness (index).
team_rosters.csv
Rosters for the twelve analyzed real teams, with each player's handedness-split advanced metrics and the Baseball-Reference split-page URL the inputs were drawn from. (The twelve teams' worksheets in the original workbook are combined here with a Team column.)
Team— team name (text; one of the twelve analyzed teams).Name— player full name (text).RHP_wOBA,RHP_wRC_plus,LHP_wOBA,LHP_wRC_plus— as in the master table.BRef_split_URL— source URL for the player's 2024 batting splits (text).
synthetic_team_rosters.csv
Membership of the three synthetic rosters (AL All-Stars, Contact, Power) used as additional test lineups. These rosters list only player names and source URLs; their metrics are looked up from the league-wide tables above.
Team— synthetic roster name (AL All-Stars,Contact, orPower).Name— player full name (text).BRef_split_URL— source URL for the player's 2024 batting splits (text).
sim_input_player_pa_outcomes.csv
The plate-appearance counting line per player per pitcher handedness, used by the simulation code to build outcome-probability distributions. Sourced from the official MLB Stats API (2024 season hitting splits vs. LHP/RHP); these values reproduce the authors' original figures exactly. One row per player per handedness faced.
Team— roster the player was analyzed under (text).Player— player full name (text).MLB_id— MLB Advanced Media player id (integer).Pitcher— handedness of the opposing pitcher (RHPorLHP).PA— plate appearances (count).AB— at-bats (count).H— hits (count).Singles— singles =H−Doubles−Triples−HR(count).Doubles,Triples,HR— doubles, triples, home runs (counts).BB— walks (count).HBP— hit-by-pitch (count).SO— strikeouts (count).GroundOuts— ground-ball outs (count).AirOuts— fly-ball + line-drive outs combined (count).SF— sacrifice flies (count).AVG,OBP,SLG— batting average, on-base, slugging vs. that handedness (proportions).
sim_input_player_baserunning.csv
Per-player baserunning rates used by the simulation's stolen-base logic. Stolen-base opportunities (SBO), stolen bases (SB) and caught stealing (CS) are sourced from Baseball-Reference (the only source that exposes SBO). One row per rostered player.
Team— roster the player was analyzed under (text).Player— player full name (text).SBO— stolen-base opportunities (count;NAif unavailable).SB— stolen bases (count).CS— caught stealing (count).PSuccess— steal success rate =SB/ (SB+CS); 0 if no attempts (proportion).PAttempt— steal attempt rate = (SB+CS) /SBO; 0 if no opportunities or no successes (proportion).
data/ — results files
results_runs_baseline_1d_2d.csv
Primary result: simulated mean runs per game and 95% confidence interval for each
team under each lineup strategy.
Team— team name (text).Lineup— strategy (Baseline,1D, or2D).MeanRuns— mean simulated runs per game (runs).CI_Lower,CI_Upper— lower/upper bound of the 95% confidence interval (runs).Wins_over_1D— projected added wins per season vs. the 1-D lineup (wins; blank where not applicable for that row).Wins_over_baseline— projected added wins per season vs. the baseline lineup (wins; blank where not applicable).
results_2d_significance.csv
Whether each team's 2-D lineup is a statistically significant improvement over its baseline.
Team— team name (text).Added_Wins_over_Baseline— projected added wins per season from the 2-D lineup (wins; may be negative).Significant—Yif the improvement is statistically significant, elseN.
results_lineup_comparison_wins.csv
Pairwise projected win differences between strategies, per team.
Team— team name (text).Baseline_vs_1D,Baseline_vs_2D,1D_vs_2D— projected win difference between the named pair of strategies (wins; sign indicates which strategy scored more).
results_random_permutation_bounds.csv
Upper/lower bounds on run production from random permutations of each team's nine best hitters.
Team— team name (text).Min_RunsPerGame,Max_RunsPerGame— minimum/maximum mean runs per game observed across the random permutations (runs/game).Min_Season_Runs,Max_Season_Runs— corresponding season-scaled run totals (runs/season).Run_Difference—Max_Season_Runs−Min_Season_Runs(runs/season).Added_Wins— wins implied byRun_Difference(wins).Previous_Win_Difference— the added wins previously attributed to lineup optimization for this team (wins), for comparison.Win_Change—Added_Wins−Previous_Win_Difference(wins).
lineup_constructions.csv
The Baseline / 1-D / 2-D batting orders for every team, in tidy long form (one row per lineup slot). Derived from the "Lineup Form and 2D Constr" worksheet; the qualitative 2-D-construction annotations from that worksheet are preserved in excel/Thesis_Results_clean.xlsx (sheet Lineup_constructions).
Team— team name (text).Lineup— strategy (Baseline,1D,2D).Position— batting-order position, 1–9 (integer).Player— player batting in that position (text).RosterIndex— the player's index in the team's wRC+-ranked roster (integer).
lineup_similarity_summary.csv
Summary statistics of how similar the three lineup strategies are to one another, per team, for each pairwise comparison.
Comparison— strategy pair (Baseline_vs_1D,Baseline_vs_2D,1D_vs_2D).Team— team name, orAveragefor the across-team summary row (text).Mean— mean lineup-position difference between the two strategies.Wins— associated projected win difference (wins; blank onAveragerows).SD— standard deviation of the position differences.
cloned_run_expectancy.csv
Run expectancy for "cloned" lineups — nine identical copies of a single player — broken out by lineup position, in tidy long form (one row per player × lineup spot).
Team— team the player belongs to (text).Player— player full name (text).HR_pct— the player's home-run rate, HR per plate appearance (proportion).wRC_plus— the player's wRC+ (index).Lineup_Spot— batting-order position the clone occupies, 1–9 (integer).Run_Expectancy— average run expectancy contributed in that spot (runs).
runpot_by_wrcplus_no_hr.csv
Cloned-lineup run potential as a function of wRC+, by lineup position (plot data).
wRC_plus— player wRC+ value (index).pos_1…pos_9— run potential when the player bats in that position (runs).
runpot_by_wrcplus_with_hr.csv
The same relationship with home-run rate retained, used for the HR residual analysis.
Name— player full name (text).HR_pct— home-run rate, HR per plate appearance (proportion).wRC_plus— player wRC+ (index).pos_1…pos_9— run potential by lineup position (runs).avg— mean run potential across the nine positions (runs).
state_2out_0on_by_position.csv
How often the "two outs, no baserunners" game state arises at each lineup position.
Lineup_Position— batting-order position, 1–9 (integer).Pct_time_2out_0on_state— percentage of plate appearances at that position occurring in the two-out, bases-empty state (percent, 0–100).
player_woba_wrcplus_hrpct.csv
League-wide player table of wOBA, wRC+, home-run rate, and team.
Name— player full name (text).wOBA— weighted on-base average (proportion).wRC_plus— weighted runs created plus (index).HR_pct— home-run rate, HR per plate appearance (proportion;NAwhere not computable).Tm— team abbreviation (text;NAwhere unavailable).
player_pa_hr_hrpct.csv
Plate appearances and home runs per player (the basis for HR_pct).
Name— player full name (text).Tm— team abbreviation (text).PA— plate appearances (count).HR— home runs (count).HR_pct—HR/PA(proportion).
player_wrcplus_ranked.csv
Players ranked within their team by wRC+.
Rank— within-team rank by wRC+ (integer).Name— player full name (text).Team— team abbreviation (text).wRC_plus— weighted runs created plus (index).
team_wrcplus_stddev.csv
Dispersion of wRC+ within each team's hitters.
Team— team abbreviation (text).StdDev_wRC_plus— standard deviation of wRC+ across the team's hitters (index units).
excel/ — convenience workbooks
DataFrame_Players_clean.xlsx— sheetPlayers(mirrorsplayers_batting_splits.csv).DataFrame_Teams_clean.xlsx— sheetsStats_master,vs_LHP,vs_RHP,Team_rosters,Synthetic_team_rosters.Thesis_Results_clean.xlsx— one sheet per results CSV listed above.
All workbooks are values-only (no formulas, no merged cells, no formatting) and carry the same data as the CSVs.
code/ — simulation code
Full_Code.ipynb— the Julia simulation notebook (original Julia 1.10.5). It is offline and CSV-driven: it reads the input files indata/(no web scraping), builds each player's plate-appearance outcome-probability distribution, and simulates 10,000 games per lineup. Packages:CSV,DataFrames,Plots,StatsBase,Tables,XLSX, and standard-libraryStatistics,Printf,Random.Project.toml/Manifest.toml— the pinned Julia package environment. On first run, executePkg.activate(@__DIR__); Pkg.instantiate()(the first setup cell does theactivate) to install the exact package versions.outputs/— created at run time; holds the workbooks the notebook writes when re-run.
A fixed random seed (Random.seed!) is set so runs are reproducible. To simulate a different team, change team_selected and the matching hard-coded lineup variables, as noted in the notebook. The 1,000-random-permutation upper-bounds routine summarized in data/results_random_permutation_bounds.csv is described in the associated thesis (handle 1840.20/46323) and is not reproduced in code; a comment in the notebook points readers there.
(See "Reproducibility notes" below for how the simulation consumes its inputs and the determinism characteristics of the Monte Carlo results.)
Reproducibility notes
The reported run figures come from a 10,000-game Monte Carlo simulation. Because the simulation draws random numbers, independent runs produce statistically equivalent but not bit-identical figures unless the random-number generator is seeded; the confidence intervals in the results files quantify this sampling variation.
The simulation's core inputs are per-player plate-appearance outcome probability distributions, which are computed from each player's raw 2024 batting line split by pitcher handedness (plate appearances, at-bats, hits, doubles, triples, home runs, walks, hit-by-pitch, strikeouts, and batted-ball type counts). Those raw split lines are available from the MLB Stats API and Retrosheet as described under "Data provenance and licensing."
Citation
If you use this dataset, please cite both the data package and the associated thesis.
- Dataset: Schaeffer, Andrew; Constantino, John; McConnell, Brandon (2025). Data and code from: Using simulation to optimize batting lineups in Major League Baseball [Dataset]. Dryad. https://doi.org/10.5061/dryad.s4mw6m9kf
- Associated thesis: Schaeffer, Andrew Graham. 2025. Using Simulation to Optimize Batting Lineups in Major League Baseball. M.S. thesis (Operations Research), North Carolina State University. https://www.lib.ncsu.edu/resolver/1840.20/46323
References
Works referenced in this README.
Associated publication
- Schaeffer, Andrew Graham. 2025. Using Simulation to Optimize Batting Lineups in Major League Baseball. M.S. thesis (Operations Research), North Carolina State University. https://www.lib.ncsu.edu/resolver/1840.20/46323 (The full methodology, including the random-permutation upper-bounds procedure, is described here.)
Data sources
- MLB Stats API, Major League Baseball Advanced Media. 2024 season hitting splits. https://statsapi.mlb.com
- Baseball-Reference.com, Sports Reference LLC. 2024 team batting (stolen-base opportunities). https://www.baseball-reference.com
- Retrosheet. Play-by-play event data. https://www.retrosheet.org
- Lahman, Sean. The Lahman Baseball Database (CC BY-SA 3.0). https://sabr.org/lahman-database/
Legal authority cited in the data-provenance statement
- Feist Publications, Inc. v. Rural Telephone Service Co., 499 U.S. 340 (1991).
- C.B.C. Distribution & Marketing, Inc. v. MLB Advanced Media, L.P., 505 F.3d 818 (8th Cir. 2007), cert. denied
