2017-03-06 62 views
2

我在嘗試預測使用holt()。預測holt時出錯()

holt(ts(c(999037.5, 998362.5, 999525.0, 999412.5, 1000000.0)),alpha=0.6, beta=0.6, damped=TRUE, initial="optimal", h=5) 

我得到以下錯誤:

Error in ets(x, "AAN", alpha = alpha, beta = beta, damped = damped, opt.crit = "mse", : 
Sorry, but I need more data! 

但是當我運行下面的代碼,我得到的輸出。

holt(ts(c(1,2)),alpha=0.6, beta=0.6, damped=TRUE, initial="optimal", h=5) 
Point Forecast  Lo 80 Hi 80  Lo 95 Hi 95 
3   1.5 0.5938062 2.406194 0.11409618 2.885904 
4   1.5 0.4868445 2.513155 -0.04948758 3.049488 
5   1.5 0.3901438 2.609856 -0.19737860 3.197379 
6   1.5 0.3012183 2.698782 -0.33337843 3.333378 
7   1.5 0.2184484 2.781552 -0.45996398 3.459964 

所以我不確定是什麼問題。

回答

2

ets你會發現裏面的代碼:

# close to line 148 
    n <- length(y) 
    if (n <= 4) { 
     fit <- HoltWintersZZ(orig.y, beta = FALSE, gamma = FALSE, 
      lambda = lambda, biasadj = biasadj) 
     fit$call <- match.call() 
     return(fit) 
    } 
    npars <- 2L 
    if (trendtype == "A" | trendtype == "M") 
     npars <- npars + 2L 
    if (seasontype == "A" | seasontype == "M") 
     npars <- npars + m 
    if (!is.null(damped)) 
     npars <- npars + as.numeric(damped) 
    if (n <= npars + 1) 
     stop("Sorry, but I need more data!") 
    if (errortype == "Z") 
     errortype <- c("A", "M") 
    if (trendtype == "Z") { 
     if (allow.multiplicative.trend) 
      trendtype <- c("N", "A", "M") 
     else trendtype <- c("N", "A") 
    } 

這些if語句,以使一個被觸發。