Reputation: 1
I've tried using the following code with the forecast package:
fit=Arima(data[,1], order=c(1,0,0), include.mean=TRUE, include.drift = TRUE)
However, this only includes a mean and a linear trend. How do I forecast with the inclusion a quadratic trend term?
Upvotes: 0
Views: 1517
Reputation: 325
You can use the xreg
argument to include arbitrary regressors, including any deterministic polynomial trend. See code below for an example with simulated data:
library(forecast)
# Simulate some fake data with a quadratic trend
set.seed(123)
t <- 1:100
y <- (t^2)/500 + arima.sim(model = list(ar=0.5),n = length(t))
# Create regressor matrix and fit model
regressors <- cbind(trend=t,quad=t^2)
mod <- Arima(y, order = c(1,0,0),xreg = regressors,include.constant = TRUE)
summary(mod)
# Will print:
# Series: y
# ARIMA(1,0,0) with non-zero mean
#
# Coefficients:
# ar1 intercept trend quad
# 0.4960 -0.1021 0.0112 0.0019
# s.e. 0.0864 0.5177 0.0237 0.0002
#
# sigma^2 estimated as 0.83: log likelihood=-130.68
# AIC=271.36 AICc=272 BIC=284.38
Note: an alternative method would involve creating a quadratic trend by twice-differencing the data and including a constant term, like this:
mod <- Arima(y, order = c(1,2,0), include.drift = TRUE)
If you try it, a warning message will appear and you will see that the drift term is gone and there is no quadratic trend at all. This is because quadratic trends are rather unlikely in practice and tend to lead to incorrect, explosive forecasts. I would avoid them unless you have good domain knowledge that makes you believe they are appropriate.
Upvotes: 1