# Difference between using lm + Arima and auto.arima

I want to do a linear regression over the corporate spread bonds. The way I did it is to run a linear model using lm, then running an auto.arima on residuals of the output of lm and at last use the same coefficients as in the auto.arima and run an Arima model with the spread values. At last, I want to do a forecast. When I run an auto.arima with xreg, I get a different answer from using lm+Arima. I get an "I" term when using auto.arima though my variables are all stationary. I wonder what is the correct way to do this. Here's my code:


forecast.func <- function(NS.spread, ind.v, maturity, training, forc.horizon){

forc <- list()
j <- 0

# linear model
f <- ind.v[(1+j):(training+j) , maturity]
a <- cbind(y,f)
a <- as.data.frame(a)
b <- lm(y ~ lagmatrix(f, -1), data= a)

# auto- arima
c <- auto.arima(b$residuals, test= "adf") # Arima d <- Arima(y, xreg = lagmatrix(f, -1), order = c(c$$arma, c$$arma, c$arma), include.mean = FALSE)

# forecast
e <- ind.v[(training+j+1):(training+j+forc.horizon) , maturity]
h <- forecast(d, xreg = lagmatrix(e, -1))

forc <- c(h, forc)

j <- j + forc.horizon

}

return(forc)
}


Difference between using lm + Arima and auto.arima
In lm + Arima, the lm estimates ignore the ARIMA structure of the error term. This yields a logical inconsistency; the lm step effectively assumes no ARIMA structure, but the next step explicitly models it. Both the point estimates and the confidence intervals from lm can be expected to differ from the case where the error structure is not ignored. This probably also explains the problem with the I term.
In Arima with xreg or auto.arima with xreg, the estimates of xreg take the ARIMA structure of the error term into account. This is the proper way to account for error autocorrelation.
• Shouldn't gls used instead? – usεr11852 Aug 18 '20 at 9:19
• I was thinking somehting likegls( ..., correlation=corARMA(p,q), method="ML") so we fit a multivariate regression with autocorrelated errors. In that way after doing an auto.arima(residuals(lm(...))) we pass the relevant structure to gls so we go around the lm + Arima inconsistency. (My bad, probably I should have written this out originally and not just "gls would work, no?" comment this.) – usεr11852 Aug 18 '20 at 12:28