簡體   English   中英

使用 Mcomp package 對每月時間序列進行批量預測時,如何獲得正確的 output?

[英]How to get the correct output when using batch forecasting for the monthly time series with the Mcomp package?

我正在嘗試使用Mcomp package 對每月時間序列進行批量預測。 我已經准備了一個代碼,但我沒有得到任何 output。

library(forecast)    
library(Mcomp)

使用seq function,因為我需要 select 以 7 結尾的特定時間序列。

tsset <- (seq(1507, 2797, 10)) 
tsset

horizon <- 18
fit1<-array(0,130)

for (tsi in 1:130){
  y <- tsset[[tsi]]$x
  yt <- head(y, length(y) - horizon)
  yv <- tail(y, horizon)

  for(i in 1:130){
    fit1 <-c(ets(yt))
  }
  print(fit1)
}

給定時間序列中的前 112 個點(您不需要循環),以下是您如何獲得最后 18 個點的預測:

tsset<- seq(1507, 2797, 10) + 10*runif(130) # add noise
horizon <- 18

y <- tsset
n <- length(y)
yt <- head(y, n - horizon)
#yv <- tail(y, horizon)
fit1 <- ets(yt)
yv1 <- forecast(fit1, h=horizon)

start <- n - horizon + 1
plot(start:n, yv, type='l', col='red', lty=1, xlab='t', ylab='y(t)')
lines(start:n, yv1$mean, col='blue', lty=2)
lines(start:n, yv1$upper[,2], col='green', lty=2)
lines(start:n, yv1$lower[,2], col='green', lty=2)
legend("topleft", legend=c("original", "forecast", "95% CI"),
                  col=c("red", "blue", "green"), lty=c(1,2,2), cex=0.8)

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM