Skip to main content

Time-Series Regression (ARIMAX): Did the Seat Belt Law Save Drivers?

Regression with ARIMA errors in R with arima() and the forecast package, on 16 years of monthly road casualties in Great Britain around the seat belt law of 1983: why least squares misjudges time series, seasonal differences, choosing the order with the ACF and AICc, the step effect of a law with petrol price and traffic as covariates, residual checks, the world without the law, placebo dates and a control group, spurious regression, and APA reporting.

The question: one law, one country, one date

On 31 January 1983 wearing a seat belt became compulsory for drivers and front-seat passengers in Great Britain. Did it save lives? The government asked two statisticians to find out (Harvey & Durbin, 1986).

There is no control group. The law came for everybody on the same day. All there is are the numbers of casualties, month by month, for years before and two years after. The question is whether the series stepped down at the date of the law, by more than its usual ups and downs.

A regression with a dummy variable for “after the law” seems to do it. But months that follow each other are not independent: a bad autumn affects several months, the economy goes in waves, and every December is worse than every June. Ordinary least squares takes neighboring months for new information, and its standard errors are wrong.

Regression with ARIMA errors (often called ARIMAX) has two parts: a regression for what we want to know, and an ARIMA model for how the rest moves over time. Used for a question like this, it is called interrupted time series or intervention analysis (Box & Tiao, 1975).

Code
library(forecast)   # Arima(), auto.arima(), forecast()
library(ggplot2)

# number formats for the text
f0   <- function(x) formatC(x, format = "f", digits = 0, big.mark = ",")
f1   <- function(x) formatC(x, format = "f", digits = 1, big.mark = ",")
f2   <- function(x) formatC(x, format = "f", digits = 2, big.mark = ",")
f3   <- function(x) formatC(x, format = "f", digits = 3, big.mark = ",")
# no leading zero
nz <- function(x, d = 2) sub("^(-?)0", "\\1", formatC(x, format = "f", digits = d))
pval <- function(p) if (p < .001) "< .001" else paste("=", nz(p, 3))
pct  <- function(x, d = 0) paste0(formatC(100 * x, format = "f", digits = d), "%")

1. The data

The data come with R, as the time series Seatbelts: 192 months, from January 1969 to December 1984.

Code
head(Seatbelts, 2)
         DriversKilled drivers front rear  kms PetrolPrice VanKilled law
Jan 1969           107    1687   867  269 9059   0.1029718        12   0
Feb 1969            97    1508   825  265 7685   0.1023630         6   0
Code
road <- data.frame(date = as.numeric(time(Seatbelts)), as.data.frame(Seatbelts))
y <- log(Seatbelts[, "drivers"]) # log of the car drivers killed or seriously injured
X <- cbind(
  law = Seatbelts[, "law"],
  petrol = log(Seatbelts[, "PetrolPrice"]),
  km = log(Seatbelts[, "kms"])
)
c(months = nrow(road), months_with_the_law = sum(road$law))
             months months_with_the_law 
                192                  23 

drivers is the number of car drivers killed or seriously injured in the month, rear the same for rear-seat passengers, whom the law did not concern. kms is the distance driven, PetrolPrice the price of petrol, and law is 1 from February 1983. We take logarithms: effects on casualties are percentages, and a seasonal swing that grows with the level becomes constant.


2. Look at the data

Code
long <- rbind(
  data.frame(date = road$date, n = road$drivers, who = "drivers"),
  data.frame(date = road$date, n = road$rear, who = "rear-seat passengers (no law)")
)
ggplot(long, aes(date, n)) +
  geom_line(colour = "grey40", linewidth = 0.5) +
  geom_vline(xintercept = 1983 + 1 / 12, colour = "#eb6834", linetype = "dashed", linewidth = 0.8) +
  facet_wrap(~who, ncol = 1, scales = "free_y") +
  labs(
    title = "Killed or seriously injured, per month",
    subtitle = "Dashed line: the seat belt law",
    x = NULL,
    y = NULL
  ) +
  theme_bw()

Plot: 2. Look at the data

Code
before <- mean(road$drivers[road$date >= 1982 & road$date < 1983])
after <- mean(road$drivers[road$date >= 1983 + 1 / 12 & road$date < 1984 + 1 / 12])
c(mean_1982 = before, mean_of_the_first_year = after, change = after / before - 1)
             mean_1982 mean_of_the_first_year                 change 
          1621.6666667           1277.9166667             -0.2119733 

