As a Mets fan, I’ve watched my team spend more than almost anyone in baseball and still miss the playoffs. That made me wonder how much payroll actually matters. In this project I look at every MLB team from 2011 to 2025 (leaving out the 60-game 2020 season) and ask one question: do teams that spend more win more?
The work follows a simple order. First I collect the data from two places, then I clean it and join it together, then I analyze it and show the results.
library(rvest)
library(httr2)
library(dplyr)
library(tidyr)
library(stringr)
library(purrr)
library(readr)
library(ggplot2)
library(scales)
library(broom)
library(plotly)
My proposal planned to scrape payrolls from stevetheump.com, but that site went offline while I was building the project, so I switched to Spotrac. Spotrac keeps a payroll page for every MLB season. Each page has one table with a row per team and the team’s total payroll for that season. I scrape one page per season with rvest. The table also has an “Averages” row in the middle, which I drop later.
get_payroll <- function(season) {
page <- request(paste0("https://www.spotrac.com/mlb/payroll/_/year/", season)) |>
req_user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)") |>
req_throttle(rate = 1) |>
req_perform() |>
resp_body_html()
tbl <- html_table(html_element(page, "table"))
payroll_col <- str_subset(names(tbl), "Total Payroll")[1]
tibble(season = season,
team_code = word(str_squish(tbl$Team), -1),
payroll_text = tbl[[payroll_col]])
}
seasons <- c(2011:2019, 2021:2025)
raw_payrolls <- map_dfr(seasons, get_payroll)
head(raw_payrolls)
## # A tibble: 6 × 3
## season team_code payroll_text
## <int> <chr> <chr>
## 1 2011 NYY $210,950,685
## 2 2011 BOS $170,490,761
## 3 2011 PHI $170,018,182
## 4 2011 LAA $146,234,559
## 5 2011 NYM $141,831,841
## 6 2011 CHC $137,666,584
The MLB Stats API returns the final regular season standings for any year as JSON. I request one season at a time and pull out each team’s ID, wins, and losses.
get_standings <- function(season) {
resp <- request("https://statsapi.mlb.com/api/v1/standings") |>
req_url_query(leagueId = "103,104", season = season,
standingsTypes = "regularSeason") |>
req_perform() |>
resp_body_json()
map_dfr(resp$records, function(division) {
map_dfr(division$teamRecords, function(t) {
tibble(season = season,
team_id = t$team$id,
wins = t$wins,
losses = t$losses)
})
})
}
standings <- map_dfr(seasons, get_standings)
count(standings, season)
## # A tibble: 14 × 2
## season n
## <int> <int>
## 1 2011 30
## 2 2012 30
## 3 2013 30
## 4 2014 30
## 5 2015 30
## 6 2016 30
## 7 2017 30
## 8 2018 30
## 9 2019 30
## 10 2021 30
## 11 2022 30
## 12 2023 30
## 13 2024 30
## 14 2025 30
The payroll column comes in as text like “$115,698,927”.
parse_number() strips the dollar sign and commas and turns
it into a real number. The “Averages” row has no team, so I drop it
here.
payrolls <- raw_payrolls |>
filter(team_code != "") |>
mutate(payroll = parse_number(payroll_text))
The two sources don’t name teams the same way. Spotrac uses abbreviations like “NYM” and “CHW”. The API uses a team ID number, and its names follow whatever the team was called that year (the 2015 Cleveland team comes back as “Indians” and Arizona as “D-backs”). Some abbreviations also changed over time, like the Florida Marlins becoming Miami. I made a lookup table that links each team ID to every abbreviation it could show up under, then reshaped it so each abbreviation gets its own row.
teams <- tribble(
~team_id, ~team, ~codes,
108, "Angels", "LAA,ANA",
109, "Diamondbacks", "ARI,AZ",
110, "Orioles", "BAL",
111, "Red Sox", "BOS",
112, "Cubs", "CHC",
113, "Reds", "CIN",
114, "Guardians", "CLE",
115, "Rockies", "COL",
116, "Tigers", "DET",
117, "Astros", "HOU",
118, "Royals", "KC,KCR",
119, "Dodgers", "LAD",
120, "Nationals", "WSH,WAS,WSN",
121, "Mets", "NYM",
133, "Athletics", "OAK,ATH",
134, "Pirates", "PIT",
135, "Padres", "SD,SDP",
136, "Mariners", "SEA",
137, "Giants", "SF,SFG",
138, "Cardinals", "STL",
139, "Rays", "TB,TBR",
140, "Rangers", "TEX",
141, "Blue Jays", "TOR",
142, "Twins", "MIN",
143, "Phillies", "PHI",
144, "Braves", "ATL",
145, "White Sox", "CHW,CWS",
146, "Marlins", "MIA,FLA",
147, "Yankees", "NYY",
158, "Brewers", "MIL"
)
team_codes <- teams |>
separate_longer_delim(codes, delim = ",") |>
select(team_id, team_code = codes)
payrolls <- payrolls |>
left_join(team_codes, by = "team_code")
# Stop with a clear message if any abbreviation didn't match
unmatched <- filter(payrolls, is.na(team_id))
if (nrow(unmatched) > 0) {
stop("Unmatched team codes: ", paste(unique(unmatched$team_code), collapse = ", "))
}
# Every season should have exactly 30 teams
count(payrolls, season) |> pull(n) |> unique()
## [1] 30
Now both sources share a season and a team ID, so I can join them. Payrolls also grow every year: an average payroll in 2025 is much larger than one in 2011. Comparing raw dollars across years would be unfair, so I also measure each payroll against that season’s league average. A value of 1.0 means the team spent exactly the league average that year, and 2.0 means it spent double.
mlb <- payrolls |>
inner_join(standings, by = c("season", "team_id")) |>
left_join(select(teams, team_id, team), by = "team_id") |>
group_by(season) |>
mutate(rel_payroll = payroll / mean(payroll),
payroll_rank = min_rank(desc(payroll))) |>
ungroup() |>
mutate(win_pct = wins / (wins + losses)) |>
select(season, team, payroll, rel_payroll, payroll_rank, wins, losses, win_pct)
nrow(mlb)
## [1] 420
write_csv(mlb, "mlb_payroll_wins.csv")
season_summary <- mlb |>
group_by(season) |>
summarise(average = mean(payroll),
lowest = min(payroll),
highest = max(payroll),
highest_team = team[which.max(payroll)])
season_summary |>
mutate(across(average:highest, \(x) dollar(x / 1e6, accuracy = 0.1, suffix = "M"))) |>
knitr::kable(col.names = c("Season", "Average", "Lowest", "Highest", "Top spender"))
| Season | Average | Lowest | Highest | Top spender |
|---|---|---|---|---|
| 2011 | $100.7M | $45.4M | $211.0M | Yankees |
| 2012 | $106.8M | $54.1M | $225.6M | Yankees |
| 2013 | $109.9M | $28.7M | $236.7M | Dodgers |
| 2014 | $119.9M | $50.0M | $242.2M | Dodgers |
| 2015 | $128.4M | $73.2M | $301.7M | Dodgers |
| 2016 | $134.0M | $63.2M | $266.7M | Dodgers |
| 2017 | $140.9M | $69.9M | $259.1M | Dodgers |
| 2018 | $139.3M | $68.9M | $227.4M | Red Sox |
| 2019 | $138.6M | $64.2M | $229.2M | Red Sox |
| 2021 | $131.5M | $42.4M | $267.8M | Dodgers |
| 2022 | $150.6M | $44.9M | $273.0M | Dodgers |
| 2023 | $166.4M | $62.3M | $349.1M | Mets |
| 2024 | $170.4M | $63.5M | $324.3M | Mets |
| 2025 | $175.4M | $67.8M | $359.2M | Dodgers |
ggplot(mlb, aes(factor(season), payroll / 1e6)) +
geom_boxplot(fill = "#2a78d6", alpha = 0.25, outlier.shape = NA) +
geom_jitter(width = 0.15, size = 1.2, alpha = 0.6) +
scale_y_continuous(labels = label_dollar(suffix = "M")) +
labs(title = "Payrolls keep growing, and the gap between teams is wide",
x = NULL, y = "Total payroll") +
theme_minimal()
This chart is why I use payroll compared to the league average instead of raw dollars. The whole league moves up over time, so a $150 million payroll meant something different in 2011 than it did in 2025.
model <- lm(win_pct ~ rel_payroll, data = mlb)
fit <- glance(model)
coefs <- tidy(model, conf.int = TRUE)
knitr::kable(coefs, digits = 3)
| term | estimate | std.error | statistic | p.value | conf.low | conf.high |
|---|---|---|---|---|---|---|
| (Intercept) | 0.419 | 0.010 | 43.997 | 0 | 0.400 | 0.438 |
| rel_payroll | 0.081 | 0.009 | 9.089 | 0 | 0.063 | 0.098 |
slope <- coefs$estimate[2]
r_squared <- fit$r.squared
p_value <- coefs$p.value[2]
r_value <- cor(mlb$rel_payroll, mlb$win_pct)
significant <- p_value < 0.05
p <- ggplot(mlb, aes(rel_payroll, win_pct)) +
geom_point(aes(text = paste0(season, " ", team,
"<br>Payroll: ", dollar(payroll / 1e6, accuracy = 0.1, suffix = "M"),
"<br>Record: ", wins, "-", losses)),
color = "grey50", alpha = 0.6) +
geom_point(data = filter(mlb, team == "Mets"), color = "#eb6834", size = 2.5) +
geom_smooth(method = "lm", se = TRUE, color = "#2a78d6") +
geom_hline(yintercept = 0.5, linetype = "dashed", color = "grey60") +
geom_vline(xintercept = 1, linetype = "dashed", color = "grey60") +
scale_y_continuous(labels = label_number(accuracy = 0.001)) +
scale_x_continuous(labels = label_number(suffix = "x")) +
labs(title = "Payroll compared to winning percentage",
subtitle = "Each dot is one team in one season, 2011-2025 (no 2020). Mets in orange.",
x = "Payroll compared to that season's league average",
y = "Winning percentage") +
theme_minimal()
p
The correlation is 0.41 and the p-value is <2e-16, so the relationship is very unlikely to be chance. The slope says that a team spending double the league average (moving from 1.0 to 2.0) raises its winning percentage by about 0.081. Over a 162-game season, that is about 13 extra wins.
But payroll only explains 17% of the differences in winning percentage (the R-squared). Most of what separates good and bad teams comes from other things, like player development, injuries, trades, and luck.
This is the same chart made with plotly, which we didn’t cover in class. Hover over any dot to see the team, season, payroll, and record.
ggplotly(p, tooltip = "text")
Using the regression, I can predict how many games each Mets team “should” have won based on its payroll, and compare that to what actually happened.
mets <- mlb |>
mutate(expected_wins = round(fitted(model) * (wins + losses)),
difference = wins - expected_wins) |>
filter(team == "Mets") |>
select(season, payroll_rank, rel_payroll, wins, expected_wins, difference)
knitr::kable(mets, digits = 2,
col.names = c("Season", "Payroll rank", "Payroll vs average",
"Actual wins", "Expected wins", "Difference"))
| Season | Payroll rank | Payroll vs average | Actual wins | Expected wins | Difference |
|---|---|---|---|---|---|
| 2011 | 5 | 1.41 | 77 | 86 | -9 |
| 2012 | 14 | 0.98 | 74 | 81 | -7 |
| 2013 | 14 | 0.92 | 74 | 80 | -6 |
| 2014 | 20 | 0.79 | 79 | 78 | 1 |
| 2015 | 17 | 0.90 | 90 | 80 | 10 |
| 2016 | 12 | 1.10 | 87 | 82 | 5 |
| 2017 | 15 | 1.02 | 70 | 81 | -11 |
| 2018 | 12 | 1.08 | 77 | 82 | -5 |
| 2019 | 12 | 1.06 | 86 | 82 | 4 |
| 2021 | 3 | 1.54 | 77 | 88 | -11 |
| 2022 | 2 | 1.77 | 101 | 91 | 10 |
| 2023 | 1 | 2.10 | 75 | 95 | -20 |
| 2024 | 1 | 1.90 | 89 | 93 | -4 |
| 2025 | 2 | 1.94 | 83 | 93 | -10 |
best_mets <- slice_max(mets, difference, n = 1)
worst_mets <- slice_min(mets, difference, n = 1)
The Mets’ best season compared to their payroll was 2015 and 2022 (+10 wins each). Their worst was 2023, when they ranked No. 1 in payroll and won 75 games, 20 fewer than their payroll predicted.
Spending more does help. Across 420 team-seasons, higher payrolls go with higher winning percentages, and the relationship is statistically significant (p-value: <2e-16). But the effect is smaller than most fans would guess: payroll explains only about 17% of the differences in winning, and a team has to spend twice the league average to expect roughly 13 more wins. Money raises a team’s chances, but it doesn’t buy a winner on its own.
Limitations. Spotrac’s totals include money for injured players and salary a team is still paying to players it released or traded, so payroll isn’t exactly the same as money spent on the players on the field. This is a correlation, not proof that spending causes winning (good teams might also spend more because they are already good). I also left out 2020 because 60 games is too short to compare.