Exercises

Instructions

Over the course of the semester, you are required to submit written solutions to two of the following exercises. You should prepare your solution in a Quarto file (i.e., a .qmd) that contains all code needed to reproduce your analysis. Your solution should be structured similarly to the lecture notes, with code tightly integrated with exposition.

Once you submit your solutions, you should respond to the corresponding post on Piazza with an overview of your analysis and the main results. In that post, you should also reflect on your analysis, commenting on matters including, but not limited to, limitations and potential extensions. If there are parts of your analysis about which you are unsure, you can raise those questions in your Piazza post! You will be required to respond to feedback and suggestions made by your fellow students about your solution. You must also provide constructive feedback to your peers’ solutions to exercises you have not submitted.

You should upload your Quarto markdown file (i.e., a .qmd) at this submission link. If you use external data (i.e., data that cannot be directly loaded into R), then you should submit a compressed archive (i.e., a .zip or a .tar.gz file) that contains the data and your Quarto markdown file. Be sure to include your name and the exercise number (e.g., 01-1 for Lecture 01, Exercise 1) in your submission’s filename.

Lecture 01

01-1: Best Shooting Performances in the WNBA

The package wehoop provides functions for scraping play-by-play and box score data for women’s college and professional basketball. Using that package, replicate the analysis from lecture to identify the best shooting performances in the WNBA between 2022 and now. To load in box score data, you will need to use the functions wehoop::load_wnba_player_box() and wehoop::most_recent_wnba_season() to load the raw box score data.

ImportantDifferences between the NBA and WNBA

The NBA and WNBA have different All-Star dates and the WNBA dataset may have slightly different column names than the NBA dataset. So, you will need to modify some parts of the code from Lecture 1 to run this analysis!

01-2: Four Factors

Dean Oliver, pioneer of basketball analytics, introduced Four Factors to describe how teams win. The Four Factors are computed from box score data at the team level and attempt to summarize a team’s performance in terms of shooting, rebounding, turnovers, and free throws. Using data from either the NBA or WNBA, compute the four factors for each team in every season since 2002. Which teams’ were the best in terms of each of these four factors?

01-3: Offensive Efficiency

Dean Oliver introduced an offensive efficiency metrics that tracks how many points are produced by an individual player over the course of 100 possessions. While it’s possible to compute offensive efficiency exactly using play-by-play or player-tracking data, these data were not always publicly available at the time that Oliver was writing. Oliver developed a formula for approximating offensive efficiency using only information contained in the box score; the offensive rating page on Basketball Reference has the full derivation.

Using either NBA or WNBA data, identify the player-seasons with the highest and lowest offensive ratings.

ImportantIntermediate Variables

To compute offensive rating formula, you will need to compute several intermediate variables that summarize both team and individual performance. Performing this analysis will require some clever grouping operations!

Lecture 2

02-1: Over- and Under-performing XG

For each team in EURO 2022, sum their \(\textrm{XG}_{i}\) values and sum the residuals \(Y_{i} - \textrm{XG}_{i}.\) Which teams most over- or under-performed expectations? What relationship, if any, do you observe between teams’ cumulative XG and their performance relative to the StatsBomb XG model’s expectations?

02-2: EURO 2025 Performance

During Lecture 2, we worked with data from EURO 2022 tournament. Hudl has released similar data from the EURO 2025 tournament (which was also won by the Three Lionesses). Repeat the analyses from Lecture 2 to identify the EURO 2025 players with the most extreme goals over expected values in that tournament. Similarly, repeat the exercise in Section 3.1 to identify teams that most over- or under-performed expectations (in terms of goal scoring) during EURO 2025.

02-3: League Performance

Hudl’s free data includes full seasons from several top professional leagues. Using the data from all complete league seasons explore the relationships between (i) the cumulative \(\textrm{XG}\) the team generates on offense; (ii) the cumulative \(\textrm{XG}\) the team gives up on defense; and (iii) their overall win-loss record. Do these relationships vary across leagues?

Lecture 3

03-1: \(\textrm{XG}\) and the Shot Cone

For every shot attempt, we can form a triangular region by connecting the shot location to the goal posts (whose coordinates are (120, 36) and (120, 44)) and connecting the two goal posts. We will refer to this region as the “shot cone”. Add two new feature to the data frame wi_shots that we created in Lecture 3: ConeAngle, which measures the angle between the lines connecting the shot location to the goal posts and ConeArea, which is the area of the shot cone.

Intuitively, what sorts of relationships would you expect between ConeAngle and ConeArea and XG?

