Skip to main content

Generalized Least Squares: Okun’s Law With Errors That Remember

Generalized least squares (GLS) in R with nlme::gls(), on FRED’s US quarterly unemployment and real GDP, 1948-2019: Okun’s law with autocorrelated errors and a variance that changed over time, detecting both (ACF, PACF, Durbin-Watson, Breusch-Godfrey), AR(1), ARMA and variance structures compared with AIC and likelihood-ratio tests, REML against ML, OLS against GLS, GLS by hand (Prais-Winsten), Newey-West standard errors as the alternative, the caveats and APA reporting.

The question: how much does unemployment fall when the economy grows?

In 1962 the economist Arthur Okun noticed that when the US economy grows fast, unemployment falls, and when it stalls, unemployment rises. The relation, now called Okun’s law, is one of the best known rules of thumb in macroeconomics (Okun, 1962). It is a regression, and this page asks: by how much does the unemployment rate change, quarter by quarter, for each percentage point of economic growth?

An ordinary regression (OLS) assumes that each quarter’s error is independent of the others, and that the errors have the same spread in every quarter. Economic data break both assumptions:

  • Errors that remember. A quarter that is worse than the rule predicts tends to be followed by another one: unemployment moves in slow waves. The errors are autocorrelated.
  • A spread that changes. The economy was far more volatile in the 1950s to 1970s than it has been since the mid 1980s. The errors have unequal variances.

OLS still gives unbiased estimates when the errors are like that, but they are not the most precise ones and, worse, the standard errors and p values are wrong. Generalized least squares (GLS) puts the memory and the changing spread into the model, and gives the best estimates for the errors that the data actually have.

Problem What it looks like In nlme::gls()
Errors depend on the previous ones residuals run in streaks; the ACF is not zero correlation = corAR1(), corARMA()
The spread differs between groups the residuals are wider in some groups weights = varIdent(form = ~ 1 | group)
The spread follows a covariate the residuals fan out as a variable grows weights = varPower(), varExp()
Both both signs together correlation = ... and weights = ... in the same call

If you know the weighted version, see weighted least squares: it is GLS for the case when the errors are independent and only the variances differ. Two other pages deal with different departures from OLS: robust regression for outliers, and quantile regression for effects that differ along the distribution of the outcome. The polynomial regression example shows a first, short gls() with AR(1) errors, on the CO₂ record; here we go much deeper, on different data.

Code
library(ggplot2)
library(nlme)       # gls() and the correlation and variance structures (comes with R)
library(lmtest)     # dwtest(), bgtest()
library(sandwich)   # NeweyWest()

# colors: the same for the same thing in every chart
era_colours    <- c("1948-83" = "#2a78d6", "1984-2019" = "#eb6834")
method_colours <- c("OLS, usual SE"      = "#2a78d6", "OLS, Newey-West SE"   = "#eb6834",
                    "GLS, AR(1)"         = "#1baf7a", "GLS, AR(1) + variance" = "#eda100")

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

1. The data

The Federal Reserve Bank of St. Louis publishes thousands of economic series on its site FRED, free and with no login. Each can be downloaded as a CSV file straight from R. We need two series:

  • GDPC1: real gross domestic product of the United States, from the US Bureau of Economic Analysis. Real means adjusted for inflation. FRED gives its units as billions of chained 2017 dollars, seasonally adjusted annual rate, one value per quarter.
  • UNRATE: the civilian unemployment rate, from the US Bureau of Labor Statistics, in percent, seasonally adjusted, one value per month. It is the percentage of the labor force (people aged 16 and over, not in institutions or the armed forces) who are without a job and looking for one.

FRED labels both series “public domain: citation requested”, so they are free to use, and it asks that you cite the source (see the references). The units above are the ones in FRED’s own notes for each series.

Code
download_time <- system.time({
  gdp <- read.csv("https://fred.stlouisfed.org/graph/fredgraph.csv?id=GDPC1")
  une <- read.csv("https://fred.stlouisfed.org/graph/fredgraph.csv?id=UNRATE")
})[["elapsed"]]
head(gdp, 3)
  observation_date    GDPC1
1       1947-01-01 2182.681
2       1947-04-01 2176.892
3       1947-07-01 2172.432
Code
head(une, 3)
  observation_date UNRATE
1       1948-01-01    3.4
2       1948-02-01    3.8
3       1948-03-01    4.0

Both files together took 0.6 seconds. GDPC1 has 319 quarters (from 1947-01-01) and UNRATE has 946 months (from 1948-01-01).

Okun’s law is usually written in changes: the change in the unemployment rate against the growth of output. Two steps put the data in that form.

Code
# 1. unemployment: the mean of the three months of each quarter (a quarter with a missing month is NA)
une$quarter <- as.Date(cut(as.Date(une$observation_date), "quarter"))
quarterly   <- aggregate(UNRATE ~ quarter, data = une, na.action = na.pass,
                         FUN = function(x) if (length(x) == 3) mean(x) else NA)
missing_months <- une$observation_date[is.na(une$UNRATE)]

# 2. join with GDP, and take changes
gdp$quarter <- as.Date(gdp$observation_date)
d <- merge(gdp, quarterly, by = "quarter")
d <- d[order(d$quarter), ]
d$growth  <- c(NA, 400 * diff(log(d$GDPC1)))   # growth of real GDP, % at an annual rate
d$du      <- c(NA, diff(d$UNRATE))             # change in the unemployment rate, percentage points
d$growth1 <- c(NA, head(d$growth, -1))         # last quarter's growth (used in section 8)
covid <- subset(d, quarter >= as.Date("2020-01-01") & quarter <= as.Date("2020-07-01"))
d <- d[complete.cases(d) & d$quarter < as.Date("2020-01-01"), ]
d$year <- as.numeric(format(d$quarter, "%Y")) + (as.numeric(format(d$quarter, "%m")) - 1) / 12
d$era  <- factor(ifelse(d$quarter < as.Date("1984-01-01"), "1948-83", "1984-2019"))
head(d[, c("quarter", "growth", "du", "growth1")], 4)
     quarter     growth         du    growth1
3 1948-07-01  2.2914968 0.10000000  6.5554969
4 1948-10-01  0.4528895 0.06666667  2.2914968
5 1949-01-01 -5.5447081 0.83333333  0.4528895
6 1949-04-01 -1.3609425 1.20000000 -5.5447081
  • growth is \(400 \times \Delta \ln(\text{GDP})\): the quarter’s growth of real GDP in percent, expressed at an annual rate, as the statistical agencies do. A value of 3 means “growing at 3% a year”.
  • du is the change in the quarterly unemployment rate from the previous quarter, in percentage points. A value of 0.2 means that the rate rose, say, from 5.0% to 5.2%.

The sample runs from 1948 Q3 to 2019 Q4, 286 quarters (the first quarters are lost to taking changes and lags). We stop at the end of 2019. In the second quarter of 2020 the economy shrank at an annual rate of 32.8% in one quarter, and the next quarter rebounded; those few quarters are so extreme that they would decide the whole regression, and they are not an error structure but a one-off shock. The unemployment file has 1 missing month (2025-10-01); the code above sets its quarter to missing, and it lies after our sample anyway.


2. Look at the data

