2017-03-06 61 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语句,以使一个被触发。