Skip to content
All library documents

Quadratic Regression Forecasts Require Consistent Time and Predictor Data

Article Quant Q&A · Author: Dylan Koh

Summary

This exchange concerns forecasting a time series with a quadratic regression and why a one-step-ahead prediction may disagree with the plotted trend. The question shows a sales series, constructs year and squared-year predictors, fits a linear model in those predictors, and then calls the prediction function with a new observation. The reply suggests fitting the model with the original series and year variables, plotting fitted values, and supplying the new year when predicting.

The discussion points toward a key practical issue: regression predictions depend on matching the names and construction of predictors used at fitting time. The shown data also appears inconsistent: nineteen sales observations are paired with only two years, so the model setup cannot represent the stated series as written. The reply does not diagnose this mismatch or give a complete corrected example, and its alternative model omits a linear time term. Treat it as a prompt to check data alignment, predictor definitions, and model specification before interpreting a forecast; it does not establish that a quadratic trend is appropriate.

Key ideas

  • A quadratic time trend can be fit by including both time and its squared value as predictors.
  • Prediction data must supply predictors in a form consistent with those used to fit the model.
  • The displayed sales vector and year vector have different lengths, which undermines the example as written.
  • Plotting fitted values can help compare a regression fit with the observed series.
  • The exchange does not establish that a quadratic model is a reliable forecasting method.

Tags

Full text
# Predict Quadratic Trend in Time Series


# 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?

## Answer by Richi Wa (score 1)

https://quant.stackexchange.com/a/7160

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

` 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.

```

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

```

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

```

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

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.