ImportantNote

You do not necessarily need to fit any model to answer this question!

03-2: Predictive Utility of ConeAngle and ConeArea I

Using 100 random training/testing splits, how much predictive accuracy is gained (if any) by including ConeAngle, ConeArea, and both ConeAngle and ConeArea as additional features in the random forests model we built in Lecture 3?

03-3: Estimating XG Using More Data

In Lecture 3, we trained our XG models using only data from women’s international competitions. Train an XG model using data from at least 5 different full competitions contained in the public StatsBomb data. How similar are the XG predictions of your new model to the proprietary XG values provided by StatsBomb?

Lecture 4

04-1: Sensitivity of (Weighted) APM

In Lecture 4, we set a 250 minute threshold and collapsed all players below that threshold into a single baseline player. Re-fit the APM and weighted APM models using different choices of minutes cut-offs (e.g., 100 or 300). How much do the top- and bottom-10 player rankings change?

04-2: Re-thinking Stint Weights

In Lecture 4, we weighted stints using only the lead at the start of the stint. One could reasonably argue that weights should also account for the time left in the game. Propose your own weighting scheme and see how the player rankings change.

04-3: Predictive Quality of APM Models

Estimate the out-of-sample predictive mean square error of the basic APM model using 100 training/testing splits built in Lecture 4. That is, for each training and testing split, fit each model using the training data and then compute the average of the squared difference between the actual \(Y\)’s and the model predictions in the testing split. Is the basic APM model a good predictive model? Why or why not?

Lecture 5

05-1: Additional Player Comparisons

During Lecture 5, we used the bootstrap to quantify our uncertainty about the difference between Luka Dončić’s and Anthony Davis’ regularized APM estimates. Pick 10 players and compare the bootstrap distributions of the pairwise differences in their RAPM estimates.

05-2: Predictive Quality of RAPM Models

Using the same 100 training/testing splits constructed in Section 5.3, estimate the out-of-sample mean square error for our RAPM model based on the 2024-25 data. Instead of computing an optimal \(\lambda\) for each training split, you may use the optimal \(\lambda\) value computed for the whole datset. Is RAPM a better predictive model than APM?

Lecture 6

06-1: Run Value Created Over Time

Scrape data from the 2022, 2023, 2024, 2025, and 2026 regular seasons and re-run the analyses from Lecture 6. In particular, compute the final run value metric (i.e. RE24) for each batter-season. How predictive is RE24 across seasons? Is it more or less predictive than batting average?

06-2: More Granular Expected Runs

In Lecture 6, we computed the expected runs conditional on the number of outs and baserunner configuration. Compute a new, more granular version of the expected run matrix by conditioning on the number of outs, baserunner configuration, and ballpark. Using this new version of expected runs, re-compute run value and RE24 and determine which batters create the most run value for their team. Does ballpark appear to make much difference?

Lecture 8

08-1: More Granular Out Modeling

In Lecture 8, we modeled the probability of a batted ball resulting in out using just the batted ball location. Try adjusting for additional factors about the pitch and swing in our GAM. How do the out probabilities and our downstream analysis change when you account for these factors?

08-2: Replicate opeWAR Analysis

Replicate the full analytic pipeline from Lectures 7 and 8 to estimate WAR using data from the 2025 and 2026 regular seasons. How correlated are individual player’s WAR values and their constituent RAA_b, RAA_br, RAA_f, and RAA_p values across seasons? What are the implications if the season-to-season correlation is low?

Lecture 9

09-1: Per-Pass Win Probability Added

Arguably, a better measure of a play success than EPA is whether a play increased the offensive team’s chances of winning the game. nflfastR provides estimates of the win probability and win probability added. Repeat the modeling but with WPA instead of EPA. What is the relationship between per-pass WPA and per-pass EPA after adjusting for the same fixed effects from our full model?

09-2: Replicate Per-Pass EPA Analysis

Replicate the multilevel modeling of per-pass EPA using data from the 2022-23, 2023-24, and 2025-26 regular seasons. To what extent is a quarterback’s per-pass EPA in one season predictive of their per-pass EPA in the next season?

Lecture 10

10-1: Win Probability-Based WAR

Repeat the analysis from Lecture 10 using win probability added instead of expected points added. Note,you do not need to convert from the points to win scale in this re-analysis. Which players appear to contribute the most to their team’s overall win probability?

10-2: Replicate nflWAR Analysis

Replicate the full NFL WAR analysis using data from 2022-23, 2023-24, and 2025-26 regular seasons. To what extent are individual players’ IPAR, IPAA, and WAR values stable across seasons?

