Skip to content

Bug: implied_total calculation reversed for home teams in ep_preprocess.R #24

@cschupbach

Description

@cschupbach

Issue

In R/ep_preprocess.R[42-50], the calculation of implied_total in .preprocess_common_fields() reverses the logic for home and away teams. The result assigns the away implied total to both teams when the home team is favored.

Current output

Example using 2025_07_TB_DET:

game_id posteam posteam_type spread_line total_line implied_total
2025_07_TB_DET DET home 6.0 54.5 24.25
2025_07_TB_DET TB away 6.0 54.5 24.25
  • In nflverse play-by-play data, spread_line is from the home team’s perspective (+6 = home favored).

Expected behavior

  • Home (DET): implied_total = (total_line + spread_line) / 2 = (54.5 + 6.0) / 2 = 30.25
  • Away (TB): implied_total = (total_line - spread_line) / 2 = (54.5 - 6.0) / 2 = 24.25

Proposed fix

Replace the existing case_when() logic with:

implied_total = dplyr::if_else(
  .data$posteam_type == "home",
  (.data$total_line + .data$spread_line) / 2,
  (.data$total_line - .data$spread_line) / 2
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions