Helper function to prepare fastRhockey PBP data for expected goals (xG) calculations.
Adapted from the hockeyR helper_nhl_prepare_xg_data() function. The feature
engineering logic (lag events, era dummies, shot metrics, one-hot
encoding) is identical to the hockeyR xG training pipeline so that the
same xgboost models can be used for inference.
Arguments
- x
A play-by-play data frame produced by
nhl_game_pbpornhl_game_feed.
Details
The function:
Filters out shootouts, penalty shots, and shift-change events.
Computes lag features (last event type/team, time since last, distance from last, event zones).
Adds era dummies for the four training eras (2011-13, 2014-18, 2019-21, 2022+).
Computes tactical booleans:
rebound,rush,cross_ice_event.One-hot encodes
shot_typeandlast_event_type.Pads any missing model features to zero so the xgboost DMatrix dimensions match the trained models.
