diff --git a/README.md b/README.md index 46c86243..26e4a39a 100644 --- a/README.md +++ b/README.md @@ -234,29 +234,29 @@ summary(lynx_mvgam) #> #> #> GAM coefficient (beta) estimates: -#> 2.5% 50% 97.5% Rhat n_eff -#> (Intercept) 6.4000 6.60 6.900 1 718 -#> s(season).1 -0.6500 -0.13 0.420 1 987 -#> s(season).2 0.7600 1.30 1.900 1 865 -#> s(season).3 1.3000 1.90 2.600 1 816 -#> s(season).4 -0.0360 0.53 1.100 1 909 -#> s(season).5 -1.4000 -0.69 -0.096 1 759 -#> s(season).6 -1.3000 -0.56 0.150 1 869 -#> s(season).7 0.0092 0.71 1.400 1 970 -#> s(season).8 0.6100 1.40 2.000 1 802 -#> s(season).9 -0.3500 0.21 0.840 1 897 -#> s(season).10 -1.4000 -0.86 -0.370 1 1366 +#> 2.5% 50% 97.5% Rhat n_eff +#> (Intercept) 6.400 6.60 6.900 1.00 961 +#> s(season).1 -0.650 -0.14 0.380 1.00 984 +#> s(season).2 0.730 1.30 1.900 1.00 1113 +#> s(season).3 1.300 1.90 2.500 1.00 727 +#> s(season).4 -0.054 0.53 1.100 1.00 727 +#> s(season).5 -1.300 -0.70 -0.069 1.00 919 +#> s(season).6 -1.200 -0.55 0.170 1.00 1012 +#> s(season).7 0.012 0.73 1.400 1.00 1134 +#> s(season).8 0.600 1.40 2.100 1.01 756 +#> s(season).9 -0.410 0.22 0.810 1.00 710 +#> s(season).10 -1.400 -0.87 -0.350 1.00 1164 #> #> Approximate significance of GAM smooths: #> edf Ref.df Chi.sq p-value -#> s(season) 9.96 10 49.6 <2e-16 *** +#> s(season) 9.95 10 53.4 <2e-16 *** #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 #> #> Latent trend parameter AR estimates: #> 2.5% 50% 97.5% Rhat n_eff -#> ar1[1] 0.57 0.83 0.98 1.01 659 -#> sigma[1] 0.38 0.48 0.60 1.01 745 +#> ar1[1] 0.59 0.83 0.99 1.00 519 +#> sigma[1] 0.38 0.48 0.60 1.01 485 #> #> Stan MCMC diagnostics: #> n_eff / iter looks reasonable for all parameters @@ -265,7 +265,7 @@ summary(lynx_mvgam) #> 0 of 2000 iterations saturated the maximum tree depth of 12 (0%) #> E-FMI indicated no pathological behavior #> -#> Samples were drawn using NUTS(diag_e) at Thu Jul 25 3:12:50 PM 2024. +#> Samples were drawn using NUTS(diag_e) at Tue Sep 03 1:56:36 PM 2024. #> For each parameter, n_eff is a crude measure of effective sample size, #> and Rhat is the potential scale reduction factor on split MCMC chains #> (at convergence, Rhat = 1) @@ -370,14 +370,12 @@ partial effects of smooths on the link scale ``` r require(gratia) #> Loading required package: gratia +#> Warning: package 'gratia' was built under R version 4.2.3 #> #> Attaching package: 'gratia' #> The following object is masked from 'package:mvgam': #> #> add_residuals -#> The following object is masked from 'package:brms': -#> -#> posterior_samples draw(lynx_mvgam) ``` @@ -405,7 +403,7 @@ series (testing and training) ``` r plot(lynx_mvgam, type = 'forecast', newdata = lynx_test) #> Out of sample DRPS: -#> 2380.85453525 +#> 2356.32008125 ``` @@ -535,41 +533,41 @@ summary(mod, include_betas = FALSE) #> #> Observation precision parameter estimates: #> 2.5% 50% 97.5% Rhat n_eff -#> phi[1] 5.4 8.3 12 1 1248 -#> phi[2] 5.7 8.6 13 1 1312 -#> phi[3] 5.6 8.5 12 1 1724 +#> phi[1] 5.4 8.3 12 1 2019 +#> phi[2] 5.7 8.7 13 1 1795 +#> phi[3] 5.5 8.4 12 1 1680 #> #> GAM coefficient (beta) estimates: -#> 2.5% 50% 97.5% Rhat n_eff -#> (Intercept) -0.2 0.19 0.46 1.01 566 +#> 2.5% 50% 97.5% Rhat n_eff +#> (Intercept) -0.18 0.19 0.45 1.01 757 #> #> Approximate significance of GAM smooths: #> edf Ref.df Chi.sq p-value -#> s(season) 3.872 5 29.63 1.6e-05 *** -#> s(season):seriesseries_1 0.615 4 0.77 0.98 -#> s(season):seriesseries_2 1.012 4 0.30 0.99 -#> s(season):seriesseries_3 1.106 4 1.54 0.81 +#> s(season) 4.231 5 28.89 2.6e-06 *** +#> s(season):seriesseries_1 0.687 4 0.69 0.98 +#> s(season):seriesseries_2 0.664 4 0.60 0.99 +#> s(season):seriesseries_3 1.286 4 1.39 0.82 #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 #> #> Latent trend marginal deviation (alpha) and length scale (rho) estimates: -#> 2.5% 50% 97.5% Rhat n_eff -#> alpha_gp[1] 0.051 0.41 0.92 1.01 525 -#> alpha_gp[2] 0.360 0.72 1.20 1.00 946 -#> alpha_gp[3] 0.150 0.46 1.00 1.00 659 -#> rho_gp[1] 1.100 3.80 15.00 1.01 370 -#> rho_gp[2] 1.900 7.80 37.00 1.01 365 -#> rho_gp[3] 1.400 5.10 21.00 1.00 645 +#> 2.5% 50% 97.5% Rhat n_eff +#> alpha_gp[1] 0.06 0.41 0.96 1.00 823 +#> alpha_gp[2] 0.38 0.73 1.30 1.00 1073 +#> alpha_gp[3] 0.15 0.45 0.98 1.00 903 +#> rho_gp[1] 1.10 3.90 14.00 1.01 302 +#> rho_gp[2] 1.70 7.00 32.00 1.01 364 +#> rho_gp[3] 1.30 4.80 22.00 1.01 373 #> #> Stan MCMC diagnostics: #> n_eff / iter looks reasonable for all parameters #> Rhat looks reasonable for all parameters -#> 12 of 2000 iterations ended with a divergence (0.6%) +#> 18 of 2000 iterations ended with a divergence (0.9%) #> *Try running with larger adapt_delta to remove the divergences #> 0 of 2000 iterations saturated the maximum tree depth of 12 (0%) #> E-FMI indicated no pathological behavior #> -#> Samples were drawn using NUTS(diag_e) at Thu Jul 25 3:13:40 PM 2024. +#> Samples were drawn using NUTS(diag_e) at Tue Sep 03 1:57:57 PM 2024. #> For each parameter, n_eff is a crude measure of effective sample size, #> and Rhat is the potential scale reduction factor on split MCMC chains #> (at convergence, Rhat = 1) diff --git a/docs/articles/data_in_mvgam.html b/docs/articles/data_in_mvgam.html index ff06e687..17989235 100644 --- a/docs/articles/data_in_mvgam.html +++ b/docs/articles/data_in_mvgam.html @@ -81,7 +81,7 @@
vignettes/data_in_mvgam.Rmd
data_in_mvgam.Rmd
series
as a factor
variable
@@ -176,28 +176,28 @@
-summary(mgcv::gam(y ~ series + s(time, by = series),
+summary(mgcv::gam(y ~ series + s(time, by = series),
data = simdat$data_train,
family = poisson()))
#>
@@ -208,25 +208,23 @@ A single outcome variable#> y ~ series + s(time, by = series)
#>
#> Parametric coefficients:
-#> Estimate Std. Error z value Pr(>|z|)
-#> (Intercept) -1.6035 0.6005 -2.671 0.00757 **
-#> seriesseries_2 1.9155 0.6601 2.902 0.00371 **
-#> seriesseries_3 1.2765 0.6790 1.880 0.06012 .
-#> seriesseries_4 2.0982 0.6508 3.224 0.00126 **
+#> Estimate Std. Error z value Pr(>|z|)
+#> (Intercept) -0.1536 0.2918 -0.526 0.5987
+#> seriesseries_2 0.6781 0.3582 1.893 0.0584 .
+#> seriesseries_3 -2.2093 1.1016 -2.005 0.0449 *
+#> seriesseries_4 -0.3154 0.4940 -0.639 0.5231
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Approximate significance of smooth terms:
-#> edf Ref.df Chi.sq p-value
-#> s(time):seriesseries_1 1.494 1.833 0.575 0.73049
-#> s(time):seriesseries_2 2.591 3.278 13.476 0.00574 **
-#> s(time):seriesseries_3 4.750 5.799 9.781 0.12285
-#> s(time):seriesseries_4 4.592 5.621 13.802 0.03315 *
-#> ---
-#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
+#> edf Ref.df Chi.sq p-value
+#> s(time):seriesseries_1 2.752 3.397 1.887 0.608
+#> s(time):seriesseries_2 1.236 1.436 1.218 0.507
+#> s(time):seriesseries_3 4.664 5.653 4.517 0.580
+#> s(time):seriesseries_4 3.461 4.274 6.525 0.194
#>
-#> R-sq.(adj) = 0.628 Deviance explained = 68.3%
-#> UBRE = 0.31332 Scale est. = 1 n = 59
Depending on the observation families you plan to use when building models, there may be some restrictions that need to be satisfied within the outcome variable. For example, a Beta regression can only handle @@ -248,17 +246,17 @@
A call to gam
using the mgcv
package leads
to a model that actually fits (though it does give an unhelpful warning
message):
But the same call to mvgam
gives us something more
useful:
@@ -369,15 +367,15 @@Checking data with
get_mvgam_ series = factor('series_1'), outcome = rnorm(8)) bad_times -#> time series outcome -#> 1 1 series_1 -0.8227444 -#> 2 3 series_1 -0.6851957 -#> 3 5 series_1 1.5221436 -#> 4 7 series_1 -0.8227729 -#> 5 9 series_1 1.0787734 -#> 6 11 series_1 -0.7118972 -#> 7 13 series_1 -1.2150116 -#> 8 15 series_1 1.5165404
Next we call get_mvgam_priors
by simply specifying an
intercept-only model, which is enough to trigger all the checks:
@@ -398,22 +396,22 @@Checking data with
get_mvgam_ dplyr::arrange(time) -> good_times #> Joining with `by = join_by(time, series)` good_times -#> time series outcome -#> 1 1 series_1 -0.8227444 -#> 2 2 series_1 NA -#> 3 3 series_1 -0.6851957 -#> 4 4 series_1 NA -#> 5 5 series_1 1.5221436 -#> 6 6 series_1 NA -#> 7 7 series_1 -0.8227729 -#> 8 8 series_1 NA -#> 9 9 series_1 1.0787734 -#> 10 10 series_1 NA -#> 11 11 series_1 -0.7118972 -#> 12 12 series_1 NA -#> 13 13 series_1 -1.2150116 -#> 14 14 series_1 NA -#> 15 15 series_1 1.5165404
Now the call to get_mvgam_priors
, using our filled in
data, should work:
@@ -423,9 +421,9 @@Checking data with
get_mvgam_ #> param_name param_length param_info #> 1 (Intercept) 1 (Intercept) #> 2 vector<lower=0>[n_series] sigma_obs; 1 observation error sd -#> prior example_change -#> 1 (Intercept) ~ student_t(3, -0.7, 2.5); (Intercept) ~ normal(0, 1); -#> 2 sigma_obs ~ student_t(3, 0, 2.5); sigma_obs ~ normal(0.91, 0.9); +#> prior example_change +#> 1 (Intercept) ~ student_t(3, -0.2, 2.5); (Intercept) ~ normal(0, 1); +#> 2 sigma_obs ~ student_t(3, 0, 2.5); sigma_obs ~ normal(-0.47, 0.56); #> new_lowerbound new_upperbound #> 1 NA NA #> 2 NA NA
get_mvgam_
#> param_name param_length param_info
#> 1 (Intercept) 1 (Intercept)
#> 2 vector<lower=0>[n_series] sigma_obs; 1 observation error sd
-#> prior example_change
-#> 1 (Intercept) ~ student_t(3, -0.5, 2.5); (Intercept) ~ normal(0, 1);
-#> 2 sigma_obs ~ student_t(3, 0, 2.5); sigma_obs ~ normal(-0.01, 0.79);
+#> prior example_change
+#> 1 (Intercept) ~ student_t(3, -0.4, 2.5); (Intercept) ~ normal(0, 1);
+#> 2 sigma_obs ~ student_t(3, 0, 2.5); sigma_obs ~ normal(-0.62, 1);
#> new_lowerbound new_upperbound
#> 1 NA NA
#> 2 NA NA
@@ -498,17 +496,17 @@ NA
s= 'series1'),
time = 1:10)
miss_dat
-#> outcome cov series time
-#> 1 -1.5062280 NA series1 1
-#> 2 0.8873110 -1.419737577 series1 2
-#> 3 -0.5854087 0.006758633 series1 3
-#> 4 -0.8946378 -0.989167769 series1 4
-#> 5 -0.4520713 2.359401432 series1 5
-#> 6 0.5739319 -0.802900274 series1 6
-#> 7 -0.5756935 -0.735234481 series1 7
-#> 8 0.4873677 -1.386964284 series1 8
-#> 9 1.2759287 -0.474650053 series1 9
-#> 10 -1.8709314 -1.539955160 series1 10
+#> outcome cov series time
+#> 1 0.1561020 NA series1 1
+#> 2 0.1084784 0.98322738 series1 2
+#> 3 0.0330442 0.28407529 series1 3
+#> 4 0.6572311 -1.45353685 series1 4
+#> 5 0.8854784 0.02783985 series1 5
+#> 6 1.6044159 -1.17292983 series1 6
+#> 7 -0.9053955 0.88927692 series1 7
+#> 8 2.3019384 0.36575792 series1 8
+#> 9 0.1608429 -0.58446531 series1 9
+#> 10 0.9125095 3.75742498 series1 10
get_mvgam_priors(outcome ~ cov,
data = miss_dat,
@@ -517,10 +515,10 @@ Covariates with no NA
s#> 1 (Intercept) 1 (Intercept)
#> 2 cov 1 cov fixed effect
#> 3 vector<lower=0>[n_series] sigma_obs; 1 observation error sd
-#> prior example_change
-#> 1 (Intercept) ~ student_t(3, -0.5, 2.5); (Intercept) ~ normal(0, 1);
-#> 2 cov ~ student_t(3, 0, 2); cov ~ normal(0, 1);
-#> 3 sigma_obs ~ student_t(3, 0, 2.5); sigma_obs ~ normal(0.47, 0.76);
+#> prior example_change
+#> 1 (Intercept) ~ student_t(3, 0.4, 2.5); (Intercept) ~ normal(0, 1);
+#> 2 cov ~ student_t(3, 0, 2); cov ~ normal(0, 1);
+#> 3 sigma_obs ~ student_t(3, 0, 2.5); sigma_obs ~ normal(-0.59, 0.3);
#> new_lowerbound new_upperbound
#> 1 NA NA
#> 2 NA NA
@@ -551,14 +549,14 @@ Covariates with no NA
s#> 5 cov4 1 cov4 fixed effect
#> 6 cov5 1 cov5 fixed effect
#> 7 vector<lower=0>[n_series] sigma_obs; 1 observation error sd
-#> prior example_change
-#> 1 (Intercept) ~ student_t(3, -0.4, 2.5); (Intercept) ~ normal(0, 1);
-#> 2 cov1 ~ student_t(3, 0, 2); cov1 ~ normal(0, 1);
-#> 3 cov2 ~ student_t(3, 0, 2); cov2 ~ normal(0, 1);
-#> 4 cov3 ~ student_t(3, 0, 2); cov3 ~ normal(0, 1);
-#> 5 cov4 ~ student_t(3, 0, 2); cov4 ~ normal(0, 1);
-#> 6 cov5 ~ student_t(3, 0, 2); cov5 ~ normal(0, 1);
-#> 7 sigma_obs ~ student_t(3, 0, 2.5); sigma_obs ~ normal(-0.4, 0.32);
+#> prior example_change
+#> 1 (Intercept) ~ student_t(3, -0.2, 2.5); (Intercept) ~ normal(0, 1);
+#> 2 cov1 ~ student_t(3, 0, 2); cov1 ~ normal(0, 1);
+#> 3 cov2 ~ student_t(3, 0, 2); cov2 ~ normal(0, 1);
+#> 4 cov3 ~ student_t(3, 0, 2); cov3 ~ normal(0, 1);
+#> 5 cov4 ~ student_t(3, 0, 2); cov4 ~ normal(0, 1);
+#> 6 cov5 ~ student_t(3, 0, 2); cov5 ~ normal(0, 1);
+#> 7 sigma_obs ~ student_t(3, 0, 2.5); sigma_obs ~ normal(-0.32, 0.68);
#> new_lowerbound new_upperbound
#> 1 NA NA
#> 2 NA NA
@@ -740,8 +738,8 @@ Example with NEON tick data
-testmod <- mvgam(y ~ s(epiWeek, by = series, bs = 'cc') +
- s(series, bs = 're'),
+testmod <- mvgam(y ~ s(epiWeek, by = series, bs = 'cc') +
+ s(series, bs = 're'),
trend_model = 'AR1',
data = model_dat,
backend = 'cmdstanr',
@@ -770,7 +768,7 @@ Example with NEON tick data#> $ S8 : num [1:8, 1:8] 1.037 -0.416 0.419 0.117 0.188 ...
#> $ p_coefs : Named num 0
#> ..- attr(*, "names")= chr "(Intercept)"
-#> $ p_taus : num 1.14
+#> $ p_taus : num 0.945
#> $ ytimes : int [1:416, 1:8] 1 9 17 25 33 41 49 57 65 73 ...
#> $ n_series : int 8
#> $ sp : Named num [1:9] 0.368 0.368 0.368 0.368 0.368 ...
diff --git a/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-24-1.png b/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-24-1.png
index 327ff76c..a3825320 100644
Binary files a/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-24-1.png and b/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-24-1.png differ
diff --git a/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-25-1.png b/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-25-1.png
index d8288e81..0c08f9cd 100644
Binary files a/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-25-1.png and b/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-25-1.png differ
diff --git a/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-26-1.png b/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-26-1.png
index 3c39ede9..cb03d0e4 100644
Binary files a/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-26-1.png and b/docs/articles/data_in_mvgam_files/figure-html/unnamed-chunk-26-1.png differ
diff --git a/docs/articles/forecast_evaluation.html b/docs/articles/forecast_evaluation.html
index 804ac365..be3096b2 100644
--- a/docs/articles/forecast_evaluation.html
+++ b/docs/articles/forecast_evaluation.html
@@ -26,7 +26,7 @@
mvgam
- 1.1.2
+ 1.1.3
brms
, which can fit Hilbert space approximate
GPs. See ?brms::gp
for more details.
-mod2 <- mvgam(y ~ s(season, bs = 'cc', k = 8) +
- gp(time, by = series, c = 5/4, k = 20,
+mod2 <- mvgam(y ~ s(season, bs = 'cc', k = 8) +
+ gp(time, by = series, c = 5/4, k = 20,
scale = FALSE),
knots = list(season = c(0.5, 12.5)),
trend_model = 'None',
@@ -275,32 +275,32 @@ Modelling dynamics with GPs#>
#> GAM coefficient (beta) estimates:
#> 2.5% 50% 97.5% Rhat n_eff
-#> (Intercept) -1.1 -0.51 0.34 1 694
+#> (Intercept) -1.1 -0.51 0.25 1 731
#>
#> GAM gp term marginal deviation (alpha) and length scale (rho) estimates:
#> 2.5% 50% 97.5% Rhat n_eff
-#> alpha_gp(time):seriesseries_1 0.21 0.78 2.2 1 819
-#> alpha_gp(time):seriesseries_2 0.73 1.30 2.9 1 761
-#> alpha_gp(time):seriesseries_3 0.46 1.10 2.8 1 1262
-#> rho_gp(time):seriesseries_1 1.30 5.40 22.0 1 682
-#> rho_gp(time):seriesseries_2 2.10 10.00 17.0 1 450
-#> rho_gp(time):seriesseries_3 1.50 8.80 24.0 1 769
+#> alpha_gp(time):seriesseries_1 0.19 0.75 2 1.00 932
+#> alpha_gp(time):seriesseries_2 0.76 1.40 3 1.00 845
+#> alpha_gp(time):seriesseries_3 0.48 1.10 3 1.00 968
+#> rho_gp(time):seriesseries_1 1.10 4.90 25 1.01 678
+#> rho_gp(time):seriesseries_2 2.20 10.00 17 1.00 645
+#> rho_gp(time):seriesseries_3 1.50 9.20 24 1.00 908
#>
#> Approximate significance of GAM smooths:
-#> edf Ref.df Chi.sq p-value
-#> s(season) 3.36 6 21.1 0.0093 **
+#> edf Ref.df Chi.sq p-value
+#> s(season) 3.4 6 21.1 0.011 *
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Stan MCMC diagnostics:
#> n_eff / iter looks reasonable for all parameters
#> Rhat looks reasonable for all parameters
-#> 1 of 2000 iterations ended with a divergence (0.05%)
+#> 7 of 2000 iterations ended with a divergence (0.35%)
#> *Try running with larger adapt_delta to remove the divergences
#> 0 of 2000 iterations saturated the maximum tree depth of 12 (0%)
#> E-FMI indicated no pathological behavior
#>
-#> Samples were drawn using NUTS(diag_e) at Sat Jun 29 12:35:39 PM 2024.
+#> Samples were drawn using NUTS(diag_e) at Tue Sep 03 2:33:39 PM 2024.
#> For each parameter, n_eff is a crude measure of effective sample size,
#> and Rhat is the potential scale reduction factor on split MCMC chains
#> (at convergence, Rhat = 1)
-mcmc_plot(mod2, variable = c('alpha_gp'), regex = TRUE, type = 'areas')
mcmc_plot(mod2, variable = c('alpha_gp'), regex = TRUE, type = 'areas')
And now the length scale (\(\rho\)) parameters:
-mcmc_plot(mod2, variable = c('rho_gp'), regex = TRUE, type = 'areas')
mcmc_plot(mod2, variable = c('rho_gp'), regex = TRUE, type = 'areas')
We can again plot the nonlinear effects:
-conditional_effects(mod2, type = 'link')
conditional_effects(mod2, type = 'link')
The estimates for the temporal trends are fairly similar for the two models, but below we will see if they produce similar forecasts
@@ -374,45 +374,45 @@forec
#> ..$ series_3: int [1:25] 1 0 0 1 0 0 1 0 1 0 ...
#> $ test_times : int [1:25] 76 77 78 79 80 81 82 83 84 85 ...
#> $ hindcasts :List of 3
-#> ..$ series_1: num [1:2000, 1:75] 1 1 0 0 0 0 0 0 0 0 ...
+#> ..$ series_1: num [1:2000, 1:75] 0 0 0 1 0 1 0 0 0 0 ...
#> .. ..- 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:2000, 1:75] 0 0 0 0 0 0 0 0 0 0 ...
+#> ..$ series_2: num [1:2000, 1:75] 0 0 0 0 0 1 0 0 0 0 ...
#> .. ..- 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:2000, 1:75] 1 4 0 4 4 1 1 6 3 1 ...
+#> ..$ series_3: num [1:2000, 1:75] 3 2 2 0 1 3 2 3 1 3 ...
#> .. ..- 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: num [1:2000, 1:25] 0 1 0 0 0 1 1 0 0 3 ...
-#> ..$ series_2: num [1:2000, 1:25] 0 2 0 1 0 2 1 0 1 0 ...
-#> ..$ series_3: num [1:2000, 1:25] 1 8 4 2 2 1 2 0 2 0 ...
+#> ..$ series_1: num [1:2000, 1:25] 0 1 0 0 0 1 1 1 1 1 ...
+#> ..$ series_2: num [1:2000, 1:25] 0 0 1 1 0 0 0 1 0 0 ...
+#> ..$ series_3: num [1:2000, 1:25] 0 0 1 1 0 3 1 0 3 2 ...
#> - attr(*, "class")= chr "mvgam_forecast"
We can plot the forecasts for some series from each model using the
S3 plot
method for objects of this class:
plot(fc_mod1, series = 1)
#> Out of sample CRPS:
-#> 14.89051875
plot(fc_mod2, series = 1)
#> Out of sample DRPS:
-#> 10.84228725
plot(fc_mod1, series = 2)
#> Out of sample CRPS:
-#> 495050222726067
plot(fc_mod2, series = 2)
-#> Out of sample CRPS:
-#> 14.7121945
Clearly the two models do not produce equivalent forecasts. We will come back to scoring these forecasts in a moment.
@@ -429,8 +429,8 @@newdata
mod2
but include the testing data for automatic
forecasts:
-mod2 <- mvgam(y ~ s(season, bs = 'cc', k = 8) +
- gp(time, by = series, c = 5/4, k = 20,
+mod2 <- mvgam(y ~ s(season, bs = 'cc', k = 8) +
+ gp(time, by = series, c = 5/4, k = 20,
scale = FALSE),
knots = list(season = c(0.5, 12.5)),
trend_model = 'None',
@@ -447,7 +447,7 @@ Forecasting with newdata
plot(fc_mod2, series = 1)
#> Out of sample DRPS:
-#> 10.78167525
+#> 10.8005245
The returned list contains a data.frame
for each series
in the data that shows the CRPS score for each evaluation in the testing
data, along with some other useful information about the fit of the
@@ -527,31 +527,31 @@
We can also compare forecasts against out of sample observations using the Expected Log Predictive Density (ELPD; also known as the log score). The ELPD is a strictly proper scoring rule that can be @@ -563,31 +563,31 @@
Finally, when we have multiple time series it may also make sense to
use a multivariate proper scoring rule. mvgam
offers two
such options: the Energy score and the Variogram score. The first
@@ -612,7 +612,7 @@
The returned object still provides information on interval coverage @@ -621,31 +621,31 @@
energy_mod2$all_series
#> score eval_horizon score_type
-#> 1 0.7705198 1 energy
-#> 2 1.1330328 2 energy
-#> 3 1.2600785 3 energy
+#> 1 0.7546579 1 energy
+#> 2 1.1200630 2 energy
+#> 3 1.2447843 3 energy
#> 4 NA 4 energy
-#> 5 0.4427578 5 energy
-#> 6 1.8848308 6 energy
-#> 7 1.4186997 7 energy
-#> 8 0.7280518 8 energy
-#> 9 1.0467755 9 energy
+#> 5 0.4465348 5 energy
+#> 6 1.8231460 6 energy
+#> 7 1.4418019 7 energy
+#> 8 0.7172890 8 energy
+#> 9 1.0762943 9 energy
#> 10 NA 10 energy
-#> 11 1.4172423 11 energy
-#> 12 3.2326925 12 energy
-#> 13 1.5987732 13 energy
-#> 14 1.1798872 14 energy
-#> 15 1.0311968 15 energy
-#> 16 1.8261356 16 energy
+#> 11 1.4112423 11 energy
+#> 12 3.2385416 12 energy
+#> 13 1.5836460 13 energy
+#> 14 1.1953349 14 energy
+#> 15 1.0412578 15 energy
+#> 16 1.8348615 16 energy
#> 17 NA 17 energy
-#> 18 0.7170961 18 energy
-#> 19 0.8927311 19 energy
+#> 18 0.7142977 18 energy
+#> 19 0.9059773 19 energy
#> 20 NA 20 energy
-#> 21 1.0544501 21 energy
-#> 22 1.3280321 22 energy
+#> 21 1.1043397 21 energy
+#> 22 1.3292391 22 energy
#> 23 NA 23 energy
-#> 24 2.1843621 24 energy
-#> 25 1.2352041 25 energy
+#> 24 2.1419570 24 energy
+#> 25 1.2610880 25 energy
You can use your score(s) of choice to compare different models. For example, we can compute and plot the difference in CRPS scores for each series in data. Here, a negative value means the Gaussian Process model diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-13-1.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-13-1.png index a928b1f0..dba7cdfb 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-13-1.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-13-1.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-14-1.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-14-1.png index 91929bec..c4c70376 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-14-1.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-14-1.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-15-1.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-15-1.png index c68f404f..f81bd3e5 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-15-1.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-15-1.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-15-2.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-15-2.png index 1da70679..bf48bc83 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-15-2.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-15-2.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-1.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-1.png index 0199fa02..bce5f434 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-1.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-1.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-2.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-2.png index 29b6a888..f08e7dcb 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-2.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-2.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-3.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-3.png index ad12aeb3..dcc6592a 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-3.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-3.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-4.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-4.png index 2ae4de6d..61ac74bf 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-4.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-18-4.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-22-1.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-22-1.png index f5f5a83c..8347eca5 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-22-1.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-22-1.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-1.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-1.png index 5643424b..46bb5f6e 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-1.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-1.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-2.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-2.png index d73a0f58..51002835 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-2.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-2.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-3.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-3.png index 365642af..81d4de53 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-3.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-28-3.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-9-1.png index 146519aa..3e22fb75 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-9-1.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-9-2.png b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-9-2.png index 822eea46..275ed111 100644 Binary files a/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-9-2.png and b/docs/articles/forecast_evaluation_files/figure-html/unnamed-chunk-9-2.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index 9bfbcb90..7de0d62e 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -10,7 +10,7 @@ mvgam - 1.0.91 + 1.1.3