The drivers’ series has a strong yearly wave, a fall after the oil crisis of 1973–74, slow drifts, and a drop at the dashed line. In the year after the law there were 21% fewer casualties than in 1982. The series of the rear passengers shows no such drop. But how much of the drop is the law, and how much would have happened anyway?


3. Why least squares is not enough

Code
month <- factor(cycle(y))
ols <- lm(y ~ X[, "law"] + X[, "petrol"] + X[, "km"] + month)
round(coef(summary(ols))[2:4, ], 3)
              Estimate Std. Error t value Pr(>|t|)
X[, "law"]      -0.161      0.023  -7.121    0.000
X[, "petrol"]   -0.403      0.057  -7.111    0.000
X[, "km"]       -0.157      0.046  -3.427    0.001
Code
r_acf <- acf(resid(ols), plot = FALSE, lag.max = 24)$acf[-1]
round(r_acf[1:12], 2)
 [1] 0.45 0.38 0.26 0.20 0.27 0.21 0.18 0.09 0.16 0.10 0.20 0.20
Code
lb_ols <- Box.test(resid(ols), lag = 24, type = "Ljung-Box"); lb_ols$p.value
[1] 0

With a dummy for each month of the year, OLS finds an effect of the law of -0.16 on the log scale. But the residuals correlate with those of the next month at 0.45, and with those of two months later at 0.38. The Ljung–Box test of the first 24 autocorrelations has p < .001. The standard errors are too small, and they cannot be repaired by a formula that does not know how the series moves.


4. The model step by step, with formulas

Step 1: regression with errors that remember

\[y_t = \beta_1\,\text{law}_t + \beta_2\,\text{petrol}_t + \beta_3\,\text{km}_t + n_t\]

\(n_t\) is everything else, and it follows a time-series model. The \(\beta\)’s have their usual meaning.

Step 2: ARIMA, three ingredients

  • AR(p): today’s value depends on the last ones, \(n_t = \phi_1 n_{t-1} + \dots + e_t\).
  • MA(q): today’s value depends on the last shocks, \(n_t = e_t + \theta_1 e_{t-1} + \dots\).
  • I(d): the series is differenced \(d\) times to remove a drift, \(n_t - n_{t-1}\).

Step 3: the season

The same three for the same month of last year, with capital letters: ARIMA\((p,d,q)(P,D,Q)_{12}\). A seasonal difference (\(D = 1\)), \(n_t - n_{t-12}\), compares each month with the same month a year ago. It removes the yearly wave even if it changes slowly. When the errors are differenced, the regression is too: the law is compared as a change.

Step 4: what the estimate does

With AR(1) errors, the likelihood is that of the regression on quasi-differenced data, \(y_t - \phi y_{t-1}\) against \(x_t - \phi x_{t-1}\) (see generalized least squares). The new information of each month is only what the last month did not already say. By hand, for AR(1) errors and month dummies:

Code
months <- model.matrix(~ month)[, -1]; Xm <- matrix(X, ncol = 3, dimnames = list(NULL, colnames(X)))
Z  <- cbind(months, Xm); XX <- cbind(1, Z); n <- length(y)
profile_ll <- function(phi) {
  # exact likelihood for a given phi (Prais-Winsten)
  q <- function(v) c(sqrt(1 - phi^2) * v[1], v[-1] - phi * v[-n])
  f <- lm.fit(apply(XX, 2, q), q(as.numeric(y)))
  s2 <- mean(f$residuals^2)
  -n / 2 * (log(2 * pi * s2) + 1) + 0.5 * log(1 - phi^2)
}
phi_hat <- optimize(profile_ll, c(-0.99, 0.99), maximum = TRUE)$maximum
q <- function(v) c(sqrt(1 - phi_hat^2) * v[1], v[-1] - phi_hat * v[-n])
hand <- setNames(
  lm.fit(apply(XX, 2, q), q(as.numeric(y)))$coefficients,
  c("(Intercept)", colnames(Z))
)
ar1 <- arima(y, order = c(1, 0, 0), xreg = Z, method = "ML")
rbind(
  by_hand = c(phi = phi_hat, hand[c("law", "petrol", "km")]),
  arima = coef(ar1)[c("ar1", "law", "petrol", "km")]
)
             phi        law     petrol         km
