if (FALSE) {
-simdat <- sim_mvgam(n_series = 3, trend_model = 'AR1')
+ # \donttest{
+simdat <- sim_mvgam(n_series = 3, trend_model = AR())
mod <- mvgam(y ~ s(season, bs = 'cc', k = 6),
trend_model = AR(),
+ noncentred = TRUE,
data = simdat$data_train,
- burnin = 300,
- samples = 300,
chains = 2)
+#> Compiling Stan program using cmdstanr
+#>
+#> 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/RtmpysUQB0/model-5e0c560b6794.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
+#> Start sampling
+#> Running MCMC with 2 parallel chains...
+#>
+#> Chain 1 Iteration: 1 / 1000 [ 0%] (Warmup)
+#> Chain 2 Iteration: 1 / 1000 [ 0%] (Warmup)
+#> Chain 1 Iteration: 100 / 1000 [ 10%] (Warmup)
+#> Chain 2 Iteration: 100 / 1000 [ 10%] (Warmup)
+#> Chain 1 Iteration: 200 / 1000 [ 20%] (Warmup)
+#> Chain 1 Iteration: 300 / 1000 [ 30%] (Warmup)
+#> Chain 2 Iteration: 200 / 1000 [ 20%] (Warmup)
+#> Chain 2 Iteration: 300 / 1000 [ 30%] (Warmup)
+#> Chain 1 Iteration: 400 / 1000 [ 40%] (Warmup)
+#> Chain 2 Iteration: 400 / 1000 [ 40%] (Warmup)
+#> Chain 2 Iteration: 500 / 1000 [ 50%] (Warmup)
+#> Chain 2 Iteration: 501 / 1000 [ 50%] (Sampling)
+#> Chain 1 Iteration: 500 / 1000 [ 50%] (Warmup)
+#> Chain 1 Iteration: 501 / 1000 [ 50%] (Sampling)
+#> Chain 2 Iteration: 600 / 1000 [ 60%] (Sampling)
+#> Chain 1 Iteration: 600 / 1000 [ 60%] (Sampling)
+#> Chain 1 Iteration: 700 / 1000 [ 70%] (Sampling)
+#> Chain 2 Iteration: 700 / 1000 [ 70%] (Sampling)
+#> Chain 2 Iteration: 800 / 1000 [ 80%] (Sampling)
+#> Chain 1 Iteration: 800 / 1000 [ 80%] (Sampling)
+#> Chain 2 Iteration: 900 / 1000 [ 90%] (Sampling)
+#> Chain 1 Iteration: 900 / 1000 [ 90%] (Sampling)
+#> Chain 1 Iteration: 1000 / 1000 [100%] (Sampling)
+#> Chain 2 Iteration: 1000 / 1000 [100%] (Sampling)
+#> Chain 1 finished in 1.3 seconds.
+#> Chain 2 finished in 1.2 seconds.
+#>
+#> Both chains finished successfully.
+#> Mean chain execution time: 1.2 seconds.
+#> Total execution time: 1.4 seconds.
+#>
# Hindcasts on response scale
hc <- hindcast(mod)
str(hc)
+#> List of 15
+#> $ call :Class 'formula' language y ~ s(season, bs = "cc", k = 6)
+#> .. ..- attr(*, ".Environment")=<environment: 0x00000284b2958eb8>
+#> $ trend_call : NULL
+#> $ family : chr "poisson"
+#> $ trend_model :List of 4
+#> ..$ trend_model: chr "AR1"
+#> ..$ ma : logi FALSE
+#> ..$ cor : logi FALSE
+#> ..$ label : language AR()
+#> ..- attr(*, "class")= chr "mvgam_trend"
+#> $ drift : logi FALSE
+#> $ use_lv : logi FALSE
+#> $ fit_engine : chr "stan"
+#> $ type : chr "response"
+#> $ series_names : chr [1:3] "series_1" "series_2" "series_3"
+#> $ train_observations:List of 3
+#> ..$ series_1: int [1:75] 0 0 0 1 0 1 1 4 0 0 ...
+#> ..$ series_2: int [1:75] 0 0 0 0 1 0 4 0 0 0 ...
+#> ..$ series_3: int [1:75] 1 1 1 2 0 1 4 6 6 0 ...
+#> $ train_times : int [1:75] 1 2 3 4 5 6 7 8 9 10 ...
+#> $ test_observations : NULL
+#> $ test_times : NULL
+#> $ hindcasts :List of 3
+#> ..$ series_1: num [1:1000, 1:75] 1 0 0 1 1 1 0 1 1 1 ...
+#> .. ..- attr(*, "dimnames")=List of 2
+#> .. .. ..$ : NULL
+#> .. .. ..$ : chr [1:75] "ypred[1,1]" "ypred[2,1]" "ypred[3,1]" "ypred[4,1]" ...
+#> ..$ series_2: num [1:1000, 1:75] 0 0 0 0 1 0 1 0 0 1 ...
+#> .. ..- attr(*, "dimnames")=List of 2
+#> .. .. ..$ : NULL
+#> .. .. ..$ : chr [1:75] "ypred[1,2]" "ypred[2,2]" "ypred[3,2]" "ypred[4,2]" ...
+#> ..$ series_3: num [1:1000, 1:75] 5 1 1 0 0 0 3 0 3 1 ...
+#> .. ..- attr(*, "dimnames")=List of 2
+#> .. .. ..$ : NULL
+#> .. .. ..$ : chr [1:75] "ypred[1,3]" "ypred[2,3]" "ypred[3,3]" "ypred[4,3]" ...
+#> $ forecasts : NULL
+#> - attr(*, "class")= chr "mvgam_forecast"
plot(hc, series = 1)
+#> No non-missing values in test_observations; cannot calculate forecast score
+
plot(hc, series = 2)
+#> No non-missing values in test_observations; cannot calculate forecast score
+
plot(hc, series = 3)
+#> No non-missing values in test_observations; cannot calculate forecast score
+
# Forecasts on response scale
fc <- forecast(mod, newdata = simdat$data_test)
str(fc)
+#> List of 16
+#> $ call :Class 'formula' language y ~ s(season, bs = "cc", k = 6)
+#> .. ..- attr(*, ".Environment")=<environment: 0x00000284b2958eb8>
+#> $ trend_call : NULL
+#> $ family : chr "poisson"
+#> $ family_pars : NULL
+#> $ trend_model :List of 4
+#> ..$ trend_model: chr "AR1"
+#> ..$ ma : logi FALSE
+#> ..$ cor : logi FALSE
+#> ..$ label : language AR()
+#> ..- attr(*, "class")= chr "mvgam_trend"
+#> $ drift : logi FALSE
+#> $ use_lv : logi FALSE
+#> $ fit_engine : chr "stan"
+#> $ type : chr "response"
+#> $ series_names : Factor w/ 3 levels "series_1","series_2",..: 1 2 3
+#> $ train_observations:List of 3
+#> ..$ series_1: int [1:75] 0 0 0 1 0 1 1 4 0 0 ...
+#> ..$ series_2: int [1:75] 0 0 0 0 1 0 4 0 0 0 ...
+#> ..$ series_3: int [1:75] 1 1 1 2 0 1 4 6 6 0 ...
+#> $ train_times : int [1:75] 1 2 3 4 5 6 7 8 9 10 ...
+#> $ test_observations :List of 3
+#> ..$ series_1: int [1:25] 2 0 1 0 0 1 1 1 0 0 ...
+#> ..$ series_2: int [1:25] 4 0 0 1 2 1 2 1 2 0 ...
+#> ..$ series_3: int [1:25] 5 0 2 6 6 4 1 8 2 0 ...
+#> $ test_times : int [1:25] 76 77 78 79 80 81 82 83 84 85 ...
+#> $ hindcasts :List of 3
+#> ..$ series_1: num [1:1000, 1:75] 1 0 0 1 1 1 0 1 1 1 ...
+#> .. ..- attr(*, "dimnames")=List of 2
+#> .. .. ..$ : NULL
+#> .. .. ..$ : chr [1:75] "ypred[1,1]" "ypred[2,1]" "ypred[3,1]" "ypred[4,1]" ...
+#> ..$ series_2: num [1:1000, 1:75] 0 0 0 0 1 0 1 0 0 1 ...
+#> .. ..- attr(*, "dimnames")=List of 2
+#> .. .. ..$ : NULL
+#> .. .. ..$ : chr [1:75] "ypred[1,2]" "ypred[2,2]" "ypred[3,2]" "ypred[4,2]" ...
+#> ..$ series_3: num [1:1000, 1:75] 5 1 1 0 0 0 3 0 3 1 ...
+#> .. ..- attr(*, "dimnames")=List of 2
+#> .. .. ..$ : NULL
+#> .. .. ..$ : chr [1:75] "ypred[1,3]" "ypred[2,3]" "ypred[3,3]" "ypred[4,3]" ...
+#> $ forecasts :List of 3
+#> ..$ series_1: int [1:1000, 1:25] 0 0 0 0 1 2 3 0 1 0 ...
+#> ..$ series_2: int [1:1000, 1:25] 0 0 1 0 0 0 0 1 3 2 ...
+#> ..$ series_3: int [1:1000, 1:25] 0 0 0 1 1 0 2 3 0 0 ...
+#> - attr(*, "class")= chr "mvgam_forecast"
plot(fc, series = 1)
+#> Out of sample DRPS:
+#> 10.869222
+
plot(fc, series = 2)
+#> Out of sample DRPS:
+#> 12.066384
+
plot(fc, series = 3)
+#> Out of sample DRPS:
+#> 31.907347
+
# Forecasts as expectations
fc <- forecast(mod, newdata = simdat$data_test, type = 'expected')
plot(fc, series = 1)
+
plot(fc, series = 2)
+
plot(fc, series = 3)
+
# Dynamic trend extrapolations
fc <- forecast(mod, newdata = simdat$data_test, type = 'trend')
plot(fc, series = 1)
+
plot(fc, series = 2)
+
plot(fc, series = 3)
-}
+
+# }