Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can anyone kindly point out if I made any mistakes in making predictions using quadratic regression model in time series? I called the predict() function with the appropriate data vector and model, but the predictions do not sit well with what I observe on the time plot. I will like to know if there's anything wrong with my commands or is there something more to it?

Here are my commands and data vectors:

sales <- c(99,99,96,101,99,105,101,106,107,106,105,112,112,118,121,126,127,128,133)
year <- 1985:1986
year.sq <- year^2
sales.df <- data.frame(Year=year,Year.Squared=year.sq,Sales=sales)
quad.reg.model <- lm(sales.df$Sales ~ sales.df$Year + I(sales.df$Year.Squared), 

year <- sales.df$Year
year.sq <- sales.df$Year.Squared

# Creating a data.frame to be an argument for predict.lm() function
newdata <- data.frame(year=2004,year.sq=2004^2) 

# Prediction for Sales (1-year ahead)
sales.pred <- predict.lm(quad.reg.model,newdata,interval='predict')

and the output from the last line of command gave:

         fit       lwr      upr
1   98.53383  93.00996 104.0577

However, when I plotted the sales series and overlaid with the quadratic graph, it clearly shows that the trend is increasing and it seems like the 1-year ahead prediction does not sit well empirically. Why is this so?

Plot of Sales & Best Fit Curve (Quadratic)

share|improve this question
Should it be $1985:2003$ instead of $1985:1986$? And I can't really read the formula in lm. – Richard Jan 30 '13 at 20:59
And I can't really read the formula in lm. Shouldn't it just be lm(sales~year+I(year^2)) equivalent to lm(sales~year+year.sq) ? – Richard Jan 30 '13 at 21:06
agree w/richard. The code should not even run without errors as it is displayed. – pat Jan 30 '13 at 21:12
This should fix it but Dylan Koh should review the changes – Bob Jansen Jan 30 '13 at 21:33

I can' read your lm lines but I think this works:

mymodel = lm(sales~year+I(year^2))
Or you try just

mymodel = lm(sales~I(year^2)) 

new.data = list(year=2004)
gives a useful value.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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