by_hand 0.452686 -0.1731235 -0.3780838 -0.1324072
arima   0.452697 -0.1731300 -0.3780785 -0.1324141

5. Choosing the order

Code
# searches over the orders, with the AICc
auto <- auto.arima(y, xreg = X, stepwise = FALSE, approximation = FALSE)
auto
Series: y 
Regression with ARIMA(1,0,3)(0,1,1)[12] errors 

Coefficients:
         ar1      ma1     ma2      ma3     sma1      law   petrol      km
      0.9818  -0.7106  0.0566  -0.1851  -0.8536  -0.2219  -0.3083  0.1077
s.e.  0.0184   0.0753  0.0982   0.0815   0.0789   0.0419   0.0946  0.1187

sigma^2 = 0.005586:  log likelihood = 208.25
AIC=-398.49   AICc=-397.43   BIC=-369.75
Code
candidates <- list(
  `(1,0,0)(0,1,1)` = c(1, 0, 0),
  `(1,0,1)(0,1,1)` = c(1, 0, 1),
  `(2,0,1)(0,1,1)` = c(2, 0, 1),
  `(0,1,1)(0,1,1)` = c(0, 1, 1),
  `(1,0,3)(0,1,1)` = c(1, 0, 3)
)
fits <- lapply(candidates, function(o) Arima(y, order = o, seasonal = c(0, 1, 1), xreg = X))
comp <- t(sapply(fits, function(m) {
  c(
    AICc = m$aicc,
    law = coef(m)[["law"]],
    SE = sqrt(vcov(m)["law", "law"]),
    Ljung_Box_p = Box.test(resid(m), 24, fitdf = length(coef(m)) - 3, type = "Ljung-Box")$p.value
  )
}))
round(comp, 3)
                   AICc    law    SE Ljung_Box_p
(1,0,0)(0,1,1) -381.611 -0.175 0.034       0.000
(1,0,1)(0,1,1) -395.050 -0.224 0.049       0.012
(2,0,1)(0,1,1) -395.573 -0.223 0.042       0.006
(0,1,1)(0,1,1) -389.272 -0.244 0.047       0.005
(1,0,3)(0,1,1) -397.432 -0.222 0.042       0.038

auto.arima() chooses the smallest AICc among many models. (AICs can only be compared between models with the same differences: the one with \(d = 1\) is in another league.) What matters more than the winner is the column law: whatever the order, the effect is between -0.24 and -0.18. The OLS estimate of -0.16 was smaller, probably because the month dummies and the straight regression could not follow the slow drifts. We take the winner.

Code
fit <- auto
b <- coef(fit)[c("law", "petrol", "km")]; se <- sqrt(diag(vcov(fit)))[c("law", "petrol", "km")]
tab <- cbind(b, SE = se, z = b / se, p = 2 * pnorm(-abs(b / se)), effect = exp(b) - 1)
round(tab, 4)
             b     SE       z      p  effect
law    -0.2219 0.0419 -5.2909 0.0000 -0.1990
petrol -0.3083 0.0946 -3.2602 0.0011 -0.2653
km      0.1077 0.1187  0.9069 0.3645  0.1137
Code
ci <- exp(b[["law"]] + c(-1.96, 1.96) * se[["law"]]) - 1
  • law = -0.222: the number of drivers killed or seriously injured was \(e^{-0.222}\) = 0.80 times what it would have been, a fall of 20%, 95% CI [13%, 26%].
  • petrol = -0.31: 10% higher petrol prices go with about 2.9% fewer casualties, with the distance held constant.
  • km is not clearly different from zero once the season and the memory are in the model.
  • The first coefficients (ar1, ma1, …, sma1) describe the memory. They are not effects, and nobody reports them one by one.

6. Checking the model

If the model is right, the residuals are white noise: no pattern left.

Code
res <- data.frame(date = road$date, r = as.numeric(resid(fit)))[-(1:13), ]
a <- acf(res$r, plot = FALSE, lag.max = 24)
pa <- ggplot(res, aes(date, r)) +
  geom_hline(yintercept = 0, colour = "grey60") +
  geom_line(colour = "#2a78d6", linewidth = 0.4) +
  labs(title = "Residuals", x = NULL, y = NULL) +
  theme_bw()
