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?