将比重应用于R中的矩阵

时间:2018-08-04 00:10:19

标签: matrix functional-programming forecast

假设我们要按以下比例混合预测

库(forecastHybrid)

hm1 <- hybridModel(wineind, models = "aet", weights = "cv.errors", cvHorizon = 5,windowSize = 140,parallel = TRUE)
hm1$weights

a.weight <- 0.3539126
e.weight <- 0.3591738
t.weight <- 0.2869136

我如何通过Rob Hyndman修改此示例,以在样本外准确性测试中测试所有组合?

https://robjhyndman.com/hyndsight/benchmark-combination/ 我的尝试

y<- wineind
h<-12

a = forecast(hm1$auto.arima,h)
e = forecast(hm1$ets,h)
t = forecast(hm1$tbats,h)
fcasts <- rbind(
  a = a$mean,
  e = e$mean,
  t = t$mean
)
colnames(fcasts) <- seq(h)
method_names <- rownames(fcasts)
# Compute all possible combinations
method_choice <- rep(list(0:1), length(method_names))
names(method_choice) <- method_names
combinations <- expand.grid(method_choice) %>% tail(-1) %>% as.matrix()
# Construct names for all combinations
for (i in seq(NROW(combinations))) {
  rownames(combinations)[i] <- paste0(method_names[which(combinations[i, ] > 0)], 
                                      collapse = "")
}

这里有一个问题,我不知道该如何操作此扫描

计算组合权重

组合<-scan(组合,1,rowSums(组合),FUN =“ /”)

0 个答案:

没有答案