Suppose you are the General Manager of a baseball team, and you are selecting two players for your team. You have a budget of $10,500,000, and you have the choice between the following players: Player Name OBP SLG Salary Yandy Diaz 0.403 0.511 $8,000,000 Joey Meneses 0.320 0.366 $723,600 Jose Abreu 0.292 0.358 $19,500,000 Ryan Noda 0.384 0.400 $720,000 Nate Lowe 0.365 0.426 $4,050,000

Given your budget and the player statistics, which two players would you select?

# Load dataset and fit model to predict Runs Scored using regression model (RS)
setwd("E:/S9510/CAP4936")
baseball <- read.csv("baseball.csv")
model_RS <- lm(RS ~ OBP + SLG, data = baseball)
# Create player data
players <- data.frame(Player = c("Yandy Diaz", "Joey Meneses", "Jose Abreu", "Ryan Noda", "Nate Lowe"),
  OBP = c(0.403, 0.320, 0.292, 0.384, 0.365),
  SLG = c(0.511, 0.366, 0.358, 0.400, 0.426),
  Salary = c(8000000, 723600, 19500000, 720000, 4050000)
)
# Predict expected runs
players$PredictedRuns <- predict(model_RS, newdata = players)
# Evaluate all 2-player combinations under $10.5M
player_combos <- combn(1:nrow(players), 2, simplify = FALSE)
best_combo <- NULL
best_total_runs <- -Inf

for (combo in player_combos) {
  total_salary <- sum(players$Salary[combo])
  total_runs <- sum(players$PredictedRuns[combo])
  if (total_salary <= 10500000 && total_runs > best_total_runs) {
    best_combo <- combo
    best_total_runs <- total_runs
  }
}
# Print the best combination
best_players <- players[best_combo, ]
print("Best 2-player combination under $10.5M:")
## [1] "Best 2-player combination under $10.5M:"
print(best_players[, c("Player", "OBP", "SLG", "Salary", "PredictedRuns")])
##       Player   OBP   SLG  Salary PredictedRuns
## 1 Yandy Diaz 0.403 0.511 8000000     1104.5942
## 4  Ryan Noda 0.384 0.400  720000      882.3596
print(paste("Total Predicted Runs:", round(best_total_runs)))
## [1] "Total Predicted Runs: 1987"
print(paste("Total Salary: $", sum(best_players$Salary)))
## [1] "Total Salary: $ 8720000"