pb <- ggplot(data.frame(lag = a$lag[-1], r = a$acf[-1]), aes(lag, r)) +
  geom_hline(
    yintercept = c(-1, 1) * 1.96 / sqrt(nrow(res)),
    linetype = "dashed",
    colour = "#eb6834"
  ) +
  geom_segment(aes(xend = lag, yend = 0), linewidth = 0.9, colour = "#2a78d6") +
  geom_hline(yintercept = 0) +
  labs(title = "Their autocorrelations", x = "lag (months)", y = NULL) +
  theme_bw()
patchwork::wrap_plots(pa, pb, ncol = 1)

Checks – 6. Checking the model

Code
lb <- Box.test(resid(fit), lag = 24, fitdf = length(coef(fit)) - 3, type = "Ljung-Box")
c(Ljung_Box = lb$statistic, p = lb$p.value, Shapiro_p = shapiro.test(res$r)$p.value)
Ljung_Box.X-squared                   p           Shapiro_p 
        31.26106668          0.03778711          0.26997021 

The Ljung–Box test has p = .038, so the residuals are not perfectly white: two or three autocorrelations at long lags (18 and 22 months) lie just outside the dashed limits, where one in twenty does by chance. Compared with the OLS residuals, nearly all of the memory is in the model. The other orders of the table do no better, and the effect of the law is nearly the same in all of them.


7. The world without the law

Fit the model to the months before the law only, and let it forecast the two years after, with the petrol prices and distances that really occurred:

Code
last   <- c(1983, 1)
y_pre  <- window(y, end = last)
X_pre <- window(X[, c("petrol", "km")], end = last)
X_post <- window(X[, c("petrol", "km")], start = c(1983, 2))
pre    <- Arima(y_pre, order = arimaorder(fit)[1:3], seasonal = arimaorder(fit)[4:6], xreg = X_pre)
fc     <- forecast(pre, xreg = X_post, level = 95)
post   <- subset(road, law == 1)
cf <- data.frame(
  date = post$date,
  observed = post$drivers,
  expected = exp(as.numeric(fc$mean)),
  low = exp(as.numeric(fc$lower)),
  high = exp(as.numeric(fc$upper))
)
saved  <- sum(cf$expected - cf$observed)
c(
  observed = sum(cf$observed),
  expected = sum(cf$expected),
  difference = saved,
  share = saved / sum(cf$expected)
)
    observed     expected   difference        share 
3.039900e+04 3.697005e+04 6.571046e+03 1.777397e-01 
Code
below <- mean(cf$observed < cf$low)
below
[1] 0.5652174
Code
ggplot(subset(road, date >= 1978), aes(date, drivers)) +
  geom_ribbon(
    data = cf,
    aes(date, ymin = low, ymax = high),
    inherit.aes = FALSE,
    fill = "#2a78d6",
    alpha = 0.2
  ) +
  geom_line(colour = "grey40") +
  geom_line(data = cf, aes(date, expected), colour = "#2a78d6", linewidth = 0.9) +
  geom_vline(xintercept = 1983 + 1 / 12, linetype = "dashed", colour = "#eb6834") +
  labs(
    title = "Observed (grey), and forecast from the years before the law (blue, 95% band)",
    x = NULL,
    y = "drivers killed or seriously injured"
  ) +
  theme_bw() +
  theme(plot.title = element_text(size = 11))

Counterfactual chart – 7. The world without the law

In the 23 months the forecast expected 36,970 casualties, and 30,399 happened: 6,571 fewer, or 18%. In 57% of the months the number was below the 95% band.


8. Attacks on the result

A control: the rear seats

If the fall came from better weather, better roads or less traffic, the rear-seat passengers, whom the law did not concern, would have profited too:

Code
y_rear <- log(Seatbelts[, "rear"]); y_front <- log(Seatbelts[, "front"])
same_order <- function(v) {
  Arima(v, order = arimaorder(fit)[1:3], seasonal = arimaorder(fit)[4:6], xreg = X)
}
rear  <- same_order(y_rear); front <- same_order(y_front)
eff <- function(m) {
  bb <- coef(m)[["law"]]
  s <- sqrt(vcov(m)["law", "law"])
  100 * c(effect = exp(bb) - 1, low = exp(bb - 1.96 * s) - 1, high = exp(bb + 1.96 * s) - 1)
}
controls <- rbind(
  drivers = eff(fit),
  `front-seat passengers` = eff(front),
  `rear-seat passengers` = eff(rear)
)
round(controls, 1)
                      effect   low  high
