I'm working on some problems involving prediction of future values. I need to get an aggregated total at some point in the future.

My question is: what is the best way to predict the future values?

First, I want to mention that there are tens of thousands of different points, so I'm planning on using either the plyr or dplyr packages.

There are two ways I've gone about doing this:

  1. Time Series Forecasting
  2. Linear Regression

Also, before anyone jumps and says "You can't do extrapolation with linear regression!" I understand that and the reasons why it's a problem. But, in the below example, why would it be a problem?

Here's an example of some data I made up that mimics some of the data. The x values are months.


plot(forecast(csy.ts, h=60))
plot(forecast(y.ts, h=60))


# I arbitrarily chose 5 additional years for the forecasting

# Gives 459

# Gives 457

# Gives 616

Intuitively it makes sense that 459 should be about the right number. However, why is the regression "wrong"? To the above point of extrapolation being a problem with regression, my understanding is that it's usually a problem because there can be a surprise 'dip' in the data in the extrapolated range unaccounted for in the training set. However, the cumsum(y) data looks like a really nice logarithmic curve (it's also always increasing) so I am not worried about any 'dips' (even a spike seems rare, and even if it did spike, it would be a minor percentage of the cumsum(y) data and would not look like such an outlier).

While typing this I happened to see another post mentioning independence being violated, which I feel is most likely one of the issues here. I'm just not sure why.


1 Answer 1


The main reason why using ordinary least squares regression is frowned upon in modeling time series data is that the error terms are correlated with each other (this is called autocorrelation). If this is the case, then your standard errors from OLS will be incorrect, which affects hypothesis testing.

There are several ways that you can use specialized techiniques to account for autocorrelation, such as autoregressive models with lags, generalized least squares, and HAC (heteroskedasticity and autocorrelation consistent) standard errors.

  • $\begingroup$ So, if I need to use special methods to account for the autocorrelation, the time-series methods appear to be the way to go. However, in the example I used a dataset with 24 points. What happens when I only have 10 or 6 or even 3? The above method returns the mean for those values, but the data is obviously exponentially distributed so the mean would be highly inflated from the actual. $\endgroup$
    – Sam
    Jun 13, 2014 at 18:58

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.