# Predict Quadratic Trend in Time Series

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), data=sales.df) 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? - 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


mymodel = lm(sales~year+I(year^2))
plot(sales)
lines(fitted.values(mymodel))

Or you try just

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

Finally

new.data = list(year=2004)
predict.lm(mymodel,new.data)

gives a useful value.

-