Can someone explain me how to implement a dynamic linear regression onmodel in R? The
The concept is similar to a transfer function, which mathematically is defined in this way $ y_t=c+w(B)x_t + N_t$, whereas: $$ y_t=c+w(B)x_t + N_t $$ Where $y_t$ is the variable to forecast, $x_t$ is the exogenous variable, $w(B)$ is the backshift operator related to the exogenous variable, and $N_t$ is the error term following an ARMA model. To
To implement a transfer function model onin R, the function auto.arima
with the xreg
specification is used.
Ex: assume For example, suppose that the goal is to forecast the energy price (p)p
using a transfer function model where the exogenous variable is the demand for energy, then I can then write:
p <- auto.arima(p.train, xreg=demand.train, stationary=TRUE, seasonal=TRUE)
fcast.p <- forecast(p, h=90, xreg=demand.test)
error <- MAPE(fcast.p$mean, p.test)
But how about a dynamic linear regression model? This is mathematically defined as $y_t=c + u(B)y_t + v(B) x_t + \epsilon_t$. I:
$$
y_t=c + u(B)y_t + v(B) x_t + \epsilon_t
$$
I know about the function dynlm
, but I don't understand how to choose the optimal coefficients for lagged values of my variables.