Introduction

Does a strong first quarter help predict the final winning margin in an Australian Football League (AFL) match?

This tutorial uses 2023 AFL match data to investigate the relationship between a team’s first-quarter points margin and its final points margin.

In my first resource, I used logistic regression to investigate whether a team won or lost. In this resource, I use linear regression to investigate a numerical outcome: the final points margin.

Data source

The dataset contains AFL match results from the 2023 season, including team names and quarter-by-quarter scores.

The CSV file used in this tutorial is called matches_2023 AFL.csv.

1. Load the data

We use the tidyverse package to import and analyse the dataset.

library(tidyverse)

afl <- read_csv("matches_2023 AFL.csv")

head(afl)
## # A tibble: 6 × 22
##   round_num venue     date                 year team_1_team_name team_1_q1_goals
##   <chr>     <chr>     <dttm>              <dbl> <chr>                      <dbl>
## 1 1         M.C.G.    2023-03-16 19:20:00  2023 Richmond                       1
## 2 1         M.C.G.    2023-03-17 19:40:00  2023 Geelong                        6
## 3 1         Docklands 2023-03-18 13:45:00  2023 North Melbourne                3
## 4 1         Adelaide… 2023-03-18 16:05:00  2023 Port Adelaide                  3
## 5 1         M.C.G.    2023-03-18 19:25:00  2023 Melbourne                      3
## 6 1         Carrara   2023-03-18 19:00:00  2023 Gold Coast                     2
## # ℹ 16 more variables: team_1_q1_behinds <dbl>, team_1_q2_goals <dbl>,
## #   team_1_q2_behinds <dbl>, team_1_q3_goals <dbl>, team_1_q3_behinds <dbl>,
## #   team_1_final_goals <dbl>, team_1_final_behinds <dbl>,
## #   team_2_team_name <chr>, team_2_q1_goals <dbl>, team_2_q1_behinds <dbl>,
## #   team_2_q2_goals <dbl>, team_2_q2_behinds <dbl>, team_2_q3_goals <dbl>,
## #   team_2_q3_behinds <dbl>, team_2_final_goals <dbl>,
## #   team_2_final_behinds <dbl>

2. Calculate the scores

In Australian rules football, a goal is worth six points and a behind is worth one point.

We calculate each team’s first-quarter points and final points. We then calculate the margin between Team 1 and Team 2.

afl <- afl %>%
  mutate(
    team1_q1_points =
      team_1_q1_goals * 6 + team_1_q1_behinds,

    team2_q1_points =
      team_2_q1_goals * 6 + team_2_q1_behinds,

    team1_final_points =
      team_1_final_goals * 6 + team_1_final_behinds,

    team2_final_points =
      team_2_final_goals * 6 + team_2_final_behinds,

    q1_margin = team1_q1_points - team2_q1_points,

    final_margin = team1_final_points - team2_final_points
  )

A positive margin means Team 1 is ahead, while a negative margin means Team 1 is behind.

3. Explore the data

Before fitting the model, we can examine the distribution of first-quarter and final margins.

summary(afl$q1_margin)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -47.000  -9.000   2.000   2.667  12.250  57.000
summary(afl$final_margin)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
## -108.000  -16.250    5.000    8.792   32.000  171.000

We can also calculate the average margins.

afl %>%
  summarise(
    average_q1_margin = mean(q1_margin, na.rm = TRUE),
    average_final_margin = mean(final_margin, na.rm = TRUE)
  )
## # A tibble: 1 × 2
##   average_q1_margin average_final_margin
##               <dbl>                <dbl>
## 1              2.67                 8.79

In this dataset, the average first-quarter margin is approximately 2.67 points, while the average final margin is approximately 8.79 points.

4. Visualise the relationship

A scatterplot helps us investigate whether matches with larger first-quarter margins tend to have larger final margins.

ggplot(afl, aes(x = q1_margin, y = final_margin)) +
  geom_point(alpha = 0.6) +
  geom_smooth(method = "lm", se = TRUE) +
  labs(
    title = "First-Quarter Margin and Final AFL Margin",
    x = "Team 1's first-quarter points margin",
    y = "Team 1's final points margin"
  ) +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

Each point represents one match. The blue line shows the fitted linear relationship, and the shaded area represents its confidence interval.

