【问题标题】:Obtaining prediction point estimates and intervals from a forecast with forecast package使用预测包从预测中获取预测点估计值和区间
【发布时间】:2016-03-21 15:13:14
【问题描述】:

我需要一种打印预测值的方法。

我需要打印深蓝色的线值,如果可能的话,打印下图中灰色区域的值。

打印该值或打印 2019 年预测值的代码是什么?

library(forecast)

timese <- ts(WWWusage, start = c(2008, 1), end = c(2016, 1), frequency = 12)

### Structural Time Series Model 
# Trend likelihood    
fit <- StructTS(timese, "trend")

### Make the plot
plot(forecast(fit, level = c(70, 90)), 
     sub = "Confidence Interval 70% ~ 90% or Determined by user", 
     ylab = "Y Axis Variable",
     main = "Forecast Linear Structural Model @ Trend-Wise",
     ylim = c(0, 400))

【问题讨论】:

    标签: r plot prediction forecasting


    【解决方案1】:

    只需存储forecast 对象并打印它:

    fc <- forecast(fit, level = c(70, 90))
    fc
    #          Point Forecast    Lo 70    Hi 70    Lo 90    Hi 90
    # Feb 2016            234 230.3083 237.6917 228.1411 239.8589
    # Mar 2016            240 231.7450 248.2550 226.8991 253.1009
    # Apr 2016            246 232.1868 259.8132 224.0780 267.9220
    # May 2016            252 231.7796 272.2204 219.9095 284.0905
    # Jun 2016            258 230.6214 285.3786 214.5493 301.4507
    # Jul 2016            264 228.7832 299.2168 208.1097 319.8903
    # Aug 2016            270 226.3189 313.6811 200.6767 339.3233
    # Sep 2016            276 223.2716 328.7284 192.3183 359.6817
    # Oct 2016            282 219.6765 344.3235 183.0905 380.9095
    # Nov 2016            288 215.5631 360.4369 173.0402 402.9598
    

    对于提取单个行,将其转换为data.frame 可能更容易:

    df_fc <- as.data.frame(fc)
    df_fc["Jul 2016", ]
    #          Point Forecast    Lo 70    Hi 70    Lo 90    Hi 90
    # Jul 2016            264 228.7832 299.2168 208.1097 319.8903
    

    【讨论】:

    • 非常感谢。你介意我问一下“Lo 70”“Hi 70”等是什么意思吗?
    • 它们是预测区间 (PI) 的下限和上限。本质上,通过指定level = c(70, 90),您说要拟合具有第70 个和第90 个prediction intervals 的模型。更正式地说,PI 是与尚未观察到的随机变量相关联的区间,随机变量的指定概率位于该区间内。在这个例子中,我给出了 2016 年 3 月的 90% 区间,介于 227 和 253 之间。2016 年 3 月的实际值应该在这个区间内,概率为 0.90。
    猜你喜欢
    • 2014-07-22
    • 2016-08-14
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 2019-06-16
    • 2014-04-03
    • 2016-04-24
    相关资源
    最近更新 更多