如何使用循环作为数据框从预测输出中提取值

时间:2017-08-03 12:20:34

标签: r lapply forecasting

我有一个df:

    head(vardata_num,30)
     wt   ht dist
1  9.00 7.49 5.41
2  8.75 8.03 5.60
3  8.50 7.24 5.30
4  8.50 7.19 5.23
5  8.50 6.94 5.41
6  8.50 7.30 4.52
7  8.50 7.40 2.91
8  8.50 6.97 2.59
9  8.50 7.08 2.08
10 8.50 6.63 1.51
11 8.50 6.73 1.39
12 8.00 6.97 1.76
13 8.00 6.58 1.50
14 8.00 6.90 1.56
15 8.00 6.04 2.43
16 8.00 5.75 2.79
17 8.00 5.72 3.34
18 8.00 5.75 3.53
19 8.00 5.73 3.08
20 7.50 5.45 3.39
21 7.50 5.58 3.34
22 7.50 5.66 4.22
23 7.50 5.71 5.35
24 7.00 5.86 5.99
25 7.00 4.87 6.65
26 7.00 4.87 6.51
27 7.00 4.91 5.34
28 7.00 4.90 4.71
29 7.00 4.83 3.95
30 7.00 4.50 4.9

我正在尝试使用自定义函数使用循环预测这三个变量:

library(mafs)
ts_lapply <- lapply(vardata_num, function(x) select_forecast(ts(x),test_size = 10, horizon = 3, error = "MAPE"))  # select_forecast() from `mafs` package

我得到了如下令人敬畏的输出:

  

ts_lapply [1]#为一个变量

$wt
$wt$df_models
        model         ME      RMSE       MAE        MPE      MAPE     MASE      ACF1 best_model runtime_model
1  auto.arima -0.2826189 0.3439279 0.3102743  -4.236451  4.617906 3.149053 0.3624226      tbats          0.25
2        bats -0.1240606 0.1857631 0.1676487  -1.878305  2.479522 1.701510 0.1344866      tbats          1.60
3     croston -0.8903343 0.9183247 0.8903343 -13.164300 13.164300 9.036229 0.4086420      tbats          1.08
4         ets  0.4009141 0.5010641 0.4133541   5.941724  6.126020 4.195235 0.7171674      tbats          0.05
5       meanf -0.3138889 0.3862010 0.3583333  -4.709314  5.322341 3.636816 0.4086420      tbats          0.00
6       naive -0.4250000 0.4808846 0.4250000  -6.339031  6.339031 4.313433 0.4086420      tbats          0.02
7      nnetar -0.9093190 1.0220091 0.9093190 -13.543554 13.543554 9.228909 0.6192314      tbats          1.61
8         rwf -0.4250000 0.4808846 0.4250000  -6.339031  6.339031 4.313433 0.4086420      tbats          0.00
9   rwf_drift -0.3683824 0.4203015 0.3745588  -5.497541  5.582734 3.801493 0.3661817      tbats          0.00
10     snaive -0.4250000 0.4808846 0.4250000  -6.339031  6.339031 4.313433 0.4086420      tbats          0.00
11    splinef  0.3383595 0.4374294 0.3586967   5.014299  5.315592 3.640504 0.7075714      tbats          0.34
12   StructTS  0.2306096 0.3144022 0.2637272   3.405088  3.895718 2.676634 0.6510857      tbats          0.00
13      tbats -0.1240606 0.1857631 0.1676487  -1.878305  2.479522 1.701510 0.1344866      tbats          3.58
14     thetaf -0.4280973 0.4842184 0.4280973  -6.385061  6.385061 4.344868 0.4107693      tbats          0.02

$wt$best_forecast
    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
182       6.435371 6.171671 6.699071 6.032077 6.838666
183       6.353675 5.929582 6.777769 5.705081 7.002270
184       6.288319 5.692546 6.884092 5.377163 7.199475

$wt$df_comparison
         time forecasted observed
1  0171-12-18   7.183704     7.25
2  0172-12-18   7.098355     7.25
3  0173-12-18   7.030424     6.75
4  0174-12-18   6.976302     6.75
5  0175-12-19   6.933147     6.75
6  0176-12-18   6.898715     6.75
7  0177-12-18   6.871227     6.75
8  0178-12-18   6.849274     6.75
9  0179-12-18   6.831736     6.75
10 0180-12-18   6.817721     6.50

我想从这些输出列表中提取一些信息,以便可以提供简明的摘要。表格形式的输出格式如下所示:

var no_obs best_model pt_fcast1 pt_fcast2 pt_fcast3 
wt   181    tbats     6.435371   6.353675  6.288319
ht   150    croston   6.924046   6.963400  6.660900
dist 240    nnetar    0.8252435  1.5224686 2.2196936

在这里需要一些帮助,以便如何制作这张桌子!!!!

0 个答案:

没有答案