The upward slope suggests that a larger first-quarter margin tends to be associated with a larger final margin.

5. Fit a linear regression model

Linear regression investigates the relationship between a numerical outcome and one or more predictors.

In this analysis, the predictor is the first-quarter points margin, and the outcome is the final points margin. We use the lm() function to fit the model.

model <- lm(
  final_margin ~ q1_margin,
  data = afl
)

summary(model)
## 
## Call:
## lm(formula = final_margin ~ q1_margin, data = afl)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -85.453 -22.013  -2.906  22.646  90.165 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   4.8974     2.1654   2.262   0.0247 *  
## q1_margin     1.4603     0.1254  11.641   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 31.44 on 214 degrees of freedom
## Multiple R-squared:  0.3877, Adjusted R-squared:  0.3849 
## F-statistic: 135.5 on 1 and 214 DF,  p-value: < 2.2e-16

6. Interpret the model

The regression output provides the estimated coefficient, p-value and R-squared value.

The coefficient for q1_margin is approximately 1.4603. This means that each additional point in Team 1’s first-quarter margin is associated with an estimated increase of approximately 1.46 points in its final margin, on average.

The p-value for q1_margin is less than 2 × 10⁻¹⁶. This provides strong statistical evidence of a positive linear relationship in this dataset.

The model’s R-squared value is 0.3877, meaning that approximately 38.8% of the variation in final margins is accounted for by the linear relationship with first-quarter margins.

The intercept is approximately 4.90. This is the predicted final margin when the first-quarter margin is zero.

These results suggest that first-quarter margin is associated with final match margin, although the model does not explain all the variation in match results.

7. Predict the final margin

We can use the fitted model to estimate final margins for different first-quarter margins.

new_margins <- tibble(
  q1_margin = seq(-30, 30, by = 5)
)

new_margins$predicted_final_margin <- predict(
  model,
  newdata = new_margins
)

new_margins
## # A tibble: 13 × 2
##    q1_margin predicted_final_margin
##        <dbl>                  <dbl>
##  1       -30                 -38.9 
##  2       -25                 -31.6 
##  3       -20                 -24.3 
##  4       -15                 -17.0 
##  5       -10                  -9.71
##  6        -5                  -2.40
##  7         0                   4.90
##  8         5                  12.2 
##  9        10                  19.5 
## 10        15                  26.8 
## 11        20                  34.1 
## 12        25                  41.4 
## 13        30                  48.7

For example, when Team 1’s first-quarter margin is 10 points, the model predicts a final margin of approximately 19.5 points.

These are model estimates, not guarantees of actual match results.

8. Plot the predicted margins

ggplot(
  new_margins,
  aes(x = q1_margin, y = predicted_final_margin)
) +
  geom_line() +
  geom_point() +
  labs(
    title = "Predicted Final Margin from First-Quarter Margin",
    x = "Team 1's first-quarter points margin",
    y = "Predicted final points margin"
  ) +
  theme_minimal()

The graph shows the final margins predicted by the model for different first-quarter margins. The upward line reflects the positive coefficient from the linear regression.

9. Results and interpretation

The linear regression found a positive relationship between first-quarter margin and final margin. The estimated coefficient was 1.4603, with a p-value below 2 × 10⁻¹⁶.

The R-squared value was 0.3877, indicating that first-quarter margin accounted for approximately 38.8% of the variation in final margins in this dataset.

The model predicts that a 10-point first-quarter margin corresponds to a final margin of approximately 19.5 points. This is a prediction from the fitted model rather than a guaranteed result.

Overall, the findings suggest that teams with stronger first-quarter margins tend to finish with more favourable final margins. However, substantial variation remains unexplained by the model.

10. Limitations and conclusion

This analysis uses one season of AFL data and only one predictor. Other factors, such as team strength, injuries, venue and performance in later quarters, may also affect the final margin.

An important limitation is that the final score includes the points scored in the first quarter. Therefore, part of the relationship is expected because the first-quarter margin contributes directly to the final margin. The model does not prove that a strong first quarter independently causes a larger winning margin.

In conclusion, linear regression provides a way to describe and predict the relationship between first-quarter margin and final AFL margin. The results suggest that first-quarter performance is associated with the final margin, but predictions should be interpreted with these limitations in mind.