drivers                -19.9 -26.2 -13.0
front-seat passengers  -28.1 -34.6 -21.1
rear-seat passengers     2.5  -7.3  13.4

The effect in percent: drivers -20, front-seat passengers -28, rear-seat passengers 3, 95% CI [-7, 13]. Those whom the law did not concern saw no change that can be told from zero.

Placebo laws

Pretend that the law came at other dates, in the years before it existed, and estimate the “effect” each time:

Code
dates <- seq(1971, 1981, by = 0.5)
placebo <- sapply(dates, function(d) {
  fake <- as.numeric(time(y_pre) >= d)
  m <- try(
    Arima(
      y_pre,
      order = arimaorder(fit)[1:3],
      seasonal = arimaorder(fit)[4:6],
      xreg = cbind(law = fake, X_pre)
    ),
    silent = TRUE
  )
  if (inherits(m, "try-error")) NA else coef(m)[["law"]]
})
pl <- data.frame(
  date = c(dates, 1983.08),
  b = c(placebo, b[["law"]]),
  kind = c(rep("invented dates", length(dates)), "the real law")
)
ggplot(pl, aes(date, 100 * (exp(b) - 1), fill = kind)) +
  geom_col(width = 0.35) +
  scale_fill_manual(values = c("grey65", "#eb6834"), name = NULL) +
  labs(
    title = "The 'effect' of invented laws, and of the real one",
    x = NULL,
    y = "change of casualties (%)"
  ) +
  theme_bw() +
  theme(legend.position = "bottom")

Placebo laws

Code
larger <- sum(placebo <= b[["law"]], na.rm = TRUE)
c(placebos = sum(!is.na(placebo)), as_large_as_the_law = larger)
           placebos as_large_as_the_law 
                 21                   0 

None of the invented dates should give much. A group of them does: those of the middle of the 1970s, after the oil crisis of the winter of 1973–74 had brought speed limits and empty roads. But 0 of the 21 invented dates gave a fall as large as the law’s. The method finds any step, whatever its cause. That the step of February 1983 is the law, and not something else that happened at the same time, is an argument from outside the model, and the rear seats are its best support.


9. Things to keep in mind

  • Two models share the name ARIMAX. Regression with ARIMA errors (here, and in arima(xreg = )) has coefficients with the usual meaning. Models with lags of \(y\) next to \(x\) (transfer functions) have not: there \(\beta\) is only the immediate effect.
  • Spurious regression. Two unrelated series that drift will correlate. Two random walks:
Code
set.seed(131)
spur <- replicate(1000, {
  a <- cumsum(rnorm(100))
  b <- cumsum(rnorm(100))
  c(
    levels = summary(lm(a ~ b))$coefficients[2, 4] < .05,
    differences = summary(lm(diff(a) ~ diff(b)))$coefficients[2, 4] < .05
  )
})
rowMeans(spur)
     levels differences 
      0.752       0.050 
  • OLS finds a “significant” relation between two independent random walks in 75% of the cases; after differencing, in 5%. With series that drift, difference or model the drift.
  • Shape of the effect. We assumed a sudden, permanent step. A law may work slowly, fade, or change the slope. Think first; a step is only the simplest shape.
  • Few points after the change make it hard to tell a step from the beginning of something else.
  • Anticipation. People may change before the date. Here many put on their belts in January 1983.
  • Covariates must not be changed by the intervention, and for forecasts their future values must be known.
  • Counts. These are large, so logs of them are fine. For small counts use time-series models for counts.
  • Structural models (level, slope and season that evolve) are the alternative that Harvey and Durbin used. They found a similar effect.

10. Reporting the results in APA style

A report (APA 7th edition) needs the series and its length, the transformation, the order of the ARIMA model and how it was chosen, the checks, the effect with its interval, and the evidence that it is the intervention. The numbers come from the R objects:

