Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ jobs:
Rscript tutorials/quote-joins/odds_join.R
Rscript tutorials/quote-joins/test_odds_join.R

- name: Check the downloadable NFL kicker project
run: |
unzip -q tutorials/nfl-kicker-joins.zip -d "$RUNNER_TEMP/kicker-project"
diff -r tutorials/nfl-kicker-joins "$RUNNER_TEMP/kicker-project/nfl-kicker-joins"
cd "$RUNNER_TEMP/kicker-project/nfl-kicker-joins"
Rscript lesson.R
Rscript test_lesson.R

- name: Check point-in-time replay tutorial
working-directory: tutorials/point-in-time
run: |
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Featured as a Highlight in [R Weekly 2026-W38](https://rweekly.org/2026-W38.html
The tutorial includes a next step for checking your own books, markets and
request budget before selecting a paid plan.

[Where did 49 NFL team-games go?](https://github.com/JacobiusMakes/parlayapiR/tree/main/tutorials/nfl-kicker-joins) Compare two ways of counting teams that made an extra point. The offline RStudio project includes the 2025 game and kicker tables.

## Plan the first private request

Use the free [API workload planner](https://parlay-api.com/tools/api-workload?utm_source=github&utm_medium=r_readme&utm_campaign=request-planning)
Expand Down
Binary file added tutorials/nfl-kicker-joins.zip
Binary file not shown.
53 changes: 53 additions & 0 deletions tutorials/nfl-kicker-joins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Where did 49 NFL team-games go?

The Raiders beat Kansas City 14–12 on January 4, 2026. Daniel Carlson and Harrison Butker each kicked four field goals. A Raiders safety supplied the other two points. Neither team attempted an extra point. Start your analysis with a table of players who attempted one and that entire game disappears. [Raiders game recap](https://www.raiders.com/news/game-recap-raiders-season-capped-off-with-60-yard-field-goal-over-kansas-city-chiefs)

[Download the offline RStudio project (ZIP)](https://raw.githubusercontent.com/JacobiusMakes/parlayapiR/main/tutorials/nfl-kicker-joins.zip). Unzip it, open `nfl-kicker-joins.Rproj`, and run these lines in the R console. Both CSV files are included. You can also run `Rscript lesson.R` from the extracted directory with base R.

```r
source("lesson.R")
games <- read.csv("team-games.csv")
kickers <- read.csv("kickers.csv")
board <- join_kickers(games, kickers)
compare_denominators(board)
```

| Question about the 2025 regular season | Team-games with a make | Team-games counted | Share |
| --- | ---: | ---: | ---: |
| Among teams that attempted an extra point, how often did the team make at least one? | 487 | 495 | 98.38% |
| Across all scheduled team-games, how often did the team make at least one? | 487 | 544 | 89.52% |

A team-game means one team in one game. Each of the 272 games contributes two. The first question excludes 49 team-games with no PAT attempt. Both questions count the eight team-games with an attempt and zero makes. For the percentage of individual kicks that went in, divide made kicks by attempted kicks instead.

## Follow one team

```r
compare_denominators(subset(board, team == "LV"))
subset(board, game_id == "2025_18_KC_LV",
select = c(team, opponent, attempts, made))
```

Las Vegas made at least one PAT in all 12 games in which it attempted one. Across its full 17-game schedule, the same numerator gives 70.59%. To see the underlying player records, use the [searchable kicker table in Spanish and English](https://jacobiusmakes.github.io/parlayapi-notebooks/nfl-kicker-extra-points/).

## Catch a missing record

Delete the player row for Detroit's seven successful tries in Week 2. Run the join again and read the error.

```r
incomplete <- subset(kickers, !(game_id == "2025_02_CHI_DET" & team == "DET"))
join_kickers(games, incomplete)
```

The complete team play log records seven attempts for Detroit, so the missing player row cannot become zero. The script also checks duplicate player identities and reconciles the counts after grouping by team and game.

When testing a bookmaker's player market, define the denominator again. You need the players who were actually offered, their market, side, line, price and receipt time at your cutoff. The completed game establishes the sporting result. It cannot establish who was offered or how a sportsbook handles non-participation.

If you are choosing an archive for that part of the project, [check its sport and source date range](https://parlay-api.com/historical-coverage?utm_source=github&utm_medium=r_tutorial&utm_campaign=r_nfl_kicker_join). Verify the particular player market and observation time with a priced sample.

## Sources and reproduction

`kickers.csv` is a copy of the [published player-game file at commit 649437a](https://raw.githubusercontent.com/JacobiusMakes/parlayapi-notebooks/649437a75adb6412169098619d2bf776d9d1b233/docs/nfl-kicker-data/2025-regular-season.csv). It was derived from nflverse weekly player stats and reconciled against the play log. Its SHA-256 is `8f151846ceca73e505f0a26c281e82553f5c910709aef11fbc8436af673c5ac2`.

`team-games.csv` enumerates both sides of every regular-season game in the [nflverse 2025 play-by-play release](https://github.com/nflverse/nflverse-data/releases/download/pbp/play_by_play_2025.csv.gz). The builder counts credited one-point kicking attempts and successful results by the team in possession. The two files share underlying nflverse data. ParlayAPI selected and aggregated the fields. Both CSVs retain the [CC BY 4.0 data license](https://creativecommons.org/licenses/by/4.0/).

To regenerate the team input, download the compressed play-by-play file and run `python3 build_team_games.py play_by_play_2025.csv.gz rebuilt.csv`. Its compressed source SHA-256 is `c5d8ea60b5b9163a6db133a0a7a868fb4a325cda03a22e9e1cf620a6868ac280`. Run `Rscript test_lesson.R` from the project directory to check the exercise.
44 changes: 44 additions & 0 deletions tutorials/nfl-kicker-joins/build_team_games.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Extract team-game opportunities from the complete 2025 NFL play-by-play file."""
import csv
import gzip
import sys
from collections import Counter
from datetime import date


def extract(plays, output):
teams = {}
seen = set()
with gzip.open(plays, "rt", newline="", encoding="utf-8") as stream:
for row in csv.DictReader(stream):
if (row["season"], row["season_type"]) != ("2025", "REG"):
continue
game = row["game_id"]
home, away = row["home_team"], row["away_team"]
for team, opponent in ((home, away), (away, home)):
key = game, team
info = (date.fromisoformat(row["game_date"]).isoformat(), int(row["week"]), opponent)
if key not in teams:
teams[key] = (info, Counter())
if teams[key][0] != info:
raise ValueError(f"Inconsistent fixture {key}")
if row["extra_point_attempt"] != "1":
continue
play = game, row["play_id"]
result = row["extra_point_result"]
if (play in seen or row["play_type"] != "extra_point" or
result not in ("good", "failed", "blocked") or row["play_deleted"] == "1"):
raise ValueError(f"Ambiguous PAT {play}")
seen.add(play)
teams[game, row["posteam"]][1][result] += 1
if len(teams) != 544 or len({game for game, team in teams}) != 272:
raise ValueError("Unexpected 2025 schedule")
with open(output, "w", newline="", encoding="utf-8") as stream:
writer = csv.writer(stream, lineterminator="\n")
writer.writerow(["game_id", "game_date", "week", "team", "opponent", "play_attempts", "play_made"])
for (game, team), ((day, week, opponent), counts) in sorted(teams.items()):
writer.writerow([game, day, week, team, opponent, sum(counts.values()), counts["good"]])


if __name__ == "__main__":
extract(*sys.argv[1:])
Loading
Loading