预测holt()时出错

时间:2017-03-06 19:56:59

标签: r predict

我试图预测使用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

所以我不确定是什么问题。

1 个答案:

答案 0 :(得分: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语句。