combine_data <- function(years = c(2023), season_type = "regular", conference = "ACC") {
# Combine the data from each year
data <- lapply(years, function(year) {
cfbfastR::cfbd_game_info(year = year, season_type = season_type, conference = conference) |>
dplyr::filter(home_conference == "ACC" & away_conference == "ACC") |>
dplyr::select(season, week, home_team, home_points, away_team, away_points)
})
# Bind the data together
data <- dplyr::bind_rows(data)
# Filter out any rows with missing values for home_points
data <- data |> dplyr::filter(!is.na(home_points))
# Return the data
return(data)
}
acc_data <- combine_data(years = c(2023))
home_results <- acc_data |>
dplyr::mutate(h_result = dplyr::if_else(home_points > away_points,
"W", "L")) |>
dplyr::group_by(home_team, h_result) |>
dplyr::count() |>
tidyr::pivot_wider(
names_from = h_result,
values_from = n) |>
dplyr::rename(team = home_team, h_w = W, h_l = L) |>
dplyr::mutate_at(dplyr::vars(h_w, h_l), (~replace(., is.na(.), 0)))
away_results <- acc_data |>
dplyr::mutate(a_result = dplyr::if_else(away_points > home_points,
"W", "L")) |>
dplyr::group_by(away_team, a_result) |>
dplyr::count() |>
tidyr::pivot_wider(
names_from = a_result,
values_from = n) |>
dplyr::rename(team = away_team, a_w = W, a_l = L) |>
dplyr::mutate_at(dplyr::vars(a_w, a_l), (~replace(., is.na(.), 0))) |>
dplyr::ungroup()
full_recs <- merge(home_results, away_results, by = "team") |>
dplyr::mutate_all(list(~ifelse(is.na(.), 0, .))) |>
dplyr::mutate(W = (h_w + a_w), L = (h_l + a_l)) |>
dplyr::select(team, W, L, h_w, h_l, a_w, a_l)
home_diffs <- acc_data |>
dplyr::mutate(h_diff = home_points - away_points) |>
dplyr::group_by(home_team) |>
dplyr::summarize(home_diff = sum(h_diff)) |>
dplyr::rename(team = home_team)
away_diffs <- acc_data |>
dplyr::mutate(a_diff = away_points - home_points) |>
dplyr::group_by(away_team) |>
dplyr::summarize(away_diff = sum(a_diff)) |>
dplyr::rename(team = away_team)
full_diffs <- merge(home_diffs, away_diffs, by = "team") |>
dplyr::mutate(full_diff = (home_diff + away_diff)) |>
dplyr::select(team, full_diff, home_diff, away_diff)
diffs_recs <- merge(full_diffs, full_recs, by ="team")
# spread
spread <- tibble::tribble(
~Season,~Opponent,~Spread,~Results,~Score,
2023,"Virginia",-23.5,"L","17-21",
2022,"Georgia Tech",-21.5,"L","17-21",
2021,"South Carolina",-12,"L","21-38",
2021,"Florida State",-17.5,"L","25-35",
2021,"at Georgia Tech",-14.5,"L","22-45",
2020,"at Florida State",-13.5,"L","28-31"
)