如何使用MIDASR软件包在MIDAS模型中使用边缘数据进行预测?

问题描述 投票:4回答:1

我正在尝试通过midasr包使用每月变量来生成季度变量的提前1步预测。我遇到的麻烦是,当样本中每月观测值的数量恰好是季度观测值的3倍时,我只能估算MIDAS模型。

[每月观测值的数量不是季度观测值的精确倍数时(例如,当我有一个新的每月数据点要用于更新预测时)如何在midasr包中进行预测?

作为示例,假设当我有(n)个季度观测值和(3*n)个月观测值时,运行以下代码来生成提前1步的预测:

#first I create the quarterly and monthly variables
n <- 20
qrt <- rnorm(n)
mth <- rnorm(3*n)

#I convert the data to time series format
qrt <- ts(qrt, start = c(2009, 1), frequency = 4)
mth <- ts(mth, start = c(2009, 1), frequency = 12)

#now I estimate the midas model and generate a 1-step ahead forecast 
library(midasr)
reg <- midas_r(qrt ~ mls(qrt, 1, 1) + mls(mth, 3:6, m = 3, nealmon), start = list(mth = c(1, 1, -1)))
forecast(reg, newdata = list(qrt = c(NA), mth =c(NA, NA, NA)))

此代码可以正常工作。现在假设我要包含一个新的每月数据点,因此新的每月数据为:

nmth <- rnorm(3*n +1)

我尝试运行以下代码来估计新模型:

reg <- midas_r(qrt ~ mls(qrt, 1, 1) + mls(nmth, 2:7, m = 3, nealmon), start = list(mth = c(1, 1, -1))) #I now use 2 lags instead 3 with the new monthly data

但是我收到一条错误消息:'Error in mls(nmth, 2:7, m = 3, nealmon) : Incomplete high frequency data'

我在网上找不到有关如何解决此问题的任何信息。

r forecasting ragged
1个回答
1
投票

[前一段时间I had to do,有类似问题。如果我没记错的话,您首先需要使用减少了滞后的旧数据集来估算模型,因此,在使用3:6滞后的情况下,应该使用2:6滞后:

reg <- midas_r(qrt ~ mls(qrt, 1, 1) + mls(mth, 2:6, m = 3, nealmon), start = list(mth = c(1, 1, -1)))

然后假设您观察到更高频率数据的新值-new_value

new_value <- rnorm(1)

然后,您可以使用此新观察到的值来预测较低频率的变量,如下所示:

forecast(reg, newdata = list(mth = c(new_value, rep(NA, 2))))
© www.soinside.com 2019 - 2024. All rights reserved.