Skip to contents

Generate evenly weighted ensemble forecast distributions from mvgam_forecast objects

Usage

ensemble(object, ...)

# S3 method for class 'mvgam_forecast'
ensemble(object, ..., ndraws = 5000)

Arguments

object

list object of class mvgam_forecast. See forecast.mvgam()

...

More mvgam_forecast objects.

ndraws

Positive integer specifying the number of draws to use from each forecast distribution for creating the ensemble. If some of the ensemble members have fewer draws than ndraws, their forecast distributions will be resampled with replacement to achieve the correct number of draws

Value

An object of class mvgam_forecast containing the ensemble predictions. This object can be readily used with the supplied S3 functions plot and score

Details

It is widely recognised in the forecasting literature that combining forecasts from different models often results in improved forecast accuracy. The simplest way to create an ensemble is to use evenly weighted combinations of forecasts from the different models. This is straightforward to do in a Bayesian setting with mvgam as the posterior MCMC draws contained in each mvgam_forecast object will already implicitly capture correlations among the temporal posterior predictions.

Author

Nicholas J Clark

Examples

# \donttest{
# Simulate some series and fit a few competing dynamic models
set.seed(1)
simdat <- sim_mvgam(n_series = 1,
                    prop_trend = 0.6,
                    mu = 1)

plot_mvgam_series(data = simdat$data_train,
                 newdata = simdat$data_test)


m1 <- mvgam(y ~ 1,
            trend_formula = ~ time +
              s(season, bs = 'cc', k = 9),
            trend_model = AR(p = 1),
            noncentred = TRUE,
            data = simdat$data_train,
            newdata = simdat$data_test,
            chains = 2,
            silent = 2)
#> In file included from stan/lib/stan_math/stan/math/prim/prob/von_mises_lccdf.hpp:5,
#>                  from stan/lib/stan_math/stan/math/prim/prob/von_mises_ccdf_log.hpp:4,
#>                  from stan/lib/stan_math/stan/math/prim/prob.hpp:359,
#>                  from stan/lib/stan_math/stan/math/prim.hpp:16,
#>                  from stan/lib/stan_math/stan/math/rev.hpp:16,
#>                  from stan/lib/stan_math/stan/math.hpp:19,
#>                  from stan/src/stan/model/model_header.hpp:4,
#>                  from C:/Users/uqnclar2/AppData/Local/Temp/RtmpotLup8/model-9e8c74e52e4c.hpp:2:
#> stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp: In function 'stan::return_type_t<T_x, T_sigma, T_l> stan::math::von_mises_cdf(const T_x&, const T_mu&, const T_k&)':
#> stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp:194: note: '-Wmisleading-indentation' is disabled from this point onwards, since column-tracking was disabled due to the size of the code/headers
#>   194 |       if (cdf_n < 0.0)
#>       | 
#> stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp:194: note: adding '-flarge-source-files' will allow for more column-tracking support, at the expense of compilation time and memory

m2 <- mvgam(y ~ time,
            trend_model = RW(),
            noncentred = TRUE,
            data = simdat$data_train,
            newdata = simdat$data_test,
            chains = 2,
            silent = 2)
#> In file included from stan/lib/stan_math/stan/math/prim/prob/von_mises_lccdf.hpp:5,
#>                  from stan/lib/stan_math/stan/math/prim/prob/von_mises_ccdf_log.hpp:4,
#>                  from stan/lib/stan_math/stan/math/prim/prob.hpp:359,
#>                  from stan/lib/stan_math/stan/math/prim.hpp:16,
#>                  from stan/lib/stan_math/stan/math/rev.hpp:16,
#>                  from stan/lib/stan_math/stan/math.hpp:19,
#>                  from stan/src/stan/model/model_header.hpp:4,
#>                  from C:/Users/uqnclar2/AppData/Local/Temp/RtmpotLup8/model-9e8c1777634c.hpp:2:
#> stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp: In function 'stan::return_type_t<T_x, T_sigma, T_l> stan::math::von_mises_cdf(const T_x&, const T_mu&, const T_k&)':
#> stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp:194: note: '-Wmisleading-indentation' is disabled from this point onwards, since column-tracking was disabled due to the size of the code/headers
#>   194 |       if (cdf_n < 0.0)
#>       | 
#> stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp:194: note: adding '-flarge-source-files' will allow for more column-tracking support, at the expense of compilation time and memory

