首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R包:组合和不使用gts对象的aggts

R包:组合和不使用gts对象的aggts
EN

Stack Overflow用户
提问于 2015-07-13 23:59:10
回答 1查看 925关注 0票数 1

我试图将R包中的组合函数和aggts函数应用到时间序列矩阵中,以获得跨层次的最优预测集。我每个月都运行相同的代码,没有问题,现在我看到升级到HTSPackagev4.5后出现了错误。

可重复的示例(如果需要,我可以脱机地共享数据文件)

代码语言:javascript
复制
    #Read in forecast data for all levels of hierarchy#

fcast<-read.csv("SampleHierarchyForecast.csv", header = TRUE, check.names = FALSE)

#Convert to time series#

fcast<-ts(fcast, start = as.numeric(2010.25) + (64)/12, end = as.numeric(2010.25) + (75)/12, f= 12)

#Create time series of only the bottom level of the hierarchy#
index<-c()

fcastBottom<-fcast
for (i in 1:length(fcastBottom [1,]))
{
    if(nchar(colnames(fcastBottom)[i])!=28)
    index[i]<-i
    else
    index[i]<-0
}
fcastBottom<-fcastBottom[,-index]

#Create grouped time series from the bottom level forecast #
GtsForecast <- gts(fcastBottom, characters = list(c(12,12), c(4)), gnames = c("Category", "Item", "Customer", "Category-Customer"))
#Use combinef function to optimally combine the full hierarchy forecast using the groups from the full hierarchy gts#
combo <- combinef(fcast, groups = GtsForecast$groups)
*Warning message:
In mapply(rep, as.list(gnames), times, SIMPLIFY = FALSE) :
  longer argument not a multiple of length of shorter*
traceback()
2: stop("Argument fcasts requires all the forecasts.")
1: combinef(fcast, groups = GtsForecast$groups)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-23 02:35:01

comebinef()函数调用gts()时,有一个小错误。现在我在github上修好了。因此,在更新开发版本之后,您可以在上面运行您自己的代码,而不会有任何麻烦。

或者,如果不想安装最新版本,则需要稍微调整代码。

代码语言:javascript
复制
combo <- combinef(fcast, groups = GtsForecast$groups, keep = "bottom")
combo <- ts(combo, start = as.numeric(2010.25) + (64)/12, 
            end = as.numeric(2010.25) + (75)/12, f = 12)
colnames(combo) <- colnames(fcastBottom)
newGtsForecast <- gts(combo, characters = list(c(12,12), c(4)), 
                  gnames = c("Category", "Item", "Customer", 
                             "Category-Customer"))
Aggregate <- aggts(newGtsForecast)

希望能帮上忙。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31395444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档