使用“midasr"包进行预测:包含新的高频值 [英] Forecasting with `midasr` package: Inclusion of new high-frequency value

查看:42
本文介绍了使用“midasr"包进行预测:包含新的高频值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用所谓的 MIDAS 概念计算提前一步预测.在这个概念中,人们根据更高频率的数据计算预测.例如,因变量 y 可以每年记录并在自变量 x 的帮助下进行解释,该变量可以例如每季度采样.

I am trying to calculate one-step-ahead forecasts using the so called MIDAS concept. Within this concept one calculates forecasts in dependence of a higher-frequency data. For example, the dependent variable y could be yearly recorded and be explained with the help of an independent variable x, which could be sampled, for example, quarterly.

有一个名为 midasr 的包,它提供了很多功能.我可以使用上述包中的函数 select_and_forecast 计算提前预测,如下所示(使用模拟数据,这是示例的简化版本,来自包 的用户指南midasr):

There is a package called midasr which offers a lot of functions. I can calculate the one-step-ahead forecasts using the function select_and_forecast from the mentioned package as follows (with simulated data, which is a simplified version of the example form the user's guide to the package midasr):

数据的生成:

library(midasr)
set.seed(1001)
n <- 250
trend <- c(1:n)
x <- rnorm(4 * n)
z <- rnorm(12 * n)
fn.x <- nealmon(p = c(1, -0.5), d = 8)
y <- 2 + 0.1 * trend + mls(x, 0:7, 4) %*% fn.x + rnorm(n)

预测的计算(样本外预测范围由参数 outsample 控制,因此在我的示例中,我计算了 10 个预测,从 240 到 250)

Calculation of forecasts (out-of-sample forecast horizon is controlled by the argument outsample, so in my example I am calculating 10 forecasts, from 240 to 250)

select_and_forecast(y~trend+mls(y,1,1,"*")+mls(x,0,4),
                          from=list(x=c(4)),
                          to=list(x=rbind(c(14,19))),
                          insample=1:250,outsample=240:250,
                          weights=list(x=c("nealmon","almonp")),
                          wstart=list(nealmon=rep(1,3),almonp=rep(1,3)),
                          IC="AIC",
                          seltype="restricted",
                          ftype="recursive",
                          measures=c("MSE"),
                          fweights=c("EW","BICW")
)$forecasts[[1]]$forecast

我现在想要做的是模拟一种情况,其中高频变量的新值变得可用,因为例如,新的月份过去了,可以在模型中使用该月的值.我会按如下进行,但我很不确定它是否正确:

What I would like to do now is to simulate a situation where a new value of the higher-frequency variable becomes available, because, for example, a new month has passed and the value for this month can be used in the model. I would proceed as follows, but am very unsure if it is correct:

select_and_forecast(y~trend+mls(y,1,1,"*")+mls(x,0,4),
                          from=list(x=c(3)),   # The only change is the reduction of the lower bound of the range of the lags of the regeressor from 4 to 3
                          to=list(x=rbind(c(14,19))),
                          insample=1:250,outsample=240:250,
                          weights=list(x=c("nealmon","almonp")),
                          wstart=list(nealmon=rep(1,3),almonp=rep(1,3)),
                          IC="AIC",
                          seltype="restricted",
                          ftype="recursive",
                          measures=c("MSE"),
                          fweights=c("EW","BICW")
)$forecasts[[1]]$forecast

理论上,通过减少时间指数,包括对高频变量的新观察,但我不知道这样使用函数是否正确.

Theoretically one includes the new observations of the higher-frequency variable through reduction of the time index, but I don't know if using the function this way is correct.

这个问题是给熟悉这个包的人的.有人可以对此发表评论吗?

This question is for someone who is familiar with the package. Can someone give a comment to this?

我想到的公式是:

y_t=\beta_0 + \beta_1B(L^{1/m};\theta)x_{t-h+1/m}^{(m)} + \epsilon_t^{(m)}

在我的例子中使用 h=1 并添加 1/m 以包含新的高频观察

With h=1 in my case and adding 1/m to include a new high-frequency observation

推荐答案

我不确定我是否正确理解了您的问题,所以我将举一个例子,希望能回答您的问题.

I am not sure that I understood your question correctly so I will give an example which I hope will answer your question.

假设您的响应变量 y 每年观察一次,而预测变量 x 每季度观察一次(对应于模拟数据).假设您有兴趣使用上一年的数据预测明年的 y 值.那么pacakgemidasr中的模型方程如下:

Suppose your response variable y is observed at a yearly frequency and the predictor variable x is observed quarterly (which corresponds to the simulated data). Say you are interested in forecasting next year y value using the data from the previous year. Then the model equation in the pacakge midasr is the following:

y~mls(x,4:7,4)

4:7 是用于预测的 x 的滞后,4 表示 x 有 4 个观测值y 的每次观察.

The values 4:7 are the lags of x used for prediction and 4 indicates that there are 4 observations of x for every observation of y.

midasr使用约定,对于低频周期t=l,我们观察高频周期m*(l-1)+1:米.所以对于 1 年我们有季度 1,2,3,4,对于年 2 我们有季度 5,6,7,8.这个约定然后假设我们在 1 年观察 yx4 季度,y2 年以及 x 的四分之一 8

The package midasr uses the convention, that for low frequency period t=l we observe high frequency periods m*(l-1)+1:m. So for year 1 we have the quarters 1,2,3,4, for year 2 we have the quarters 5,6,7,8. This convention then assumes that we observe y at year 1 together with the 4 quarter of x, y at year 2 together with quarter 8 of x and etc.

MIDAS 模型是根据滞后来制定的,滞后是从零开始的.因此,如果我们想用 x 的值来解释 1 年的 y(在我们的例子中,低频是每年的频率)同年,即季度 4,3,2,1 我们使用滞后 0,1,2,3.如果我们的目标是用 1 年的 x 值解释 2 年的 y,我们使用滞后 4,5,6,7 对应于 4,3,2,1 宿舍.

The MIDAS model is formulated in terms of lags, which start at zero. So if we want to explain y at year 1 (as in our example the low frequency is the yearly frequency) with the values of x from the same year, i.e. quarters 4,3,2,1 we use the lags 0,1,2,3. If our goal is to explain y at year 2 with values of x at year 1 the we use lags 4,5,6,7 which correspond to quarters 4,3,2,1.

现在假设我们在 3 年,但我们还没有观察到 y 值,但我们已经观察到了今年第一季度 3,即四分之一9.假设我们想使用这些信息进行预测.9季度比3年晚三个高频次,因此型号规格现在是

Now assume the we are at year 3, but we have not observed yet the y value, but we have already observed the first quarter of the year 3, i.e., the quarter 9. Suppose we want to use this information for forecasting. Quarter 9 is three high frequency lags behind the the year 3, hence the model specification is now

y~mls(x,3:7,4)

我们还包括上一年的所有信息.

where we also include all the information about the previous year too.

因此,如果我的示例符合您的要求,那么是的,包含新的高频观察只是按照您所做的方式更改 from 参数的值.但是我强烈建议从一个简单的模型开始,以完全掌握包的工作方式.

So if my example corresponds to what you are asking, then yes, inclusion of the new high frequency observation is only a matter of changing value of from argument the way you did. However I strongly suggest to start with one simple model to fully grasp the way the package works.

这篇关于使用“midasr"包进行预测:包含新的高频值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