Code
apa_table <- data.frame(
  Predictor = c("Seat belt law", "Petrol price (log)", "Distance driven (log)"),
  b = f3(tab[, "b"]),
  SE = f3(tab[, "SE"]),
  z = f2(tab[, "z"]),
  p = sapply(tab[, "p"], function(p) sub("^= ", "", pval(p))),
  CI = paste0("[", f3(b - 1.96 * se), ", ", f3(b + 1.96 * se), "]")
)
order_text <- paste0(
  "ARIMA(",
  paste(arimaorder(fit)[1:3], collapse = ","),
  ")(",
  paste(arimaorder(fit)[4:6], collapse = ","),
  ")"
)

Method (data analysis):

The monthly number of car drivers killed or seriously injured in Great Britain, January 1969–December 1984 (192 months; Harvey & Durbin, 1986), was analyzed on the log scale with a regression with ARIMA errors (interrupted time series; Schaffer et al., 2021). The seat belt law was coded as a step from February 1983; the log petrol price and the log distance driven were covariates. The order of the ARIMA model was chosen with the corrected AIC (Hyndman & Khandakar, 2008); residuals were checked with the Ljung–Box test. As controls we analyzed front- and rear-seat passengers, invented dates before the law, and the forecast of the period after the law from the period before it. Analyses were conducted in R (Version 4.6.2; R Core Team, 2026) with the package forecast.

Results:

The selected model was ARIMA(1,0,3)(0,1,1)12; its residuals showed little autocorrelation, Ljung–Box Q(24) = 31.3, p = .038. The law was followed by a fall of 20% in the number of drivers killed or seriously injured, b = -0.222, SE = 0.042, 95% CI for the change [-26%, -13%] (Table 1). The forecast from the years before the law expected 6,571 more casualties in 23 months than were observed (18%). For rear-seat passengers, whom the law did not concern, the change was 3%, 95% CI [-7%, 13%].

Table 1

Regression With ARIMA Errors of the Log Number of Drivers Killed or Seriously Injured

Predictor b SE z p 95% CI
Seat belt law -0.222 0.042 -5.29 < .001 [-0.304, -0.140]
Petrol price (log) -0.308 0.095 -3.26 .001 [-0.494, -0.123]
Distance driven (log) 0.108 0.119 0.91 .364 [-0.125, 0.340]

Note. N = 192 months. Errors: ARIMA(1,0,3)(0,1,1)12. AICc = -397.4.

Points to remember:

  • Say what shape of effect was assumed (step, slope, pulse) and that it was chosen beforehand.
  • Report the order, the selection and the residual check, and how the effect changes with other orders.
  • Give the effect in percent, with an interval.
  • Show a control series or placebo dates.

11. Summary

When One long time series, predictors or an intervention, and errors that remember
The model \(y_t = x_t^\top\beta + n_t\), with \(n_t\) an ARIMA\((p,d,q)(P,D,Q)_s\) process
How (R) forecast::auto.arima(y, xreg = X), or arima(y, order, seasonal, xreg)
Choosing AICc (same differences), then white-noise residuals
Reading it \(\beta\) as in any regression; on logs, \(e^\beta - 1\) is a percentage
Checks ACF of the residuals, Ljung–Box
For interventions Forecast without the intervention, control series, placebo dates
Danger Spurious regression of drifting series
Related pages Generalized least squares, panel data

References

Box, G. E. P., & Tiao, G. C. (1975). Intervention analysis with applications to economic and environmental problems. Journal of the American Statistical Association, 70(349), 70–79. https://doi.org/10.1080/01621459.1975.10480264

Harvey, A. C., & Durbin, J. (1986). The effects of seat belt legislation on British road casualties: A case study in structural time series modelling. Journal of the Royal Statistical Society: Series A, 149(3), 187–227. https://doi.org/10.2307/2981553

Hyndman, R. J., & Khandakar, Y. (2008). Automatic time series forecasting: The forecast package for R. Journal of Statistical Software, 27(3), 1–22. https://doi.org/10.18637/jss.v027.i03

Schaffer, A. L., Dobbins, T. A., & Pearson, S.-A. (2021). Interrupted time series analysis using autoregressive integrated moving average (ARIMA) models: A guide for evaluating large-scale health interventions. BMC Medical Research Methodology, 21, Article 58. https://doi.org/10.1186/s12874-021-01235-8