简体   繁体   English

使用来自 ARDL R ZEFE90A8E604A7C840E88D03A6B666Z 的 model object 进行预测

[英]Forecasting using model object from ARDL R package

I am trying to use forecast function on ardl model like this.我正在尝试像这样在ardl model上使用预测 function 。

library(ARDL)
data(denmark)

models <- auto_ardl(LRM ~ LRY + IBO + IDE, data = denmark, max_order = 5)
ardl_3132 <- models$best_model

fabletools::forecast(object = ardl_3132, new_data = denmark[1:20, ])
forecast::forecast(object = ardl_3132, new_data = denmark[1:20, ])

However, it's throwing an error Error in L(LRM, 1): could not find function "L"但是,它Error in L(LRM, 1): could not find function "L"

How can I make forecast work here?我怎样才能在这里进行预测?

I am seeting this error too when trying to use predict() on an ardl model.尝试在 ardl model 上使用 predict() 时,我也看到了这个错误。

L function is in tsDyn, I think, but loading that does not eliminate the error. L function 我认为在 tsDyn 中,但加载并不能消除错误。

AFAIK, in the "core" of the ARDL model usually lies simple linear regression (unless it is specified as a dynamic model with dynlm), so... My best attempt would be to try building the ARDL model using a different package/function. AFAIK,在 ARDL model 的“核心”中通常存在简单的线性回归(除非它被指定为带有 dynlm 的动态 model),所以......我最好的尝试是尝试使用不同的包构建 ARDL Z20F35E630DAF399DFA84 . It takes a bit more writing, but should give you a workable model object, which you could then use to build your prediction/forecast.它需要更多的写作,但应该会给你一个可行的 model object,然后你可以用它来构建你的预测/预测。

So what I would do, would be to estimate the ARDL model using the ARDL package, just like you did in your example above, extract the full formula from your model object, and rewrite it inside the lm() formula, using it's syntax, like so: So what I would do, would be to estimate the ARDL model using the ARDL package, just like you did in your example above, extract the full formula from your model object, and rewrite it inside the lm() formula, using it's syntax,像这样:

> ardl_3132$full_formula

LRM ~ L(LRM, 1) + L(LRM, 2) + L(LRM, 3) + LRY + L(LRY, 1) + IBO + L(IBO, 1) + L(IBO, 2) + L(IBO, 3) + IDE + L(IDE, 1) + L(IDE, 2)

We can specify the formula above inside an lm() model:我们可以在 lm() model 中指定上面的公式:

ardl_3132_lm <- lm(LRM ~ lag(LRM, 1) + lag(LRM, 2) + lag(LRM, 3) + LRY + lag(LRY, 1) + IBO + lag(IBO, 1) + lag(IBO, 2) + lag(IBO, 3) + IDE + lag(IDE, 1) + lag(IDE, 2), data = denmark)

You can use the predict.lm() function to create the forecast using the linearly specified ARDL model:您可以使用 predict.lm predict.lm() function 使用线性指定的 ARDL model 创建预测:

predict.lm(ardl_3132_lm)

The ARDL package itself is useful for estimating the model more conveniently than you would, using lm() or glm(). ARDL package 本身比使用 lm() 或 glm() 更方便地估计 model 很有用。 See summary() call on the model object to explore it's properties.请参阅对 model object 的 summary() 调用以探索它的属性。

summary(ardl_3132)

Comparing it with the lm() specified model summary shows, however, that they are not identical.然而,将其与lm()指定的 model 摘要进行比较表明它们并不相同。

summary(ardl_3132_lm)

The reason for this is that the function ARDL::auto_ardl() for this specific example has selected dynlm::dynlm(formula = full_formula, data = data, start = start, end = end) which specifies Dynamic Linear Models and Time Series Regression , and not a linear model.原因是此特定示例的 function ARDL::auto_ardl()选择dynlm::dynlm(formula = full_formula, data = data, start = start, end = end)指定动态线性模型和时间序列回归,而不是线性 model。

To create a forecast from the dynlm model, you would need to use stats::predict() like so:要从 dynlm model 创建预测,您需要像这样使用stats::predict()

stats::predict(ardl_3132)

Comparing the dynlm forecasted values with the linear model predicted values,dynlm预测值与线性 model 预测值进行比较,

stats::predict(ardl_3132_lm)

we can see, that the predictions are different.我们可以看到,预测是不同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM