Compute forecast error variance decompositions from
+mvgam models with Vector Autoregressive dynamics
+
+
+
+
Usage
+
fevd(object, ...)
+
+# S3 method for mvgam
+fevd(object, h =1, ...)
+
+
+
+
Arguments
+
object
+
list object of class mvgam resulting from a call to mvgam()
+that used a Vector Autoregressive latent process model (either as VAR(cor = FALSE) or
+VAR(cor = TRUE))
+
+
+
...
+
ignored
+
+
+
h
+
Positive integer specifying the forecast horizon over which to calculate
+the IRF
+
+
+
+
Value
+
+
+
An object of class mvgam_fevd containing the posterior forecast error
+variance decompositions. This
+object can be used with the supplied S3 functions plot
+
+
+
+
+
Details
+
A forecast error variance decomposition is useful for quantifying the amount
+of information each series that in a Vector Autoregression contributes to the forecast
+distributions of the other series in the autoregression. This function calculates
+the forecast error variance decomposition using the
+orthogonalised impulse response coefficient matrices \(\Psi_h\), which can be used to
+quantify the contribution of series \(j\) to the
+h-step forecast error variance of series \(k\):
+$$
+\sigma_k^2(h) = \sum_{j=1}^K(\psi_{kj, 0}^2 + \ldots + \psi_{kj,
+h-1}^2) \quad
+$$
+If the orthogonalised impulse reponses \((\psi_{kj, 0}^2 + \ldots + \psi_{kj, h-1}^2)\)
+are divided by the variance of the forecast error \(\sigma_k^2(h)\),
+this yields an interpretable percentage representing how much of the
+forecast error variance for \(k\) can be explained by an exogenous shock to \(j\).
+
+
+
References
+
Lütkepohl, H (2006).
+New Introduction to Multiple Time Series Analysis. Springer, New York.
# \donttest{
+# Simulate some time series that follow a latent VAR(1) process
+simdat<-sim_mvgam(family =gaussian(),
+ n_series =4,
+ trend_model =VAR(cor =TRUE),
+ prop_trend =1)
+plot_mvgam_series(data =simdat$data_train, series ='all')
+
+
+# Fit a model that uses a latent VAR(1)
+mod<-mvgam(y~-1,
+ trend_formula =~1,
+ trend_model =VAR(cor =TRUE),
+ family =gaussian(),
+ data =simdat$data_train,
+ 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/Rtmpm6CzOV/model-6f604d042ef7.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
+
+# Calulate forecast error variance decompositions for each series
+fevds<-fevd(mod, h =12)
+
+# Plot them
+plot(fevds)
+
+# }
+
Plot forecast error variance decompositions from an mvgam_fevd object
+This function takes an mvgam_fevd object and produces
+a plot of the posterior median contributions to forecast variance for each series
+in the fitted Vector Autoregression
+
+
+
+
+
+
+
diff --git a/docs/reference/plot.mvgam_fevd.html b/docs/reference/plot.mvgam_fevd.html
new file mode 100644
index 00000000..b5549e85
--- /dev/null
+++ b/docs/reference/plot.mvgam_fevd.html
@@ -0,0 +1,129 @@
+
+Plot forecast error variance decompositions from an mvgam_fevd object
+This function takes an mvgam_fevd object and produces
+a plot of the posterior median contributions to forecast variance for each series
+in the fitted Vector Autoregression — plot.mvgam_fevd • mvgam
+ Skip to contents
+
+
+
+
+
+
Plot forecast error variance decompositions from an mvgam_fevd object
+This function takes an mvgam_fevd object and produces
+a plot of the posterior median contributions to forecast variance for each series
+in the fitted Vector Autoregression
Plot forecast error variance decompositions from an mvgam_fevd object
+This function takes an mvgam_fevd object and produces
+a plot of the posterior median contributions to forecast variance for each series
+in the fitted Vector Autoregression
A ggplot object,
+which can be further customized using the ggplot2 package
+
+
+
Author
+
Nicholas J Clark
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/man/fevd.mvgam.Rd b/man/fevd.mvgam.Rd
new file mode 100644
index 00000000..f39e47df
--- /dev/null
+++ b/man/fevd.mvgam.Rd
@@ -0,0 +1,81 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/fevd.mvgam.R
+\name{fevd.mvgam}
+\alias{fevd.mvgam}
+\alias{fevd}
+\title{Calculate latent VAR forecast error variance decompositions}
+\usage{
+fevd(object, ...)
+
+\method{fevd}{mvgam}(object, h = 1, ...)
+}
+\arguments{
+\item{object}{\code{list} object of class \code{mvgam} resulting from a call to \code{\link[=mvgam]{mvgam()}}
+that used a Vector Autoregressive latent process model (either as \code{VAR(cor = FALSE)} or
+\code{VAR(cor = TRUE)})}
+
+\item{...}{ignored}
+
+\item{h}{Positive \code{integer} specifying the forecast horizon over which to calculate
+the IRF}
+}
+\value{
+An object of class \code{mvgam_fevd} containing the posterior forecast error
+variance decompositions. This
+object can be used with the supplied S3 functions \code{plot}
+}
+\description{
+Compute forecast error variance decompositions from
+\code{mvgam} models with Vector Autoregressive dynamics
+}
+\details{
+A forecast error variance decomposition is useful for quantifying the amount
+of information each series that in a Vector Autoregression contributes to the forecast
+distributions of the other series in the autoregression. This function calculates
+the forecast error variance decomposition using the
+orthogonalised impulse response coefficient matrices \eqn{\Psi_h}, which can be used to
+quantify the contribution of series \eqn{j} to the
+h-step forecast error variance of series \eqn{k}:
+\deqn{
+\sigma_k^2(h) = \sum_{j=1}^K(\psi_{kj, 0}^2 + \ldots + \psi_{kj,
+h-1}^2) \quad
+}
+If the orthogonalised impulse reponses \eqn{(\psi_{kj, 0}^2 + \ldots + \psi_{kj, h-1}^2)}
+are divided by the variance of the forecast error \eqn{\sigma_k^2(h)},
+this yields an interpretable percentage representing how much of the
+forecast error variance for \eqn{k} can be explained by an exogenous shock to \eqn{j}.
+}
+\examples{
+\donttest{
+# Simulate some time series that follow a latent VAR(1) process
+simdat <- sim_mvgam(family = gaussian(),
+ n_series = 4,
+ trend_model = VAR(cor = TRUE),
+ prop_trend = 1)
+plot_mvgam_series(data = simdat$data_train, series = 'all')
+
+# Fit a model that uses a latent VAR(1)
+mod <- mvgam(y ~ -1,
+ trend_formula = ~ 1,
+ trend_model = VAR(cor = TRUE),
+ family = gaussian(),
+ data = simdat$data_train,
+ silent = 2)
+
+# Calulate forecast error variance decompositions for each series
+fevds <- fevd(mod, h = 12)
+
+# Plot them
+plot(fevds)
+}
+}
+\references{
+Lütkepohl, H (2006).
+New Introduction to Multiple Time Series Analysis. Springer, New York.
+}
+\seealso{
+\code{\link{VAR}}, \code{\link{plot.mvgam_irf}}, \code{\link{stability}}
+}
+\author{
+Nicholas J Clark
+}
diff --git a/man/mvgam_fevd-class.Rd b/man/mvgam_fevd-class.Rd
new file mode 100644
index 00000000..c16cd329
--- /dev/null
+++ b/man/mvgam_fevd-class.Rd
@@ -0,0 +1,20 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/mvgam_fevd-class.R
+\name{mvgam_fevd-class}
+\alias{mvgam_fevd-class}
+\title{\code{mvgam_fevd} object description}
+\description{
+A \code{mvgam_fevd} object returned by function \code{\link{fevd}}.
+Run \code{methods(class = "mvgam_fevd")} to see an overview of available methods.
+}
+\details{
+A \code{mvgam_fevd} object contains a list of posterior forecast
+error variance decompositions, each stored as
+its own list
+}
+\seealso{
+\link{mvgam}, \link{VAR}
+}
+\author{
+Nicholas J Clark
+}
diff --git a/man/plot.mvgam_fevd.Rd b/man/plot.mvgam_fevd.Rd
new file mode 100644
index 00000000..69ffd5fd
--- /dev/null
+++ b/man/plot.mvgam_fevd.Rd
@@ -0,0 +1,29 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/mvgam_fevd-class.R
+\name{plot.mvgam_fevd}
+\alias{plot.mvgam_fevd}
+\title{Plot forecast error variance decompositions from an mvgam_fevd object
+This function takes an \code{mvgam_fevd} object and produces
+a plot of the posterior median contributions to forecast variance for each series
+in the fitted Vector Autoregression}
+\usage{
+\method{plot}{mvgam_fevd}(x, ..)
+}
+\arguments{
+\item{x}{\code{list} object of class \code{mvgam_fevd}. See \code{\link[=fevd]{fevd()}}}
+
+\item{...}{ignored}
+}
+\value{
+A \code{\link[ggplot2]{ggplot}} object,
+which can be further customized using the \pkg{ggplot2} package
+}
+\description{
+Plot forecast error variance decompositions from an mvgam_fevd object
+This function takes an \code{mvgam_fevd} object and produces
+a plot of the posterior median contributions to forecast variance for each series
+in the fitted Vector Autoregression
+}
+\author{
+Nicholas J Clark
+}
diff --git a/misc/mvgam_cheatsheet.png b/misc/mvgam_cheatsheet.png
index f3c4f92a..8ed6ec21 100644
Binary files a/misc/mvgam_cheatsheet.png and b/misc/mvgam_cheatsheet.png differ
diff --git a/src/RcppExports.o b/src/RcppExports.o
index 03b01119..e8dd19f0 100644
Binary files a/src/RcppExports.o and b/src/RcppExports.o differ
diff --git a/src/mvgam.dll b/src/mvgam.dll
index 357430f9..4be42be1 100644
Binary files a/src/mvgam.dll and b/src/mvgam.dll differ
diff --git a/src/trend_funs.o b/src/trend_funs.o
index 1c0d5a8f..917270cf 100644
Binary files a/src/trend_funs.o and b/src/trend_funs.o differ
diff --git a/tests/testthat/test-example_processing.R b/tests/testthat/test-example_processing.R
index 39167c7b..88143e78 100644
--- a/tests/testthat/test-example_processing.R
+++ b/tests/testthat/test-example_processing.R
@@ -57,6 +57,13 @@ test_that("irf() gives correct outputs", {
expect_no_error(plot(irfs))
})
+test_that("fevd() gives correct outputs", {
+ fevds <- fevd(mvgam:::mvgam_example3, h = 12)
+ expect_true(length(fevds) == 30)
+ expect_true(NROW(fevds[[1]]$process_1) == 12)
+ expect_no_error(plot(fevds))
+})
+
test_that("variable extraction works correctly", {
expect_true(inherits(as.matrix(mvgam:::mvgam_example4,
'A', regex = TRUE),