推荐答案
由于您已经使用R之外的样本内和完整样本准备了数据,因此无需将其转换为时间序列对象.
Since you already prepared the data with in-sample and full-sample outside of R, there is no need to convert it to time series objects.
这里是代码的清理版本,它假定数据文件位于R工作目录中:
Here is the cleaned-up version of your code, which assumes that data files are in R working directory:
library(midasr)
yvellareg <- scan("ymonthlyjackson.csv")
xvellareg <- scan("xdailyjackson.csv")
#yvellareg is the monthly y variable
#xvellareg is the daily x variable
betareg <- midas_r(yvellareg ~ mls(yvellareg, 1, 1) + mls(xvellareg, 3:25, 30), start=NULL)
summary(betareg)
#Defining data for forecasting
xdailyfulldata <- scan("xdailyfulldatajackson.csv")
ymonthlyfulldata <- scan("ymonthlyfulldatajackson.csv")
fulldata <- list(xvellareg=xdailyfulldata,
yvellareg=ymonthlyfulldata)
insample <- 1:length(yvellareg)
outsample <- (1:length(fulldata$yvellareg))[-insample]
#errorhere
avgf<-average_forecast(list(betareg),
data=fulldata,
insample=insample,
outsample=outsample)
sqrt(avgf$accuracy$individual$MSE.out.of.sample)
但是这仍然会引发错误,因为您的数据不符合要求. Package Midasr希望每个低频周期具有相同数量的高频周期.您的情况是30.但是我们有
But this still throws an error, since your data is not conformable. Package midasr expects that each low frequency period has the same number of high frequency periods. In your case this is 30. But we have
> length(xdailyfulldata)
[1] 1230
> length(ymonthlyfulldata)
[1] 42
> 1230/42
[1] 29.28571
自42*30=1260
起,您似乎每月观察的次数多于每日观察的次数.每月放弃一次观察将使代码运行没有错误:
Since 42*30=1260
it seems you have more monthly than daily observations. Dropping one monthly observation makes the code run without the errors:
fulldata <- list(xvellareg=xdailyfulldata,
yvellareg=ymonthlyfulldata[-42])
insample <- 1:length(yvellareg)
outsample <- (1:length(fulldata$yvellareg))[-insample]
#errorhere
avgf<-average_forecast(list(betareg),
data=fulldata,
insample=insample,
outsample=outsample)
sqrt(avgf$accuracy$individual$MSE.out.of.sample)
[1] 1.118709
这篇关于使用Midasr进行预测时出错(包括可复制的示例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!