As a financial institution, we often run into analysis of time series data. A lot of times we end up doing regression using time series variables. As this happens, we often encounter residuals with time series structure that violates basic assumption of independent errors in OLS regression. Recently we are building another model in which I believe we have regression with autocorrelated errors.The residuals from linear model have lm(object)
has clearly a AR(1) structure, as evident from ACF and PACF. I took two different approaches, the first one was obviously to fit the model using Generalized least squares gls()
in R. My expectation was that the residuals from gls(object) would be a white noise (independent errors). But the residuals from gls(object)
still have the same ARIMA structure as in the ordinary regression. Unfortunately there is something wrong in what I am doing that I could not figure out. Hence I decided to manually adjust the regression coefficients from the linear model (OLS estimates). Surprisingly that seems to be working when I plotted the residuals from adjusted regression (the residuals are white noise). I really want to use gls()
in nlme
package so that coding will be lot simpler and easier. What would be the approach I should take here? Am I supposed to use REML? or is my expectation of non-correlated residuals (white noise) from gls() object wrong?
gls.bk_ai <- gls(PRNP_BK_actINV ~ PRM_BK_INV_ENDING + NPRM_BK_INV_ENDING,
correlation=corARMA(p=1), method='ML', data = fit.cap01A)
gls2.bk_ai <- update(gls.bk_ai, correlation = corARMA(p=2))
gls3.bk_ai <- update(gls.bk_ai, correlation = corARMA(p=3))
gls0.bk_ai <- update(gls.bk_ai, correlation = NULL)
anova(gls.bk_ai, gls2.bk_ai, gls3.bk_ai, gls0.bk_ai)
## looking at the AIC value, gls model with AR(1) will be the best bet
acf2(residuals(gls.bk_ai)) # residuals are not white noise
Is there something wrong with what I am doing???????
Best Answer
The residuals from
gls
will indeed have the same autocorrelation structure, but that does not mean the coefficient estimates and their standard errors have not been adjusted appropriately. (There's obviously no requirement that $\Omega$ be diagonal, either.) This is because the residuals are defined as $e = Y - X\hat{\beta}^{\text{GLS}}$. If the covariance matrix of $e$ was equal to $\sigma^2\text{I}$, there would be no need to use GLS!In short, you haven't done anything wrong, there's no need to adjust the residuals, and the routines are all working correctly.
predict.gls
does take the structure of the covariance matrix into account when forming standard errors of the prediction vector. However, it doesn't have the convenient "predict a few observations ahead" feature ofpredict.Arima
, which takes into account the relevant residuals at the end of the data series and the structure of the residuals when generating predicted values.arima
has the ability to incorporate a matrix of predictors in the estimation, and if you're interested in prediction a few steps ahead, it may be a better choice.EDIT: Prompted by a comment from Michael Chernick (+1), I'm adding an example comparing GLS with ARMAX (arima) results, showing that coefficient estimates, log likelihoods, etc. all come out the same, at least to four decimal places (a reasonable degree of accuracy given that two different algorithms are used):
EDIT: Prompted by a comment from anand (OP), here's a comparison of predictions from
gls
andarima
with the same basic data structure as above and some extraneous output lines removed:As we can see, the predicted values are different, although they are converging as we move farther into the future. This is because
gls
doesn't treat the data as a time series and take the specific value of the residual at observation 995 into account when forming predictions, butarima
does. The effect of the residual at obs. 995 decreases as the forecast horizon increases, leading to the convergence of predicted values.Consequently, for short-term predictions of time series data,
arima
will be better.