Code
ols <- lm(du ~ growth, data = d)

ggplot(d, aes(growth, du)) +
  geom_hline(yintercept = 0, colour = "grey75") +
  geom_vline(xintercept = 0, colour = "grey75") +
  geom_point(aes(colour = era), alpha = 0.7, size = 1.8) +
  geom_smooth(method = "lm", formula = y ~ x, colour = "grey20", se = FALSE, linewidth = 0.8) +
  scale_colour_manual(values = era_colours) +
  labs(title = "Okun's law: faster growth, falling unemployment",
       subtitle = "One point per quarter, 1948-2019. Line: the ordinary least squares fit.",
       x = "growth of real GDP (% at an annual rate)",
       y = "change in unemployment rate (points)", colour = NULL) +
  theme_bw() +
  theme(legend.position = "bottom")

Plot: 2. Look at the data

Code
summary(ols)$coefficients
               Estimate  Std. Error   t value     Pr(>|t|)
(Intercept)  0.21801441 0.021574040  10.10540 1.038353e-20
growth      -0.07025641 0.004459099 -15.75574 1.265744e-40

The relation is clear: the OLS slope is -0.070. For each extra percentage point of annual growth, the unemployment rate changes by -0.070 points in the quarter, and, with no growth at all, it rises by 0.22 points a quarter (the intercept). But this chart hides the order of the quarters, and the order is where the trouble is. The residuals, in time order:

Code
d$ols_resid <- resid(ols)

ggplot(d, aes(quarter, ols_resid)) +
  geom_hline(yintercept = 0, colour = "grey60") +
  geom_vline(xintercept = as.Date("1984-01-01"), linetype = "dashed", colour = "grey40") +
  geom_line(colour = "grey60", linewidth = 0.3) +
  geom_point(aes(colour = era), size = 1.4) +
  scale_colour_manual(values = era_colours) +
  labs(title = "The OLS residuals in time order",
       subtitle = "Dashed line: the first quarter of 1984",
       x = NULL, y = "residual (points)", colour = NULL) +
  theme_bw() +
  theme(legend.position = "bottom")

Look residuals – 2. Look at the data

Code
sd_era <- tapply(d$ols_resid, d$era, sd)

Two patterns, one for each assumption:

  1. Streaks. The residuals do not jump around at random: several quarters in a row are above zero, then several below. The errors remember.
  2. A change of spread. The scatter is wide up to the early 1980s and narrower after. The standard deviation of the residuals is 0.318 points before 1984 and 0.219 after, 1.45 times as large. This calmer period is known as the Great Moderation (Kim & Nelson, 1999; McConnell & Perez-Quiros, 2000). We chose 1984 by looking at the chart and from that literature, not by a test: keep that in mind when we test the difference in section 4.

Detecting autocorrelation

Three tools, from the picture to the test.

The ACF and PACF of the residuals. The autocorrelation function (ACF) is the correlation of the residuals with themselves k quarters earlier, for k = 1, 2, 3… The partial autocorrelation function (PACF) is the same after removing the effect of the quarters in between. For independent errors, nearly all bars lie within the dashed band (\(\pm 1.96/\sqrt{n}\)).

Code
correlogram <- function(x, lag.max = 16) {
  a <- acf(x,  lag.max = lag.max, plot = FALSE)
  p <- pacf(x, lag.max = lag.max, plot = FALSE)
  data.frame(lag = c(a$lag[-1], p$lag), value = c(a$acf[-1], p$acf),
             type = rep(c("ACF", "PACF"), each = lag.max))
}
band <- qnorm(.975) / sqrt(nrow(d))

ggplot(correlogram(d$ols_resid), aes(lag, value)) +
  geom_hline(yintercept = 0, colour = "grey50") +
  geom_hline(yintercept = c(-band, band), linetype = "dashed", colour = "#2a78d6") +
  geom_col(width = 0.35, fill = "grey35") +
  facet_wrap(~ type) +
  labs(title = "ACF and PACF of the OLS residuals",
       x = "lag (quarters)", y = "correlation") +
  theme_bw()

Acf – Detecting autocorrelation

Code
acf_values  <- acf(d$ols_resid, plot = FALSE)$acf[-1]
pacf_values <- pacf(d$ols_resid, plot = FALSE)$acf

How to read it: the ACF starts at 0.33 at lag 1 and dies away over a few quarters, while the PACF has one large bar at lag 1 (0.33) and then little. A large first bar in the PACF with an ACF that decays is the signature of an AR(1) process: each error is a fraction of the previous one, plus new noise. (An ACF that stops after \(q\) lags and a PACF that decays points to a moving average, MA(\(q\)).)

The Durbin-Watson test looks at the correlation at lag 1 only. The statistic is about \(2(1 - r_1)\): it is 2 when there is no autocorrelation, and below 2 when it is positive.

The Breusch-Godfrey test tests up to a chosen lag (here 4 quarters, a year) and, unlike Durbin-Watson, it remains valid when the predictors include lagged values of the outcome.

Code
dw <- dwtest(ols)
bg <- bgtest(ols, order = 4)
dw

    Durbin-Watson test

data:  ols
DW = 1.3329, p-value = 6.554e-09
alternative hypothesis: true autocorrelation is greater than 0
Code
bg

    Breusch-Godfrey test for serial correlation of order up to 4

data:  ols
LM test = 34.883, df = 4, p-value = 4.91e-07

Both reject the hypothesis of independent errors: Durbin-Watson \(d\) = 1.33, p < .001; Breusch-Godfrey \(\chi^2\)(4) = 34.9, p < .001.

Detecting unequal variances

For the variance, plot the residuals against the thing that might drive it (here time, above) or the fitted values, and compare the spread of the groups. A formal check is fitted below: the likelihood-ratio test of a model in which the variance differs between the two periods (section 4). The usual textbook tests of equal variance (Breusch-Pagan, Levene) assume independent errors, which we have just seen is wrong here, so the model comparison is the cleaner route.


3. The model step by step, with formulas

Step 1: the linear model with general errors

\[\mathbf{y} = \mathbf{X}\boldsymbol\beta + \boldsymbol\varepsilon, \qquad \operatorname{Var}(\boldsymbol\varepsilon) = \sigma^2 \boldsymbol\Omega\]

\(\mathbf{y}\) is the vector of the 286 changes in unemployment, \(\mathbf{X}\) the matrix with a column of ones and the growth, and \(\boldsymbol\beta\) the intercept and slope. OLS assumes \(\boldsymbol\Omega = \mathbf{I}\), the identity matrix: ones on the diagonal (equal variances) and zeros elsewhere (no correlations). GLS lets \(\boldsymbol\Omega\) be any symmetric positive definite matrix:

  • the diagonal of \(\boldsymbol\Omega\) holds the relative variances of the errors;
  • the off-diagonal cells hold their correlations.

Step 2: the GLS estimator