Lecture 11

11-1: Replicate RSAR Analysis

Replicate the full Runs Saved Above Replacement analysis for the 2023 and 2024 regular seasons. To what extend do catchers’ RSAR values vary season-to-season? What are potential implications of such variability to roster building?

11-2: Pitcher Framing Metric

We used the catcher random effects from a multilevel model to estimate how much more each catcher contributed to the probability of a called strike than a replacement-level catcher. Those estimated contributions formed the basis of the catcher metric RSAR.

One could argue, however, that pitchers are responsible for at least some of the value created by pitch framing; after all, for a catcher to frame a pitch successfully, the pitcher must throw a frameable pitch! Using the multilevel model from Lecture 11, create and compute an analog of RSAR for pitchers.

11-3: Adjusting for Batter and Pitcher Quality

The historical GAM model we built in Lecture 11 only accounted for pitch location. That model and the multilevel model we fit to estimate catcher effects did not adjust for the quality of the batter or pitcher. It is at least conceivable that umpire’s may call the strike zone for an elite, veteran batter differently than they would for a batter who has just been called up. Re-fit the historical GAM to adjust for the batter’s wOBA and pitcher’s ERA, both computed at the end of the 2024 regular season, in addition to the pitch location. Similarly, re-fit the multilevel model to adjust for batter’s wOBA and pitcher’s ERA computed at the end of the 2025 as fixed effects. How do the resulting RSAR estimates and catcher rankings change after we adjust for batter and pitcher quality in both component models.

Lecture 12

12-1: Ranking for Men’s D1 Hockey

College Hockey Inc. presents a tabular view of the results of all Division 1 men’s hockey games from the 2025-26 season. Create a CSV file, similar to the one we worked with in Lecture 12 for the results of women’s hockey, and fit a Bradley-Terry model to estimate the latent strengths of all D1 men’s hockey teams.

Lecture 13

13-1: Uncertainty about Team Rankings

Use the bootstrap to quantify the uncertainty in relative rankings of each team. To do this, you will need to re-sample individual games, re-compute the numbers of home & away team wins for every combination of teams and neutral, and fit a Bradley-Terry model. Report the number of bootstrap simulations in which Wisconsin was ranked 1st and also report a 95% bootstrap confidence interval for Wisconsin’s overall rank.

13-2: Full Tournament Simulation

Build a simulation for the entire NCAA Tournament based on the estimating probabilities from our Bradley-Terry model that accounts for home advantage. In this tournament, the first round and quarterfinals were held on the campuses of the top-4 seeded teams (Ohio State, Wisconsin, Penn State, and Minnesota). Subsequent games were played at Penn’s State’s home arena. Your simulation should involve only the 11 teams who actually played in the tournament

13-3: Replicate Analysis for D1 Men’s Hockey

Replicate the analyses from Lecture 13 for Division 1 Men’s Hockey. You will need to use the data introduced in Exercise 12-1

Lecture 15

15-1: Run Expectancy via Markov Chains

When simulating the number of runs scored in the half-inning, we initialized our Markov chains from 0.000, which is the state at the start of every half-inning. By initializing at some other state — say 1.000 — we can study the distribution of runs scored after an at-bat beginning in that state. Use a Markov chain simulation to estimate the run expectancy for every state and compare it to the matrix we estimated in Lecture 6.

15-2: Whole-game Simulation

It is straightforward to use the Markov chain simulator for half-innings developed in Lecture 15 to simulate an entire game’s worth of at-bats. Specifically, a single iteration of the whole game simulator multiple sequential runs of the half-inning simulator. Using this simulator, you can compute many things, including the scores of each team and many box score statistics (e.g., single, double, RBIs), which can be computed directly from the game state transitions. Build a whole-game simulator and look at the distribution of some box score statistics. You could also

Lectures 16-17

16-1: Starting Contexts

The drive simulator in we built in Lecture 17 repeatedly identifies the down, distance, and absolute position on the field (i.e., the starting context) for a given play and then samples the play results from the pool of plays with similar starting contexts. As noted in lecture, the contexts are not equally represented in the data. Identify the most and least common starting contexts. Does that match your intuition?

16-2: Regulation Drive Simulator

In lecture, we built a simulator for drives under new potential overtime rules. Modify the underlying logic to build a realistic simulation of drives in regulation, when teams have the option to not “go for it” on 4th down. You will specifically need to adjust the logic employed on 4th down and you will need to re-define the pool of potential plays from which to sample.