I have run a simple linear regressions of insect counts against weather variables, e.g. total monthly rainfall. I have previously never known of autocorrelation but a reviewr of my manuscript has required me to test for autocorrelation and run models which account for its occurence.

I found suggestions by Macro on "How to test the autocorrelation of the residuals?" very easy to follow and helpful for a first timer like me to test for autocorrelation. I have found autocorrelation occuring in some of my linear regression models, but I haven't got such a simple approach to correcting for the autocorrelation. Most answers go into complex equations (with packages like "spdep", "sphet", "gmm", etc.) rather than straight forward R commands to run corrective models.

I would greatly appreciate someone who can help me out to make meaning out of my data through a simple approach.

  • $\begingroup$ How long of a time series are you working with? $\endgroup$
    – N Brouwer
    Nov 11, 2015 at 16:45
  • $\begingroup$ I am working with data collected monthly over 2 years. $\endgroup$
    – Egonyu
    Nov 12, 2015 at 14:32
  • 1
    $\begingroup$ Is change over time a key part your analysis or are you mostly interested in the effects of weather? Books by Zuur et al (eg Mixed Effects Models and Extensions in Ecology with R) have useful info on modeling short time series of ecological data. They cover diagnostics and implement AR1 and ARIMA models using the gls and lme functions from the nlme package in R. Perhaps a model like this would work for you: gls(count~weather.var1+weather.var2, correlation = corAR1(form = ∼,,,). The "..." would depend on the structure of data. $\endgroup$
    – N Brouwer
    Nov 12, 2015 at 18:15
  • $\begingroup$ GLS with an AR structure should be sufficient to control for autocorrelation $\endgroup$
    – Jon
    Jan 1, 2017 at 22:54

2 Answers 2


Autocorrelated errors signal model misspecification. Ideally, model errors should be $i.i.d.$ and thus should have no patterns in them. If they do, there is some information left unextracted; some more modelling can be done to extract the pattern.

There are two ways of dealing with the problem of autocorrelated errors.

  1. Leave the model specification as is but expand confidence intervals around the regression coefficients to account for the violation of the model assumption of non-autocorrelated errors. This can be motivated by the wish to retain the original model that may be directly derived from theory and/or have a nice interpretation. This can be done by using heteroskedasticity and autocorrelation (HAC) robust standard errors, e.g. by Newey and West (1987). HAC standard errors (as an alternative to the regular standard errors) should be available in any major statistical software package; they seem to be quite popular among practitioners, perhaps because they provide an easy solution.
    Pros: easy to use; can retain the original model.
    Cons: wider confidence intervals $\rightarrow$ lower precision, less power (harder to reject null hypotheses); model is misspecified; less accurate forecasting (due to neglecting the autocorrelation in model errors).
  2. Change the model specification to obtain non-autocorrelated errors. For example, run a regression with ARMA errors (easy to implement by arima or auto.arima functions in R including the regressors via the parameter xreg) or -- as DJohnson suggested -- include lags of dependent variable as regressors.
    Pros: narrower confidence intervals $\rightarrow$ higher precision, more power (easier to reject null hypotheses); model is correctly specified (unless there are other faults, which may quite often be true); more accurate forecasting.
    Cons: requires more work; cannot retain the original model.

I side with Francis Diebold's forceful argumentation (in his blog post "The HAC Emperor has no Clothes") that 2. is the way to go.


  • Newey, Whitney K; West, Kenneth D (1987). "A Simple, Positive Semi-definite, Heteroskedasticity and Autocorrelation Consistent Covariance Matrix". Econometrica 55 (3): 703–708. doi:10.2307/1913610
  • $\begingroup$ Dear Hardy, I am trying to follow arima modelling in R guided by commands in onlinecourses.science.psu.edu/stat510/?q=book/export/html/53. When examining the lm model using afc2 function to determine whether an AR( ) or MA( ) model is appropriate, I am not sure how to inteprete the graphs. Following the examples given in the aforementioned source, I deduce that when the vertical lines cross the doted blue lines, there is an autocorrelation, otherwise lines which are within the range of the blue lines imply the ordinary linear regression is appropriate for the data, not so? $\endgroup$
    – Egonyu
    Nov 12, 2015 at 13:41
  • 1
    $\begingroup$ That sounds reasonable. $\endgroup$ Nov 12, 2015 at 14:19
  • $\begingroup$ Thanks a lot Hardy and DJohnson for your kind guidance. With the approach above, I conclude that there are no autocorrelations in my response and explanatory variables. This is good for finalisation of my MS but denies me a chance to follow the procedure to the end. I will pick it up when I get data show autocorrelation. $\endgroup$
    – Egonyu
    Nov 12, 2015 at 14:30
  • 1
    $\begingroup$ You should look for autocorrelations in model residuals, not in the variables (unless you model is $y_t=c+\varepsilon_t$ where the residual is just the dependent variable minus its mean). To address a user in the comments, add "@", like @RichardHardy. Otherwise the users are not notified. $\endgroup$ Nov 12, 2015 at 14:51
  • $\begingroup$ Autocorrelation does not always imply a miss specified model. $\endgroup$
    – Repmat
    Jun 15, 2016 at 8:29

The link to this presentation develops several intuitive approaches to correcting for autocorrelation when tests show that it exists. Most of these methods are for AR(1) or first-order processes and include:

  • Adding/deleting variables, e.g., including 1-period lags of the response
  • Increasing the temporal period, e.g., from daily to weekly, and so on
  • Adjusting the errors by first differencing and multiplying by the autocorrelation coefficient, rho (apologies for my lack of Latex skills but the formula is on page 17 of the link):


If none of these "simple" solutions work, then to your point, the methods become increasingly complex and in at least some cases, the "cure" can be worse than the "disease" it is attempting to fix


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.