Appendix B — Generalized least squares
Here we use time series data (ordered by \(t\)), thus, Equation A.1 will be written with the time indices \(t\) as \[ y_t=\beta_0+\beta_1x_t+\varepsilon_t, \tag{B.1}\] where the regression errors at times \(t\) and \(t-1\) are \[ \begin{split} \varepsilon_t&=y_t-\beta_0-\beta_1x_t,\\ \varepsilon_{t-1}&=y_{t-1}-\beta_0-\beta_1x_{t-1}. \end{split} \tag{B.2}\]
An AR(1) model for the errors will yield \[ \begin{split} y_t-\beta_0-\beta_1x_t & = \rho\varepsilon_{t-1} + w_t, \\ y_t-\beta_0-\beta_1x_t & = \rho(y_{t-1}-\beta_0-\beta_1x_{t-1})+w_t, \end{split} \tag{B.3}\] where \(w_t\) are uncorrelated errors.
Rewrite it as \[ \begin{split} y_t-\rho y_{t-1}&=\beta_0(1-\rho)+\beta_1(x_t-\rho x_{t-1})+w_t,\\ y_t^* &= \beta_0^* + \beta_1 x_t^*+w_t, \end{split} \tag{B.4}\] where \(y_t^* = y_t-\rho y_{t-1}\); \(\beta_0^* = \beta_0(1-\rho)\); \(x_t^* = x_t-\rho x_{t-1}\). Notice the errors \(w_t\) in the final Equation B.4 for the transformed variables \(y_t^*\) and \(x_t^*\) are uncorrelated.
To get from Equation B.1 to Equation B.4, we can use an iterative procedure by Cochrane and Orcutt (1949) as in the example below.
What we have just applied is the method of generalized least squares (GLS): \[ \hat{\boldsymbol{\beta}} = \left( \boldsymbol{X}^{\top}\boldsymbol{\Sigma}^{-1}\boldsymbol{X}\right)^{-1} \boldsymbol{X}^{\top}\boldsymbol{\Sigma}^{-1}\boldsymbol{Y}, \tag{B.5}\] where \(\boldsymbol{\Sigma}\) is the covariance matrix. The method of weighted least squares (WLS; Appendix A) is just a special case of the GLS. In the WLS approach, all the off-diagonal entries of \(\boldsymbol{\Sigma}\) are 0.
We can use the function nlme::gls()
and specify the correlation
structure to avoid iterating the steps from the previous example manually:
modDish_ar1_v2 <- nlme::gls(DISH ~ RES
,correlation = nlme::corAR1(form = ~Year)
,data = D)
summary(modDish_ar1_v2)
#> Generalized least squares fit by REML
#> Model: DISH ~ RES
#> Data: D
#> AIC BIC logLik
#> 342 347 -167
#>
#> Correlation Structure: AR(1)
#> Formula: ~Year
#> Parameter estimate(s):
#> Phi
#> 1
#>
#> Coefficients:
#> Value Std.Error t-value p-value
#> (Intercept) -137.5 3714137 0.00 1
#> RES 45.7 6 7.35 0
#>
#> Correlation:
#> (Intr)
#> RES 0
#>
#> Standardized residuals:
#> Min Q1 Med Q3 Max
#> -0.000249 -0.000014 0.000135 0.000232 0.000338
#>
#> Residual standard error: 3714137
#> Degrees of freedom: 26 total; 24 residual