\[\hat{\boldsymbol\beta}_{GLS} = (\mathbf{X}'\boldsymbol\Omega^{-1}\mathbf{X})^{-1}\mathbf{X}'\boldsymbol\Omega^{-1}\mathbf{y}, \qquad \operatorname{Var}(\hat{\boldsymbol\beta}_{GLS}) = \sigma^2(\mathbf{X}'\boldsymbol\Omega^{-1}\mathbf{X})^{-1}\]

With \(\boldsymbol\Omega = \mathbf{I}\) this is the OLS formula, \((\mathbf{X}'\mathbf{X})^{-1}\mathbf{X}'\mathbf{y}\). The estimator is due to Aitken (1935). By the Gauss-Markov theorem generalized to correlated errors, it is the best linear unbiased estimator when \(\boldsymbol\Omega\) is right: no other linear unbiased estimator has smaller variance.

Step 3: GLS is OLS on transformed data

Write \(\boldsymbol\Omega = \mathbf{L}\mathbf{L}'\) (the Cholesky decomposition, the matrix version of a square root) and multiply the model by \(\mathbf{L}^{-1}\):

\[\underbrace{\mathbf{L}^{-1}\mathbf{y}}_{\mathbf{y}^*} = \underbrace{\mathbf{L}^{-1}\mathbf{X}}_{\mathbf{X}^*}\boldsymbol\beta + \underbrace{\mathbf{L}^{-1}\boldsymbol\varepsilon}_{\boldsymbol\varepsilon^*}, \qquad \operatorname{Var}(\boldsymbol\varepsilon^*) = \sigma^2\mathbf{L}^{-1}\boldsymbol\Omega\mathbf{L}^{-1\prime} = \sigma^2\mathbf{I}\]

The transformed errors are independent with equal variances, so ordinary least squares on \((\mathbf{y}^*, \mathbf{X}^*)\) is exactly right. That is the whole idea: GLS is OLS after transforming the data by \(\boldsymbol\Omega^{-1/2}\), which removes the memory and equalizes the spread. Section 6 does it by hand.

Step 4: the two classic cases

Unequal variances, independent errors. \(\boldsymbol\Omega\) is diagonal, \(\operatorname{diag}(\omega_1, \dots, \omega_n)\). The transformation divides each observation by \(\sqrt{\omega_i}\): noisy observations count for less. This is weighted least squares, with weights \(1/\omega_i\) (see the WLS example). varIdent(), varPower() and varExp() give the \(\omega_i\) a shape, with few parameters.

AR(1) errors. Each error is a fraction \(\phi\) of the one before, plus new noise:

\[\varepsilon_t = \phi\,\varepsilon_{t-1} + u_t, \qquad u_t \sim (0, \sigma_u^2), \qquad |\phi| < 1\]

The correlation of two errors \(k\) quarters apart is \(\phi^k\): it decays geometrically, which is what the ACF above showed. So \(\boldsymbol\Omega\) has \(\Omega_{ij} = \phi^{|i-j|}\) (up to the scale \(1/(1-\phi^2)\) that goes into \(\sigma^2\)), and \(\boldsymbol\Omega^{-1/2}\) is a simple “quasi-differencing”:

\[y_t^* = y_t - \phi\,y_{t-1}, \qquad x_t^* = x_t - \phi\,x_{t-1} \qquad (t = 2, \dots, n)\]

and, to keep the first observation, \(y_1^* = \sqrt{1-\phi^2}\,y_1\) and \(x_1^* = \sqrt{1-\phi^2}\,x_1\) (Prais & Winsten, 1954). Dropping the first observation instead is the Cochrane-Orcutt method (Cochrane & Orcutt, 1949). In the transformed data the errors are \(u_t\): independent.

Step 5: the matrix \(\boldsymbol\Omega\) is unknown

In practice we never know \(\phi\) or the variance ratios. Feasible GLS estimates them from the data, usually by maximum likelihood (ML) or restricted maximum likelihood (REML), and then uses the estimated \(\hat{\boldsymbol\Omega}\) in the formula. That is what gls() does, and the price is that the standard errors no longer account for the uncertainty in \(\hat{\boldsymbol\Omega}\): they are good in large samples, a little optimistic in small ones.

Step 6: what goes wrong with OLS

With \(\operatorname{Var}(\boldsymbol\varepsilon) = \sigma^2\boldsymbol\Omega\), OLS is still unbiased, but its true variance is

\[\operatorname{Var}(\hat{\boldsymbol\beta}_{OLS}) = \sigma^2(\mathbf{X}'\mathbf{X})^{-1}\mathbf{X}'\boldsymbol\Omega\mathbf{X}(\mathbf{X}'\mathbf{X})^{-1}\]

and lm() reports \(\sigma^2(\mathbf{X}'\mathbf{X})^{-1}\), which is only the same when \(\boldsymbol\Omega = \mathbf{I}\). With positive autocorrelation of both the errors and the predictor, the true variance is usually larger than the reported one: the standard errors are too small, and the p values too optimistic. The expression in the middle is also what the Newey-West estimator of section 7 estimates, so that OLS can be kept.


4. Fitting the models

The starting point: no structure

gls() with no extra arguments is OLS, fitted by likelihood. The estimates match lm():

Code
fit_ols <- gls(du ~ growth, data = d, method = "ML")
rbind(lm = coef(ols), gls = coef(fit_ols))
    (Intercept)      growth
lm    0.2180144 -0.07025641
gls   0.2180144 -0.07025641

One structure at a time

We now add a correlation structure, a variance structure, or both. Each model is fitted by maximum likelihood (method = "ML"), for a reason explained below.

Code
d$time10    <- (d$year - 1984) / 10        # decades from 1984
d$growthdev <- abs(d$growth - mean(d$growth))

fits <- list(
  "OLS (independent, equal variances)" = fit_ols,
  "AR(1)"                              = update(fit_ols, correlation = corAR1()),
  "AR(2)"                              = update(fit_ols, correlation = corARMA(p = 2)),
  "ARMA(1,1)"                          = update(fit_ols, correlation = corARMA(p = 1, q = 1)),
  "Variance by period"                 = update(fit_ols, weights = varIdent(form = ~ 1 | era)),
  "AR(1) + variance by time (varExp)"  = update(fit_ols, correlation = corAR1(), weights = varExp(form = ~ time10)),
  "AR(1) + variance by growth (varPower)" = update(fit_ols, correlation = corAR1(), weights = varPower(form = ~ growthdev)),
  "AR(1) + variance by period"         = update(fit_ols, correlation = corAR1(), weights = varIdent(form = ~ 1 | era)),
  "AR(2) + variance by period"         = update(fit_ols, correlation = corARMA(p = 2), weights = varIdent(form = ~ 1 | era)),
  "ARMA(1,1) + variance by period"     = update(fit_ols, correlation = corARMA(p = 1, q = 1), weights = varIdent(form = ~ 1 | era))
)

comparison <- data.frame(
  model   = names(fits),
  params  = sapply(fits, function(f) attr(logLik(f), "df")),
  logLik  = sapply(fits, function(f) as.numeric(logLik(f))),
  AIC     = sapply(fits, AIC),
  BIC     = sapply(fits, BIC),
  slope   = sapply(fits, function(f) coef(f)[["growth"]]),
  row.names = NULL)
comparison$dAIC <- comparison$AIC - min(comparison$AIC)
comparison[, c("model", "params", "logLik", "AIC", "dAIC", "BIC", "slope")]
                                   model params      logLik       AIC      dAIC      BIC       slope
1     OLS (independent, equal variances)      3 -40.4508319 86.901664 91.411985 97.86964 -0.07025641
2                                  AR(1)      4 -10.6270806 29.254161 33.764482 43.87813 -0.04325877
3                                  AR(2)      5 -10.5186902 31.037380 35.547701 49.31734 -0.04221021
4                              ARMA(1,1)      5 -10.5540134 31.108027 35.618348 49.38799 -0.04254909
5                     Variance by period      4 -30.5997982 69.199596 73.709917 83.82356 -0.06937953
6      AR(1) + variance by time (varExp)      5   1.8499864  6.300027 10.810348 24.57999 -0.03917805
7  AR(1) + variance by growth (varPower)      5   0.2780641  9.443872 13.954193 27.72383 -0.03902171
8             AR(1) + variance by period      5   7.2551604 -4.510321  0.000000 13.76964 -0.03894661
9             AR(2) + variance by period      6   7.4352565 -2.870513  1.639808 19.06544 -0.04002301
10        ARMA(1,1) + variance by period      6   7.4065965 -2.813193  1.697128 19.12276 -0.03985937

Each row is a different guess about \(\boldsymbol\Omega\). AIC (and BIC) measure the fit with a penalty for the number of parameters: smaller is better, and a difference of more than about 2 matters. AIC can be negative: only the differences between models matter. Reading the table:

  • Correlation alone. AR(1) lowers AIC from 86.9 to 29.3. AR(2) and ARMA(1,1) add a parameter or two and are worse than AR(1): the single parameter \(\phi\) was enough, as the PACF suggested.
  • Variance alone, with independent errors, helps too (AIC 69.2), but less than the correlation does.
  • Both together is far better than either: AIC -4.5 for AR(1) with a variance that differs between the two periods.
  • Variance structures compared, all on top of AR(1): by period (-4.5) beats a variance that changes smoothly with time (varExp, 6.3) and one that grows with the distance of growth from its mean (varPower, 9.4). The spread changed once, around 1984, more than it drifted.
  • Richer correlation on top (AR(2) or ARMA(1,1) with the variance) does not pay: AIC -2.9 and -2.8.

We keep AR(1) with a variance that differs by period. The formal comparisons are likelihood-ratio tests of nested models, which anova() does for gls objects:

Code
lrt_corr <- anova(fits[["Variance by period"]], fits[["AR(1) + variance by period"]])   # add AR(1)
lrt_var  <- anova(fits[["AR(1)"]],              fits[["AR(1) + variance by period"]])   # add the variance
lrt_ar2  <- anova(fits[["AR(1) + variance by period"]], fits[["AR(2) + variance by period"]])
lrt_corr
                                     Model df      AIC      BIC    logLik   Test  L.Ratio p-value
fits[["Variance by period"]]             1  4 69.19960 83.82356 -30.59980                        
fits[["AR(1) + variance by period"]]     2  5 -4.51032 13.76964   7.25516 1 vs 2 75.70992  <.0001
Code
lrt_var
                                     Model df       AIC      BIC    logLik   Test  L.Ratio p-value
fits[["AR(1)"]]                          1  4 29.254161 43.87813 -10.62708                        
fits[["AR(1) + variance by period"]]     2  5 -4.510321 13.76964   7.25516 1 vs 2 35.76448  <.0001
  • Adding AR(1) to the model with unequal variances: \(\chi^2\)(1) = 75.7, p < .001.
  • Adding the variance by period to the AR(1) model: \(\chi^2\)(1) = 35.8, p < .001. The 1984 cut was chosen by looking at the data, so this p value is a little too good; with a difference this large the conclusion does not depend on it.
  • Adding a second AR term: \(\chi^2\)(1) = 0.36, p = .548: not needed.

ML or REML?

gls() has two ways to estimate the variance and correlation parameters:

REML (the default) ML (method = "ML")
The idea maximizes the likelihood of the residuals, after removing the fixed effects maximizes the likelihood of the data
Variance parameters less biased: it allows for the degrees of freedom used by \(\boldsymbol\beta\), as dividing by \(n - p\) does biased down, like dividing by \(n\)
Likelihoods of two models comparable only if their fixed effects (the formula) are the same comparable whatever the fixed effects

So the rule: to compare models that differ only in the correlation or variance structure, REML is fine; to compare models with different fixed effects, as in section 8, use ML. Above, the fixed effects are always the same, so REML would do; we used ML anyway so that every model of this page is on the same footing. For the final model, and for reporting, we refit with REML. The two fits are close, and REML has the slightly larger \(\hat\sigma\):

Code
final    <- update(fits[["AR(1) + variance by period"]], method = "REML")
final_ml <- fits[["AR(1) + variance by period"]]
summary(final)
Generalized least squares fit by REML
  Model: du ~ growth 
  Data: d 
       AIC      BIC    logLik
  9.621187 27.86606 0.1894065

Correlation Structure: AR(1)
 Formula: ~1 
 Parameter estimate(s):
      Phi 
0.5796191 
Variance function:
 Structure: Different standard deviations per stratum
 Formula: ~1 | era 
 Parameter estimates:
  1948-83 1984-2019 
1.0000000 0.5968704 

Coefficients:
                  Value  Std.Error   t-value p-value
(Intercept)  0.09631635 0.03363099  2.863916  0.0045
growth      -0.03871077 0.00442266 -8.752821  0.0000

 Correlation: 
       (Intr)
growth -0.385

Standardized residuals:
        Min          Q1         Med          Q3         Max 
-2.66919477 -0.55100656 -0.04785601  0.46937574  5.01545984 

Residual standard error: 0.3764562 
Degrees of freedom: 286 total; 284 residual
Code
rbind(ML = c(coef(final_ml), phi = coef(final_ml$modelStruct$corStruct, unconstrained = FALSE), sigma = sigma(final_ml)),
      REML = c(coef(final), phi = coef(final$modelStruct$corStruct, unconstrained = FALSE), sigma = sigma(final)))
     (Intercept)      growth   phi.Phi     sigma
ML    0.09703580 -0.03894661 0.5735784 0.3731382
REML  0.09631635 -0.03871077 0.5796191 0.3764562

Reading the output

Code
phi_hat   <- coef(final$modelStruct$corStruct, unconstrained = FALSE)[[1]]
ratio_hat <- coef(final$modelStruct$varStruct, unconstrained = FALSE)[[1]]   # SD of 1984-2019 / SD of 1948-83
ci_final  <- intervals(final)
tt_final  <- summary(final)$tTable
sigma_hat <- sigma(final)
  • Coefficients. The slope is -0.039 (SE = 0.004): each extra point of annual growth lowers the quarterly change in unemployment by 0.039 points. With no growth, the rate rises by 0.10 points a quarter. These are the Okun’s law estimates, after allowing for the memory and the changing spread.
  • Phi is the AR(1) coefficient: 0.58, 95% CI [0.46, 0.68]. A quarter’s error carries over about .58 of itself into the next quarter, .34 two quarters later, and so on.
  • The variance function. varIdent() gives the first group (1948-83) the multiplier 1 and estimates the other relative to it: 0.60, 95% CI [0.51, 0.70]. After 1984 the errors have 0.60 times the standard deviation of the earlier years.
  • Residual standard error 0.38: the standard deviation of the errors in the reference group (1948-83). The post-1984 errors have a standard deviation of 0.22.

Checking the fit

If the model is right, the normalized residuals, \(\hat{\mathbf{L}}^{-1}\hat{\boldsymbol\varepsilon}\) (the residuals after the transformation of step 3), should look like independent noise with equal spread: no streaks, the same spread in both periods, an ACF inside the band. resid(final, type = "normalized") gives them.

Code
d$gls_resid <- resid(final, type = "normalized")

ggplot(d, aes(quarter, gls_resid)) +
  geom_hline(yintercept = 0, colour = "grey60") +
  geom_vline(xintercept = as.Date("1984-01-01"), linetype = "dashed", colour = "grey40") +
  geom_line(colour = "grey60", linewidth = 0.3) +
  geom_point(aes(colour = era), size = 1.4) +
  scale_colour_manual(values = era_colours) +
  labs(title = "The normalised GLS residuals",
       subtitle = "Dashed line: the first quarter of 1984",
       x = NULL, y = "normalised residual", colour = NULL) +
  theme_bw() +
  theme(legend.position = "bottom")

Check residuals – Checking the fit

Code
both <- rbind(cbind(correlogram(d$ols_resid), model = "OLS residuals"),
              cbind(correlogram(d$gls_resid), model = "GLS normalised residuals"))
both$model <- factor(both$model, levels = c("OLS residuals", "GLS normalised residuals"))
ggplot(subset(both, type == "ACF"), aes(lag, value)) +
  geom_hline(yintercept = 0, colour = "grey50") +
  geom_hline(yintercept = c(-band, band), linetype = "dashed", colour = "#2a78d6") +
  geom_col(width = 0.35, fill = "grey35") +
  facet_wrap(~ model) +
  labs(title = "The ACF before and after GLS",
       x = "lag (quarters)", y = "autocorrelation") +
  theme_bw()

Check residuals – Checking the fit

Code
sd_gls_era <- tapply(d$gls_resid, d$era, sd)
acf_gls    <- acf(d$gls_resid, plot = FALSE)$acf[-1]
lb_gls     <- Box.test(d$gls_resid, lag = 8, type = "Ljung-Box")

The streaks are gone and the spread is the same in both periods: the normalized residuals have a standard deviation of 1.00 before 1984 and 0.99 after. The first autocorrelation fell from 0.33 to -0.02, and most bars of the ACF are inside the band. A Ljung-Box test of the first 8 lags does not reject independence at the .05 level, \(\chi^2\)(8) = 14.6, p = .067.


5. OLS against GLS

Code
ols_se   <- summary(ols)$coefficients[, "Std. Error"]
ar1_fit  <- update(fits[["AR(1)"]], method = "REML")
nw       <- NeweyWest(ols, lag = 4, prewhite = FALSE)
nw_se    <- sqrt(diag(nw))

comp <- data.frame(
  method   = c("OLS, usual SE", "OLS, Newey-West SE", "GLS, AR(1)", "GLS, AR(1) + variance"),
  slope    = c(coef(ols)[["growth"]], coef(ols)[["growth"]],
               coef(ar1_fit)[["growth"]], coef(final)[["growth"]]),
  se       = c(ols_se[["growth"]], nw_se[["growth"]],
               summary(ar1_fit)$tTable["growth", "Std.Error"], tt_final["growth", "Std.Error"]),
  intercept = c(coef(ols)[[1]], coef(ols)[[1]], coef(ar1_fit)[[1]], coef(final)[[1]]),
  se_int   = c(ols_se[[1]], nw_se[[1]],
               summary(ar1_fit)$tTable[1, "Std.Error"], tt_final[1, "Std.Error"]))
comp$method <- factor(comp$method, levels = comp$method)
comp$lower  <- comp$slope - qnorm(.975) * comp$se
comp$upper  <- comp$slope + qnorm(.975) * comp$se
comp$ratio  <- comp$se / comp$se[1]
comp[, c("method", "intercept", "se_int", "slope", "se", "ratio")]
                 method  intercept     se_int       slope          se     ratio
1         OLS, usual SE 0.21801441 0.02157404 -0.07025641 0.004459099 1.0000000
2    OLS, Newey-West SE 0.21801441 0.03666095 -0.07025641 0.006605116 1.4812670
3            GLS, AR(1) 0.13354728 0.03451726 -0.04300275 0.004227026 0.9479551
4 GLS, AR(1) + variance 0.09631635 0.03363099 -0.03871077 0.004422662 0.9918285
Code
ggplot(comp, aes(slope, method, colour = method)) +
  geom_vline(xintercept = 0, colour = "grey75") +
  geom_errorbar(aes(xmin = lower, xmax = upper), width = 0.25) +
  geom_point(size = 2.5) +
  scale_colour_manual(values = method_colours) +
  scale_y_discrete(limits = rev) +
  labs(title = "The Okun slope, four ways",
       subtitle = "Points: the slope. Bars: 95% confidence intervals.",
       x = "change in unemployment per point of growth (points)", y = NULL, colour = NULL) +
  theme_bw() +
  theme(legend.position = "bottom", axis.text.y = element_blank(), axis.ticks.y = element_blank())

Compare chart – 5. OLS against GLS

Code
lines <- data.frame(growth = seq(min(d$growth), max(d$growth), length.out = 100))
lines <- rbind(
  data.frame(lines, du = coef(ols)[[1]] + coef(ols)[["growth"]] * lines$growth, method = "OLS, usual SE"),
  data.frame(lines, du = coef(final)[[1]] + coef(final)[["growth"]] * lines$growth, method = "GLS, AR(1) + variance"))
lines$method <- factor(lines$method, levels = c("OLS, usual SE", "GLS, AR(1) + variance"))
ggplot(d, aes(growth, du)) +
  geom_point(colour = "grey65", size = 1.4) +
  geom_line(data = lines, aes(colour = method), linewidth = 0.9) +
  scale_colour_manual(values = method_colours) +
  labs(title = "The OLS and GLS lines",
       x = "growth of real GDP (% at an annual rate)",
       y = "change in unemployment rate (points)", colour = NULL) +
  theme_bw() +
  theme(legend.position = "bottom")

Compare lines – 5. OLS against GLS

Two things stand out, and neither is what a textbook example would give.

1. The standard error hardly changes between OLS and GLS. With the usual OLS SE as the benchmark, the GLS standard errors are 0.95 times (AR(1)) and 0.99 times (AR(1) with variance) as large. We might have expected a big increase, as in the CO₂ example. One reason is that GLS does two things at once: it makes the standard errors honest and it makes the estimate more precise, by giving less weight to the noisy early years and by using the information in the streaks. These two effects can cancel, and they seem to here. The Newey-West standard error (section 7), which corrects the inference without changing the estimate, is 1.48 times the usual one: that is the honest price of the autocorrelation if we keep OLS.

2. The slope itself moves a lot: from -0.070 (OLS) to -0.043 (AR(1)) and -0.039 (AR(1) with variance), a change of about 45% of the OLS value, and well outside the OLS interval, [-0.079, -0.062]. If the errors were just autocorrelated and independent of the predictor, OLS and GLS would both estimate the same slope, and would differ only by chance. A gap this large is a warning that something is missing from the mean model. Section 8 follows it up.


6. GLS by hand: the Prais-Winsten transformation

To see that GLS really is OLS on transformed data, we do it several ways with the \(\hat\phi\) from the ML fit of AR(1) (without the variance), 0.529.

Code
y <- d$du
X <- cbind(`(Intercept)` = 1, growth = d$growth)
n <- length(y)
phi <- coef(fits[["AR(1)"]]$modelStruct$corStruct, unconstrained = FALSE)[[1]]

# (a) the formula, with the matrix Omega[i, j] = phi^|i - j|
Omega <- phi^abs(outer(1:n, 1:n, "-"))
Oinv  <- solve(Omega)
beta_formula <- solve(t(X) %*% Oinv %*% X, t(X) %*% Oinv %*% y)

# (b) the Prais-Winsten transformation, then ordinary least squares
y_star <- c(sqrt(1 - phi^2) * y[1],  y[-1] - phi * y[-n])
X_star <- rbind(sqrt(1 - phi^2) * X[1, ],  X[-1, ] - phi * X[-n, ])
beta_pw <- coef(lm(y_star ~ X_star - 1))

# (c) the same, dropping the first observation: Cochrane-Orcutt
beta_co <- coef(lm(y_star[-1] ~ X_star[-1, ] - 1))

# (d) gls() with phi held fixed at the same value
fit_fixed <- gls(du ~ growth, data = d, correlation = corAR1(value = phi, fixed = TRUE), method = "ML")

# (e) gls() estimating phi
beta_gls <- coef(fits[["AR(1)"]])

round(rbind("(a) formula" = beta_formula[, 1], "(b) Prais-Winsten" = beta_pw,
            "(c) Cochrane-Orcutt" = beta_co, "(d) gls, phi fixed" = coef(fit_fixed),
            "(e) gls, phi estimated" = beta_gls, "OLS" = coef(ols)), 5)
                       (Intercept)   growth
(a) formula                0.13434 -0.04326
(b) Prais-Winsten          0.13434 -0.04326
(c) Cochrane-Orcutt        0.13356 -0.04325
(d) gls, phi fixed         0.13434 -0.04326
(e) gls, phi estimated     0.13434 -0.04326
OLS                        0.21801 -0.07026
  • Rows (a), (b) and (d) are the same numbers, as the theory says: the formula, the transformation and gls() with the same \(\hat\phi\) are three ways to write one calculation. (The largest difference between them is 1.4e-16.)
  • Row (c) drops the first quarter and moves the slope by 1.1e-05: with 286 observations one quarter does not matter.
  • Row (e) is the gls() fit that estimated \(\phi\) itself: it is where the value 0.529 used in the other rows came from, so it agrees with them. The classic iterative Prais-Winsten method has to find \(\phi\) on its own: it re-estimates it from the residuals of the transformed fit and repeats until it settles:
Code
phi_it <- 0.5
for (i in 1:100) {
  ys <- c(sqrt(1 - phi_it^2) * y[1],  y[-1] - phi_it * y[-n])
  Xs <- rbind(sqrt(1 - phi_it^2) * X[1, ],  X[-1, ] - phi_it * X[-n, ])
  b  <- solve(crossprod(Xs), crossprod(Xs, ys))
  e  <- y - X %*% b
  phi_new <- sum(e[-1] * e[-n]) / sum(e^2)
  if (abs(phi_new - phi_it) < 1e-10) break
  phi_it <- phi_new
}
round(c(iterations = i, phi = phi_it, b[, 1]), 4)
 iterations         phi (Intercept)      growth 
    15.0000      0.5314      0.1340     -0.0432 
Code
round(c(phi = phi, beta_gls), 4)
        phi (Intercept)      growth 
     0.5291      0.1343     -0.0433 

It converges to \(\hat\phi\) = 0.531 and a slope of -0.0432, against 0.529 and -0.0433 from gls(): nearly the same. The small difference is that the two methods estimate \(\phi\) by different criteria: the iterative method takes the lag-1 correlation of the residuals, while gls() maximizes the likelihood.

The matrix in (a) is \(286 \times 286\). That is fine here but impossible for a series of a million observations; gls() never builds it, and uses the recursion of (b) instead. The point of the hand calculation is to see what the function does.


7. The alternative: keep OLS, correct its standard errors

GLS needs a model of the errors: here, AR(1) and two variances. If it is wrong, the estimates are still unbiased, but the standard errors can be wrong too. A different approach, common in economics, is to keep the OLS estimate and replace only its standard error with one that stays valid whatever the error structure: a heteroskedasticity and autocorrelation consistent (HAC) estimator. The best known is Newey-West (Newey & West, 1987), which estimates the middle part of the formula in step 6 by weighting the products of the residuals up to a chosen lag. In R:

Code
lag_rule <- floor(0.75 * n^(1/3))                       # a common rule of thumb for the lag
nw_rule  <- sqrt(diag(NeweyWest(ols, lag = lag_rule, prewhite = FALSE)))
nw_auto  <- sqrt(diag(NeweyWest(ols)))                  # automatic lag selection (Newey & West, 1994), with prewhitening
rbind(usual = ols_se, "Newey-West, lag 4" = nw_rule, "Newey-West, automatic" = nw_auto)
                      (Intercept)      growth
usual                  0.02157404 0.004459099
Newey-West, lag 4      0.03666095 0.006605116
Newey-West, automatic  0.04027778 0.007086965
Code
coeftest(ols, vcov. = NeweyWest(ols, lag = lag_rule, prewhite = FALSE))

t test of coefficients:

              Estimate Std. Error  t value  Pr(>|t|)    
(Intercept)  0.2180144  0.0366609   5.9468 8.015e-09 ***
growth      -0.0702564  0.0066051 -10.6367 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The Newey-West standard error of the slope is 0.0066 (lag 4) or 0.0071 (automatic lag), against 0.0045 from the usual formula: 1.48 and 1.59 times as large. The OLS conclusion, that the slope is far from zero, stands; only the width of the interval changes: 95% CI [-0.083, -0.057].

GLS OLS with Newey-West SEs
Needs a model of the errors yes no
Estimate changes: more efficient if the model is right the OLS estimate: unchanged
Standard errors right if the error model is right right in large samples whatever the error structure
Efficiency the best, if the model is right not improved
Needs a good guess of the structure a long series (the estimator is erratic in short ones)

If GLS and OLS agree, use whichever is simpler to explain. If they disagree, as here, do not just choose the one you like: ask why (next section).


8. Things to keep in mind

A large gap between OLS and GLS: look for a missing predictor

Okun’s law is not instantaneous: output growth acts on unemployment with a delay, as firms hire and fire slowly. Last quarter’s growth should also matter. If it is left out of the model, it goes into the error, so the error is correlated with this quarter’s growth, because growth itself is autocorrelated (0.36). Then:

  • the errors look autocorrelated, because last quarter’s omitted growth is in them;
  • OLS is biased (it gives this quarter’s growth credit for some of last quarter’s effect);
  • GLS removes the autocorrelation in a different way, and moves the slope a different way. That is what the gap shows.

The check is to add the lag, and refit by ML (the fixed effects now differ):

Code
fit_lag_ols <- gls(du ~ growth + growth1, data = d, method = "ML")
fit_lag     <- gls(du ~ growth + growth1, data = d, method = "ML",
                   correlation = corAR1(), weights = varIdent(form = ~ 1 | era))
fit_nolag   <- final_ml                      # the section 4 model, on the same rows
lag_test    <- anova(fit_nolag, fit_lag)
lag_test
          Model df       AIC       BIC   logLik   Test  L.Ratio p-value
fit_nolag     1  5  -4.51032  13.76964  7.25516                        
fit_lag       2  6 -53.87174 -31.93579 32.93587 1 vs 2 51.36142  <.0001
Code
rbind("OLS, no lag"  = c(coef(ols), growth1 = NA),
      "OLS, lag"     = coef(fit_lag_ols),
      "GLS, no lag"  = c(coef(final_ml), growth1 = NA),
      "GLS, lag"     = coef(fit_lag))
            (Intercept)      growth     growth1
OLS, no lag   0.2180144 -0.07025641          NA
OLS, lag      0.2994343 -0.05572752 -0.04056368
GLS, no lag   0.0970358 -0.03894661          NA
GLS, lag      0.2291946 -0.04966256 -0.03292766
Code
phi_lag <- coef(fit_lag$modelStruct$corStruct, unconstrained = FALSE)[[1]]

Compare the rows:

  • With the lag, the OLS and GLS estimates of the current-quarter slope are much closer: -0.056 and -0.050, against -0.070 and -0.039 without it. The gap was mostly a missing predictor.
  • The lag is clearly needed: likelihood-ratio \(\chi^2\)(1) = 51.4, p < .001, and AIC falls from -4.5 to -53.9.
  • The AR(1) coefficient falls, from 0.58 to 0.43, but it does not vanish: the unemployment rate has some inertia that the lag does not explain. So the error structure is still needed, though the lag explained part of it.
  • Together, a one-point rise in growth lowers the unemployment rate by 0.083 points over two quarters.

The general rule: a correlation structure models what the mean model leaves over, and does not replace it. Fitting an AR(1) is a quick way to fix the standard errors, but when the residuals show streaks, first ask what is missing from the mean: a predictor, a lag, a trend, a shift in level. A small simulation shows how an AR(1) can pose as an omitted trend:

Code
set.seed(1)
sim <- data.frame(t = 1:120)
sim$y <- 0.05 * sim$t + rnorm(120)         # a straight trend plus independent noise
phi_no_trend   <- coef(gls(y ~ 1, data = sim, correlation = corAR1())$modelStruct$corStruct, unconstrained = FALSE)[[1]]
phi_with_trend <- coef(gls(y ~ t, data = sim, correlation = corAR1())$modelStruct$corStruct, unconstrained = FALSE)[[1]]
c(without_trend = phi_no_trend, with_trend = phi_with_trend)
without_trend    with_trend 
   0.81578768    0.00640159 

The noise here is independent by construction. Without the trend in the model, the fitted AR(1) coefficient is 0.82: the trend leaks into the errors and gls() accepts it as memory. With the trend, it is 0.01. An AR(1) coefficient close to 1 in a regression on a time-ordered series is often this.

Generalized least squares is not a mixed model

Multilevel models also handle correlated observations, but in a different way:

GLS (nlme::gls) Mixed model (lme, lmer)
Where the correlation comes from a pattern you specify for the errors: AR(1), exchangeable… random effects: each cluster has its own intercept (and slopes)
Targets the marginal model: the average relation, with the correlations of the errors as a nuisance the conditional model: the relation within a cluster, with the between-cluster variation as a result
Typical data one long series; repeated measurements in fixed time order observations in clusters: pupils in schools, patients in clinics
Predictions for one cluster no yes (the random effects)
Combine them lme(..., correlation = corAR1()) puts a random effect and AR(1) errors in the same model

A random intercept alone implies a constant correlation between any two observations in a cluster, however far apart. An AR(1) implies a correlation that fades with the distance. For a single time series, like this one, there are no clusters, and gls() is the tool. For repeated measures on many people, the usual answer is a mixed model, with an AR(1) added if the measurements are close together in time.

Other points

  • The error model is a hypothesis. AIC picks the best of the structures you tried, not the true one. Plot the normalized residuals each time.
  • Estimated \(\hat{\boldsymbol\Omega}\) is uncertain. Standard errors from gls() take \(\hat{\boldsymbol\Omega}\) as given, so they are a little optimistic in short series. With few observations, a HAC estimator is not better; consider a bootstrap that resamples blocks.
  • Non-stationary series. If the series wanders, as unemployment levels do, a regression of one level on another can show a strong relation that does not exist (a spurious regression). We used changes, which are stationary. GLS with \(\phi\) close to 1 is a sign that differencing is needed.
  • Heteroskedasticity from the data, not the time. A variance that grows with the fitted value is modeled with varPower(form = ~ fitted(.)) (gls() did not converge with it on these data, so we used the covariate-based varPower() of section 4 instead).
  • An uneven time grid needs a continuous-time structure, corCAR1(), in place of corAR1().

9. Reporting the results in APA style

A report (APA 7th edition) needs the data and their units, the problem found in the OLS residuals, the error structure and how it was chosen, the estimates with their uncertainty, and how the result compares with OLS. The numbers come from the R objects:

Code
b_final  <- coef(final)
ci_coef  <- ci_final$coef

models_table <- data.frame(
  Model  = c("OLS", "AR(1)", "AR(1) + variance by period", "AR(2) + variance by period",
             "ARMA(1,1) + variance by period"),
  k      = comparison$params[c(1, 2, 8, 9, 10)],
  AIC    = f1(comparison$AIC[c(1, 2, 8, 9, 10)]),
  BIC    = f1(comparison$BIC[c(1, 2, 8, 9, 10)]),
  Slope  = f3(comparison$slope[c(1, 2, 8, 9, 10)]),
  check.names = FALSE)

estimates_table <- data.frame(
  Method = c("OLS, usual SE", "OLS, Newey-West SE", "GLS, AR(1)", "GLS, AR(1) + variance by period"),
  Slope  = f3(comp$slope),
  SE     = f4(comp$se),
  `95% CI` = paste0("[", f3(comp$lower), ", ", f3(comp$upper), "]"),
  check.names = FALSE)

Method (data analysis):

We analyzed the quarterly change in the US unemployment rate (percentage points; the mean of the monthly seasonally adjusted civilian rate, U.S. Bureau of Labor Statistics) against the growth of real gross domestic product (percent at an annual rate, \(400 \times \Delta\ln\) of chained 2017 dollars, seasonally adjusted; U.S. Bureau of Economic Analysis), both from the Federal Reserve Bank of St. Louis’ FRED database, for 286 quarters from 1948 Q3 to 2019 Q4. The pandemic quarters were excluded. The residuals of an ordinary least squares (OLS) regression showed positive autocorrelation (Durbin-Watson d = 1.33, p < .001; Breusch-Godfrey test of order 4, p < .001) and a smaller spread after 1983. We therefore estimated the regression by generalized least squares (Pinheiro & Bates, 2000) with first-order autoregressive errors and a separate error variance for 1948-83 and 1984-2019. Error structures were compared by maximum likelihood with the Akaike information criterion (AIC) and likelihood-ratio tests; the final model was estimated by restricted maximum likelihood. For comparison, we also report OLS estimates with Newey-West (1987) standard errors. Analyses were conducted in R (Version 4.6.2; R Core Team, 2026) with the packages nlme, lmtest and sandwich.

Results:

Okun’s law was clear in the data. In the final model, the unemployment rate changed by -0.039 points per quarter for each additional percentage point of annual GDP growth, 95% CI [-0.047, -0.030], and rose by 0.10 points per quarter at zero growth, 95% CI [0.03, 0.16]. The errors were autocorrelated, \(\hat\phi\) = 0.58, 95% CI [0.46, 0.68], and their standard deviation after 1983 was 0.60 times that of the earlier period, 95% CI [0.51, 0.70]. Both parts of the error structure improved the fit: AR(1) errors, \(\chi^2\)(1) = 75.7, p < .001, and unequal variances, \(\chi^2\)(1) = 35.8, p < .001 (Table 1); richer correlation structures did not (AR(2): \(\chi^2\)(1) = 0.36, p = .548). The OLS slope was -0.070, and its standard error was 0.0045 with the usual formula and 0.0066 with a Newey-West estimator (Table 2). The GLS slope was about 45% smaller in size than the OLS slope. Adding last quarter’s growth to the model, \(\chi^2\)(1) = 51.4, p < .001, brought the OLS and GLS estimates of the current-quarter slope closer, -0.056 and -0.050, which suggests that the difference between them came from the omitted lag.

Table 1

Error Structures for Okun’s Law, 1948-2019, Fitted by Maximum Likelihood

Model k AIC BIC Slope
OLS 3 86.9 97.9 -0.070
AR(1) 4 29.3 43.9 -0.043
AR(1) + variance by period 5 -4.5 13.8 -0.039
AR(2) + variance by period 6 -2.9 19.1 -0.040
ARMA(1,1) + variance by period 6 -2.8 19.1 -0.040

Note. N = 286 quarters. k = number of estimated parameters (intercept, slope, error variance, plus those of the correlation and variance structures). Slope: change in the unemployment rate (points) per percentage point of annual GDP growth.

Table 2

The Okun’s Law Slope by Method

Method Slope SE 95% CI
OLS, usual SE -0.070 0.0045 [-0.079, -0.062]
OLS, Newey-West SE -0.070 0.0066 [-0.083, -0.057]
GLS, AR(1) -0.043 0.0042 [-0.051, -0.035]
GLS, AR(1) + variance by period -0.039 0.0044 [-0.047, -0.030]

Note. The GLS rows are from the models of Table 1, refitted by restricted maximum likelihood. Confidence intervals are the estimate \(\pm\) 1.96 standard errors. The Newey-West estimator used a lag of 4 quarters without prewhitening.

Points to remember:

  • Show how you found the problem (the residual plot, the ACF, a test) and how you chose the structure (AIC, likelihood-ratio tests).
  • Say whether you estimated by ML or REML, and compare models with different fixed effects only by ML.
  • Report the correlation and variance parameters with their intervals: they say something about the data, here the persistence and the Great Moderation.
  • Give the OLS estimate as well, and explain a large difference.
  • State the choices made by looking at the data (here, the 1984 cut) openly.

10. Summary

When The errors of a regression are correlated (time series, repeated measures in order) or have unequal variances
The model \(\mathbf{y} = \mathbf{X}\boldsymbol\beta + \boldsymbol\varepsilon\), \(\operatorname{Var}(\boldsymbol\varepsilon) = \sigma^2\boldsymbol\Omega\); \(\hat{\boldsymbol\beta} = (\mathbf{X}'\boldsymbol\Omega^{-1}\mathbf{X})^{-1}\mathbf{X}'\boldsymbol\Omega^{-1}\mathbf{y}\)
The idea OLS after transforming the data by \(\boldsymbol\Omega^{-1/2}\); WLS is the diagonal case
How (R) nlme::gls(y ~ x, correlation = corAR1(), weights = varIdent(form = ~ 1 | group))
Detect Residual plots; ACF and PACF; lmtest::dwtest(), bgtest(); the spread by group or covariate
Choose the structure AIC, BIC, anova() likelihood-ratio tests; use ML when fixed effects differ, REML for the final fit
Check Normalized residuals: no streaks, equal spread
Alternative Keep OLS, with sandwich::NeweyWest() standard errors
Dangers An error structure can hide a missing predictor, lag or trend; \(\hat{\boldsymbol\Omega}\) is estimated, so standard errors are optimistic in short series
Related WLS, mixed models, robust regression

References

Aitken, A. C. (1935). On least squares and linear combination of observations. Proceedings of the Royal Society of Edinburgh, 55, 42–48.

Breusch, T. S. (1978). Testing for autocorrelation in dynamic linear models. Australian Economic Papers, 17(31), 334–355.

Cochrane, D., & Orcutt, G. H. (1949). Application of least squares regression to relationships containing auto-correlated error terms. Journal of the American Statistical Association, 44(245), 32–61.

Durbin, J., & Watson, G. S. (1950). Testing for serial correlation in least squares regression: I. Biometrika, 37(3–4), 409–428.

Godfrey, L. G. (1978). Testing against general autoregressive and moving average error models when the regressors include lagged dependent variables. Econometrica, 46(6), 1293–1301.

Kim, C.-J., & Nelson, C. R. (1999). Has the U.S. economy become more stable? A Bayesian approach based on a Markov-switching model of the business cycle. Review of Economics and Statistics, 81(4), 608–616.

McConnell, M. M., & Perez-Quiros, G. (2000). Output fluctuations in the United States: What has changed since the early 1980s? American Economic Review, 90(5), 1464–1476.

Newey, W. K., & West, K. D. (1987). A simple, positive semi-definite, heteroskedasticity and autocorrelation consistent covariance matrix. Econometrica, 55(3), 703–708.

Newey, W. K., & West, K. D. (1994). Automatic lag selection in covariance matrix estimation. Review of Economic Studies, 61(4), 631–653.

Okun, A. M. (1962). Potential GNP: Its measurement and significance. In Proceedings of the Business and Economic Statistics Section (pp. 98–104). American Statistical Association.

Pinheiro, J. C., & Bates, D. M. (2000). Mixed-effects models in S and S-PLUS. Springer.

Prais, S. J., & Winsten, C. B. (1954). Trend estimators and serial correlation (Cowles Commission Discussion Paper: Statistics No. 383). Cowles Commission for Research in Economics.

U.S. Bureau of Economic Analysis. (n.d.). Real gross domestic product [GDPC1] [Data set]. FRED, Federal Reserve Bank of St. Louis. https://fred.stlouisfed.org/series/GDPC1

U.S. Bureau of Labor Statistics. (n.d.). Unemployment rate [UNRATE] [Data set]. FRED, Federal Reserve Bank of St. Louis. https://fred.stlouisfed.org/series/UNRATE

Zeileis, A. (2004). Econometric computing with HC and HAC covariance matrix estimators. Journal of Statistical Software, 11(10), 1–17. https://doi.org/10.18637/jss.v011.i10

Zuur, A. F., Ieno, E. N., Walker, N., Saveliev, A. A., & Smith, G. M. (2009). Mixed effects models and extensions in ecology with R. Springer.