我正在尝试使用带有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'
我在网上找不到有关如何处理此问题的任何内容。
不久前,我不得不处理类似的问题。如果我没记错的话,您首先需要使用滞后减少的旧数据集来估计模型,因此您应该使用滞后2:6
而不是使用3: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))))