How to check for independence of errors in OLS regression?

Let's say I have 10 observations for each hour. If I plot residuals ordered by time, I have the problem that adjacent residuals refer to the same day.

  • $\begingroup$ Well, it sounds like your errors are not independent. $\endgroup$ – Stephan Kolassa Nov 26 '18 at 19:43
  • $\begingroup$ Some more information about these observations would be helpful. The standard approach is the Durbin Watson test, but it's unclear how applicable that might be here. $\endgroup$ – whuber Nov 26 '18 at 20:03
  • $\begingroup$ Here's a bit more information: I observed prices people paid at merchants. So for each observation I know the day and hour, the product and the price. The idea is to use a regression to explain how prices are formed. The problem is taht I don't know, how to check for independence of errors and how I could use the Durbin Watson test since there are many observations for the same point in time. $\endgroup$ – Hans Meier Ruth Nov 26 '18 at 20:26
  • $\begingroup$ What you have (i.e. observing and recording ) is transactional data. This needs to be converted/bucketed as a collection i.e. a time series value e.g.total dollars spent ( or total number of sales ) in an hour for a particular product for a specified price. The temporal aggregation could be 15 minute intervals or daily totals prior to forming a useful model. $\endgroup$ – IrishStat Nov 26 '18 at 20:34
  • $\begingroup$ The problem with aggregating is that I would loose information, at least about the variability of prices at each point in time. Furthermore, I collected information about the buyers, like gender and age. The intention behind the Multiple Linear Regression was to identify what drives transaction prices, like to what extent does gender contribute to prices. $\endgroup$ – Hans Meier Ruth Nov 26 '18 at 20:59

Since you are looking at hourly observations over time, your data would often be called "time series" data. A common way to look at if the residuals are correlated is by looking at autocorrelation. That is, the correlation of the series with itself. We often look at correlations by lag, such that we look at how correlated an observation is at time $t$ with time $t + 1$.

In R, we could do something like:

cor(lh[1:(length(lh) - 1)], lh[2:length(lh)])

Which correlates all of the values of lh (except for the last data point) with the very next value of lh. So this looks at time $t$ correlated with time $t+1$ for $t = 1, 2, ..., T - 1$ where $T$ is the total number of times.

lh is a built-in time series in R. Running the above code returns 0.5807322, showing that the time series is autocorrelated. This will produce correlated residuals if it is not accounted for in the model.

I suggest looking into the area of time series analysis (I like Introductory Time Series with R by Cowpertwait and Metcalfe). What you need in particular seems to be the ACF plot, which is covered here: Interpretation of this ACF plot, and can be run in R with:


And returns:

enter image description here

The y-axis is a correlation, and the x-axis is the lag. This shows that the data is dependent on adjacent time points (lag = 1, as shown above with the cor call), but probably not any further time points (lag = 2, 3, ...).

  • $\begingroup$ Thanks! I noticed that ACF plots are frequently used. But I'm not sure wether they are applicabe in my case. @IrishStat noted that transactional data might need to be aggregated by date. So you could probably use the mean of prices for each date. If you don't aggregrate, you would have 10 observations (and 10 different prices) for each point in time. I'm not sure how ACF could handle multiple observations per point in time. On the other hand, if you aggregate you loose the variance of observations within each point of time. $\endgroup$ – Hans Meier Ruth Nov 26 '18 at 20:51
  • $\begingroup$ @HansMeierRuth Depending on how much data you have, what I would do is aggregate by date by taking the average for each day. It depends on what exactly you are trying to accomplish with your analyses. $\endgroup$ – Mark White Nov 26 '18 at 21:06
  • $\begingroup$ The overall idea is to use a regression to explain how prices are formed. For example the regression should answer the question wether age of people affects prices. Now, I want to check the assumption "independence of errors". For each point in time I have ~10 observations and hence ~10 residuals. So, you think that is legitimate to take the mean of the residuals for each point in time? $\endgroup$ – Hans Meier Ruth Nov 26 '18 at 21:27
  • $\begingroup$ @HansMeierRuth So you want to predict price, and you have a certain number of observations at ten different time points? $\endgroup$ – Mark White Nov 26 '18 at 21:38
  • $\begingroup$ Yes, I want to predict prices. But I have ~2000 distinct time points and for each time point I have ~10 observations. In my case a time point is an hour for which I have 10 observations. For example for 01.01.2018, 12pm I have 10 prices, people have paid [10€, 13€, 13€, 16€, 9€, 11€, 11€, 17€, 8€, 14€] $\endgroup$ – Hans Meier Ruth Nov 26 '18 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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