1
$\begingroup$

Can someone explain me how to implement a dynamic linear model in R?

The concept is similar to a transfer function, which mathematically is defined as: $$ 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 implement a transfer function model in R, the function auto.arima with the xreg specification is used. For example, suppose that the goal is to forecast the energy price p using a transfer function model where the exogenous variable is the demand for energy, 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 know about the function dynlm, but I don't understand how to choose the optimal coefficients for lagged values of my variables.

$\endgroup$
8
  • $\begingroup$ Hello and welcome to Cross Validated! There seems to be more than one question in your question. To increase the chance of someone answering your question, consider asking a single question here, and then asking your other questions in separate posts. Also, please consider including a minimal working example in your question. For example, could you show us how you can use auto.arima and xreg to implement a transfer function? $\endgroup$
    – mhdadk
    Commented Apr 25, 2021 at 14:09
  • $\begingroup$ Hi, thanks for your comment! I've modified the post so that it may sound clearer. $\endgroup$ Commented Apr 25, 2021 at 16:33
  • $\begingroup$ By the way, you may find this question helpful: stats.stackexchange.com/questions/367856/… $\endgroup$
    – mhdadk
    Commented Apr 25, 2021 at 17:41
  • $\begingroup$ Thanks again, but it doesn't seem to answer the question about the lagged coefficients $\endgroup$ Commented Apr 25, 2021 at 18:29
  • $\begingroup$ Hi: The last equation that you wrote represents an autoregressive distributed lag in econometrics. I didn't watch it because I don't have time but here's a video that goes through the steps of building an ARDL in R. youtube.com/watch?v=qoihlzu7CcM $\endgroup$
    – mlofton
    Commented Apr 26, 2021 at 13:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.