r - 预测 holt() 时出错

标签 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

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

最佳答案

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 语句之一被触发。

关于r - 预测 holt() 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42634435/

相关文章:

r - 使用 R 中的 plm 函数进行预测

r - 为什么 RMarkdown `render` 行为取决于它是从 RStudio Server 还是从 PHP shell 调用?

r - 使用 ggplot2 绘制带孔的土地

regex - R:如何用/替换\\?

r - 预测 R 中给定 x 的 y 值

R预测函数类型="class"错误

string - 如何使用函数的参数作为变量的名称?

python - 如何在 Rmarkdown 中使用 Reticulate 将 Pandas DataFrame 转换为 R Dataframe

r - 如何围绕模型估计手动绘制 SE/CI

R : Finding x value (predictor) for a particular y value (outcome)中的回归(物流)