# Including time variable as a fixed effect to get rid of autocorrelation?

Does it make sense to include time as a fixed effect along with your predictors to get rid of autocorrelation? Why or why not?

# TL;DR

It may make sense. It depends on what kind of autocorrelation you have. Trend is one possible type of autocorrelation, but there are also others.

You may want to take a look at . I recommend the excellent free online book Forecasting: Principles and Practice (2nd ed.) by Athanasopoulos & Hyndman, here in particular the chapter on ARIMA models.

# Longer version

Your autocorrelation may indeed come from a trend:

Note the linearly but slowly dropping ACF plot that, and the PACF plot that is essentially insignificant. This combination is characteristic for a globally trended time series. (Think about why a global trend would yield this ACF/PACF pattern.)

In such a case, it makes sense to just include time as a linear covariate. Here are the residuals:

There is no remaining autocorrelation in the residuals. Everything is good.

However, your time series may have a non-trend autocorrelation structure. For instance, an AR(1) series with a high AR term of 0.8:

Note how if the series is at a certain level, it tends to stay at that level, but there is no overall trend visible.

Here, the ACF drops much more quickly to insigficance.

If we fit a trend to this series, we get residuals and ACF/PACF plots that look pretty much like the original series. Which is not surprising, since the fitted trend is essentially flat - because there is no trend in this series.

However, suppose we fit a correctly specified AR(1) model, essentially regressing $$y_t$$ on $$y_{t-1}$$. We get white noise, which is good:

# R code

set.seed(1)
nn <- 100

obs_trend <- ts((1:nn)+rnorm(nn,0,5))

plot(obs_trend)
acf(obs_trend)
pacf(obs_trend)

model_trend_trend <- lm(obs_trend~as.vector((1:nn)))

plot(ts(resid(model_trend_trend)))
acf(ts(resid(model_trend)))
pacf(ts(resid(model_trend)))

################################################

obs_ar <- arima.sim(list(ar=0.8),n=nn)

plot(obs_ar)
acf(obs_ar)
pacf(obs_ar)

model_ar_trend <- lm(obs_ar~as.vector((1:nn)))

plot(ts(resid(model_ar_trend)))
acf(ts(resid(model_ar_trend)))
pacf(ts(resid(model_ar_trend)))

model_ar_ar <- arima(obs_ar,order=c(1,0,0))

plot(resid(model_ar_ar))
acf(ts(resid(model_ar_ar)))
pacf(ts(resid(model_ar_ar)))


Auto-regression versus linear regression of x(t)-with-t for modelling time series presents a discussion of models that may have multiple trends and even multiple level shifts . Also see Stochastic versus deterministic time series