# Calculate forecast distributions for each model
fc1 <- forecast(m1)
fc2 <- forecast(m2)

# Generate the ensemble forecast
ensemble_fc <- ensemble(fc1, fc2)

# Plot forecasts
plot(fc1)
#> Out of sample DRPS:
#> 42.791261

plot(fc2)
#> Out of sample DRPS:
#> 48.658331

plot(ensemble_fc)
#> Out of sample DRPS:
#> 44.3088696


# Score forecasts
score(fc1)
#> $series_1
#>       score in_interval interval_width eval_horizon score_type
#> 1  3.433228           1            0.9            1       crps
#> 2  1.105110           1            0.9            2       crps
#> 3  1.995765           1            0.9            3       crps
#> 4  1.447371           1            0.9            4       crps
#> 5  0.977251           1            0.9            5       crps
#> 6  1.419407           1            0.9            6       crps
#> 7  2.022923           1            0.9            7       crps
#> 8  1.727456           1            0.9            8       crps
#> 9  1.147758           1            0.9            9       crps
#> 10 1.200552           1            0.9           10       crps
#> 11 1.318235           1            0.9           11       crps
#> 12 1.700447           1            0.9           12       crps
#> 13 1.018621           1            0.9           13       crps
#> 14 0.988125           1            0.9           14       crps
#> 15 0.896207           1            0.9           15       crps
#> 16 1.007965           1            0.9           16       crps
#> 17 1.042871           1            0.9           17       crps
#> 18 4.183073           1            0.9           18       crps
#> 19 1.335348           1            0.9           19       crps
#> 20 2.246848           1            0.9           20       crps
#> 21 1.614939           1            0.9           21       crps
#> 22 1.568674           1            0.9           22       crps
#> 23 4.672876           1            0.9           23       crps
#> 24 1.362186           1            0.9           24       crps
#> 25 1.358025           1            0.9           25       crps
#> 
#> $all_series
#>       score eval_horizon score_type
#> 1  3.433228            1   sum_crps
#> 2  1.105110            2   sum_crps
#> 3  1.995765            3   sum_crps
#> 4  1.447371            4   sum_crps
#> 5  0.977251            5   sum_crps
#> 6  1.419407            6   sum_crps
#> 7  2.022923            7   sum_crps
#> 8  1.727456            8   sum_crps
#> 9  1.147758            9   sum_crps
#> 10 1.200552           10   sum_crps
#> 11 1.318235           11   sum_crps
#> 12 1.700447           12   sum_crps
#> 13 1.018621           13   sum_crps
#> 14 0.988125           14   sum_crps
#> 15 0.896207           15   sum_crps
#> 16 1.007965           16   sum_crps
#> 17 1.042871           17   sum_crps
#> 18 4.183073           18   sum_crps
#> 19 1.335348           19   sum_crps
#> 20 2.246848           20   sum_crps
#> 21 1.614939           21   sum_crps
#> 22 1.568674           22   sum_crps
#> 23 4.672876           23   sum_crps
#> 24 1.362186           24   sum_crps
#> 25 1.358025           25   sum_crps
#> 
score(fc2)
#> $series_1
#>       score in_interval interval_width eval_horizon score_type
#> 1  4.171226           1            0.9            1       crps
#> 2  1.547056           1            0.9            2       crps
#> 3  3.124789           0            0.9            3       crps
#> 4  0.999647           1            0.9            4       crps
#> 5  2.435121           1            0.9            5       crps
#> 6  2.610246           1            0.9            6       crps
#> 7  1.928458           1            0.9            7       crps
#> 8  0.961976           1            0.9            8       crps
#> 9  1.625352           1            0.9            9       crps
#> 10 1.302485           1            0.9           10       crps
#> 11 1.584327           1            0.9           11       crps
#> 12 1.754281           1            0.9           12       crps
#> 13 1.051481           1            0.9           13       crps
#> 14 1.081281           1            0.9           14       crps
#> 15 1.217669           1            0.9           15       crps
#> 16 1.177959           1            0.9           16       crps
#> 17 1.259938           1            0.9           17       crps
#> 18 2.725221           1            0.9           18       crps
#> 19 1.230060           1            0.9           19       crps
#> 20 3.820228           1            0.9           20       crps
#> 21 2.635251           1            0.9           21       crps
#> 22 1.648463           1            0.9           22       crps
#> 23 4.030445           1            0.9           23       crps
#> 24 1.360764           1            0.9           24       crps
#> 25 1.374607           1            0.9           25       crps
#> 
#> $all_series
#>       score eval_horizon score_type
#> 1  4.171226            1   sum_crps
#> 2  1.547056            2   sum_crps
#> 3  3.124789            3   sum_crps
#> 4  0.999647            4   sum_crps
#> 5  2.435121            5   sum_crps
#> 6  2.610246            6   sum_crps
#> 7  1.928458            7   sum_crps
#> 8  0.961976            8   sum_crps
#> 9  1.625352            9   sum_crps
#> 10 1.302485           10   sum_crps
#> 11 1.584327           11   sum_crps
#> 12 1.754281           12   sum_crps
#> 13 1.051481           13   sum_crps
#> 14 1.081281           14   sum_crps
#> 15 1.217669           15   sum_crps
#> 16 1.177959           16   sum_crps
#> 17 1.259938           17   sum_crps
#> 18 2.725221           18   sum_crps
#> 19 1.230060           19   sum_crps
#> 20 3.820228           20   sum_crps
#> 21 2.635251           21   sum_crps
#> 22 1.648463           22   sum_crps
#> 23 4.030445           23   sum_crps
#> 24 1.360764           24   sum_crps
#> 25 1.374607           25   sum_crps
#> 
score(ensemble_fc)
#> $series_1
#>        score in_interval interval_width eval_horizon score_type
#> 1  3.8263402           1            0.9            1       crps
#> 2  1.3036929           1            0.9            2       crps
#> 3  2.5519035           1            0.9            3       crps
#> 4  1.0739452           1            0.9            4       crps
#> 5  1.6133805           1            0.9            5       crps
#> 6  1.9180633           1            0.9            6       crps
#> 7  1.9954492           1            0.9            7       crps
#> 8  1.2471014           1            0.9            8       crps
#> 9  1.2738834           1            0.9            9       crps
#> 10 1.1792346           1            0.9           10       crps
#> 11 1.4541516           1            0.9           11       crps
#> 12 1.6823855           1            0.9           12       crps
#> 13 1.0212761           1            0.9           13       crps
#> 14 1.0489788           1            0.9           14       crps
#> 15 0.9839557           1            0.9           15       crps
#> 16 0.9631836           1            0.9           16       crps
#> 17 0.9966610           1            0.9           17       crps
#> 18 3.4294286           1            0.9           18       crps
#> 19 1.2707383           1            0.9           19       crps
#> 20 2.9218745           1            0.9           20       crps
#> 21 2.0465904           1            0.9           21       crps
#> 22 1.4433498           1            0.9           22       crps
#> 23 4.2497062           1            0.9           23       crps
#> 24 1.3876704           1            0.9           24       crps
#> 25 1.4259249           1            0.9           25       crps
#> 
#> $all_series
#>        score eval_horizon score_type
#> 1  3.8263402            1   sum_crps
#> 2  1.3036929            2   sum_crps
#> 3  2.5519035            3   sum_crps
#> 4  1.0739452            4   sum_crps
#> 5  1.6133805            5   sum_crps
#> 6  1.9180633            6   sum_crps
#> 7  1.9954492            7   sum_crps
#> 8  1.2471014            8   sum_crps
#> 9  1.2738834            9   sum_crps
#> 10 1.1792346           10   sum_crps
#> 11 1.4541516           11   sum_crps
#> 12 1.6823855           12   sum_crps
#> 13 1.0212761           13   sum_crps
#> 14 1.0489788           14   sum_crps
#> 15 0.9839557           15   sum_crps
#> 16 0.9631836           16   sum_crps
#> 17 0.9966610           17   sum_crps
#> 18 3.4294286           18   sum_crps
#> 19 1.2707383           19   sum_crps
#> 20 2.9218745           20   sum_crps
#> 21 2.0465904           21   sum_crps
#> 22 1.4433498           22   sum_crps
#> 23 4.2497062           23   sum_crps
#> 24 1.3876704           24   sum_crps
#> 25 1.4259249           25   sum_crps
#> 
# }