# How can I fit the model “Y(t) = αX + βY(t-1) - βY(t-2)" in R?

I have to make a one-step ahead forecast for a time series Y(t) using R. Theory suggests the ideal model should be:

Y(t) = αX + βY$_{t-1}$ - βY$_{t-2}$

However, I don't know how to deal with the following issues:

• I have to take βY$_{t-1}$ minus βY$_{t-2}$.
• There are both autoregressive (Y$_{t-1}$,Y$_{t-2}$) and exogenous variables (X).
• I have to test whether or not "βY$_{t-1}$ - βY$_{t-2}$" is the best way to express the autoregression, instead of other ARIMA models.

The time series Y(t) in question is:

Y <- c(57.4, 51.6, 36.1, 34.8, 41.2, 59.1, 62.5, 55.0, 53.8, 52.4, 44.5, 42.2, 50.1, 61.3, 49.6, 38.2, 51.1, 44.7, 40.8, 46.1, 53.5, 54.7, 50.3, 48.8, 53.7, 52.0)

The exogenous variable X used is:

X <- c(-12.1, 30.0, 13.5, 30.0, -3.8, -24.3, 30.0, 30.0, 30.0, 30.0, -21.6, 30.0, 0.0, 26.5, -30.0, 20.5, -4.8, -9.2, 22.2, -7.3, 15.9, 16.0, 13.7, 5.6, 5.7, 1.8)

I am a beginner. If anything was not clear, let me know and I will give the necessary explanations.

Edit: It seems that these particular Y and X are not much effective. Nevertheless I am interested in the solution, which can be applied to different values of Y and X.

• You might be better of on an R-specific site as you seem to need programming advice rather than statistical. Perhaps you can do a further edit if you can clarify the statistical aspects. – mdewey Nov 7 '16 at 9:51
• @mdewey Thanks. The main statistical issue is the second point: whether it makes sense to model "Y(t-1) - Y(t-2)" rather than usual AR models. – thetax Nov 7 '16 at 10:07
• It seems that the same question by the same author has been answered here: stackoverflow.com/questions/40471043/… – coffeinjunky Nov 8 '16 at 11:59

For arima modelling the best route is using the Arima and auto.arima functions in the forecast package.

To answer questions directly:

1. You don't need to subtract a lagged variable you can use the equasion:

Y(t) = αX + βY$_{t-1}$ + βY$_{t-2}$

The Arima model as below will assign a negative value to your second Beta coefficient if such a pattern is found in the data.

2. Ar model with 2 lagged variables and exogenous regeressor:

library(forecast)

model <- Arima(y, order = c(2,0,0), xreg=X)
1. Use model <- auto.arima(y, xreg=X) and a model will be automatically selected for you based on aicc comparison of multiple models. Use ?auto.arima for further details.

forecast(model, h= 12) will forecast the model for 12 more values.

Also look into Time series model cross validation for further model comparison.

• The above fits the model $(1-\beta_1 B-\beta_2 B^2)(Y_t - \mu - \alpha X_t)=w_t$ equivalent to a linear regression with residuals following an AR(2) process which is different from the model $(1-\beta_1 B-\beta_2 B^2)(Y_t - \mu) = \alpha X_t + w_t$ where $X_t$ influence not only $Y_t$ but also subseqeunt values. – Jarle Tufto Dec 15 '16 at 12:55
• Correct, but your ARMAX version is also different from the model in the question, which constrained $\beta_1 + \beta_2 = 0$. – Chris Haug Dec 15 '16 at 14:57

Use ARIMA with regressor variable (but not that usually great to detect patterns, external regressor is usually not useful) or you may also try Mixed modeling (Granger causality)

• Could you add more details? – thetax Nov 7 '16 at 9:16
• This is being automatically flagged as low quality, probably because it is so short. At present it is more of a comment than an answer by our standards. Can you expand on it? We can also turn it into a comment. – gung - Reinstate Monica Nov 7 '16 at 12:30

Which theory suggests that model?

Something that isn't clear: $\beta$ is a vector that contains $\beta_1, \beta_2, ..., \beta_n$?

If it is not, $\beta$ is the same, so

$Y(t) = \alpha X + \beta Y_{t-1} - \beta Y_{t−2}$ and the need to take $\beta Y_{t-1}$ minus $\beta Y_{t-2}$ may be achieved like this:

$Y(t) = \alpha X + \beta$($Y_{t-1} - Y_{t-2}$)

So think $Y_{t-1} - Y_{t-2}$ as $\Delta Y$

The model will be

$Y(t) = \alpha X + \beta \Delta Y$

Now you could look this $\beta$, with the same estimated value, as positive to t-1 and negative to t-2, because you forced that.

• I don't understand this answer. – Michael R. Chernick Jun 7 '18 at 20:59
• The question does not tell us if the first and second $\beta$ are the same. My answer shows the transformation if they are. – André Oliveira Jun 7 '18 at 21:03
• Just distributive property of multiplication. β(Y_{t−1} − Y_{t−2}) = βY_{t−1} − βY_{t−2} – André Oliveira Jun 7 '18 at 21:04