Title: | Allows Specifying a Bivariate VAR (Vector Autoregression) with Desired Spectral Characteristics |
---|---|
Description: | The spectral characteristics of a bivariate series (Marginal Spectra, Coherency- and Phase-Spectrum) determine whether there is a strong presence of short-, medium-, or long-term fluctuations (components of certain frequencies in the spectral representation of the series) in each one of them. These are induced by strong peaks of the marginal spectra of each series at the corresponding frequencies. The spectral characteristics also determine how strongly these short-, medium-, or long-term fluctuations of the two series are correlated between the two series. Information on this is provided by the Coherency spectrum at the corresponding frequencies. Finally, certain fluctuations of the two series may be lagged to each other. Information on this is provided by the Phase spectrum at the corresponding frequencies. The idea in this package is to define a VAR (Vector autoregression) model with desired spectral characteristics by specifying a number of polynomials, required to define the VAR. See Ioannidis(2007) <doi:10.1016/j.jspi.2005.12.013>. These are specified via their roots, instead of via their coefficients. This is an idea borrowed from the Time Series Library of R. Dahlhaus, where it is used for defining ARMA models for univariate time series. This way, one may e.g. specify a VAR inducing a strong presence of long-term fluctuations in series 1 and in series 2, which are weakly correlated, but lagged by a number of time units to each other, while short-term fluctuations in series 1 and in series 2, are strongly present only in one of the two series, while they are strongly correlated to each other between the two series. Simulation from such models allows studying the behavior of data-analysis tools, such as estimation of the spectra, under different circumstances, as e.g. peaks in the spectra, generating bias, induced by leakage. |
Authors: | Evangelos Ioannidis [cre, aut, cph], Panagiotis Papastamoulis [aut, cph] |
Maintainer: | Evangelos Ioannidis <[email protected]> |
License: | GPL-2 |
Version: | 1.0 |
Built: | 2025-03-09 06:37:02 UTC |
Source: | CRAN |
The spectral characteristics of a bivariate series (Marginal Spectra, Coherency- and Phase-Spectrum) determine whether there is a strong presence of short-, medium-, or long-term fluctuations (components of certain frequencies in the spectral representation of the series) in each one of them. These are induced by strong peaks of the marginal spectra of each series at the corresponding frequencies. The spectral characteristics also determine how strongly these short-, medium-, or long-term fluctuations of the two series are correlated between the two series. Information on this is provided by the Coherency spectrum at the corresponding frequencies. Finally, certain fluctuations of the two series may be lagged to each other. Information on this is provided by the Phase spectrum at the corresponding frequencies. The idea in this package is to define a VAR (Vector autoregression) model with desired spectral characteristics by specifying a number of polynomials, required to define the VAR. See Ioannidis(2007) <doi:10.1016/j.jspi.2005.12.013>. These are specified via their roots, instead of via their coefficients. This is an idea borrowed from the Time Series Library of R. Dahlhaus, where it is used for defining ARMA models for univariate time series. This way, one may e.g. specify a VAR inducing a strong presence of long-term fluctuations in series 1 and in series 2, which are weakly correlated, but lagged by a number of time units to each other, while short-term fluctuations in series 1 and in series 2, are strongly present only in one of the two series, while they are strongly correlated to each other between the two series. Simulation from such models allows studying the behavior of data-analysis tools, such as estimation of the spectra, under different circumstances, as e.g. peaks in the spectra, generating bias, induced by leakage.
The DESCRIPTION file:
Package: | VAR.spec |
Type: | Package |
Title: | Allows Specifying a Bivariate VAR (Vector Autoregression) with Desired Spectral Characteristics |
Version: | 1.0 |
Date: | 2024-06-7 |
Authors@R: | c( person("Evangelos", "Ioannidis", email = "[email protected]", role = c("cre", "aut", "cph") ), person("Panagiotis", "Papastamoulis", email = "[email protected]", role = c("aut", "cph"))) |
Description: | The spectral characteristics of a bivariate series (Marginal Spectra, Coherency- and Phase-Spectrum) determine whether there is a strong presence of short-, medium-, or long-term fluctuations (components of certain frequencies in the spectral representation of the series) in each one of them. These are induced by strong peaks of the marginal spectra of each series at the corresponding frequencies. The spectral characteristics also determine how strongly these short-, medium-, or long-term fluctuations of the two series are correlated between the two series. Information on this is provided by the Coherency spectrum at the corresponding frequencies. Finally, certain fluctuations of the two series may be lagged to each other. Information on this is provided by the Phase spectrum at the corresponding frequencies. The idea in this package is to define a VAR (Vector autoregression) model with desired spectral characteristics by specifying a number of polynomials, required to define the VAR. See Ioannidis(2007) <doi:10.1016/j.jspi.2005.12.013>. These are specified via their roots, instead of via their coefficients. This is an idea borrowed from the Time Series Library of R. Dahlhaus, where it is used for defining ARMA models for univariate time series. This way, one may e.g. specify a VAR inducing a strong presence of long-term fluctuations in series 1 and in series 2, which are weakly correlated, but lagged by a number of time units to each other, while short-term fluctuations in series 1 and in series 2, are strongly present only in one of the two series, while they are strongly correlated to each other between the two series. Simulation from such models allows studying the behavior of data-analysis tools, such as estimation of the spectra, under different circumstances, as e.g. peaks in the spectra, generating bias, induced by leakage. |
License: | GPL-2 |
LazyData: | true |
NeedsCompilation: | no |
Packaged: | 2024-06-10 08:36:15 UTC; Dell |
Author: | Evangelos Ioannidis [cre, aut, cph], Panagiotis Papastamoulis [aut, cph] |
Maintainer: | Evangelos Ioannidis <[email protected]> |
Depends: | R (>= 3.5.0) |
Repository: | CRAN |
Date/Publication: | 2024-06-11 11:30:05 UTC |
Index of help topics:
Init.var Initializes an object of class 'var' VAR.inv.roots.from.det.cross An example 'data.frame' defining a VAR (Vector autoregression) model. VAR.inv.roots.from.eta.ksi.zeta An example 'data.frame' defining a VAR model. VAR.spec-package Allows Specifying a Bivariate VAR (Vector Autoregression) with Desired Spectral Characteristics calc.VAR.spec.from.coefs Calculates the spectral matrix of a multivariate VAR (Vector autoregression) model. calculate.VAR Attempts to define a bivariate VAR (Vector autoregression) model. plot_VAR.Phase.details Plots details related to the Phase spectrum of a bivariate VAR (Vector autoregression) model. plot_VAR.spectra Plots spectra of a bivariate VAR (Vector autoregression) model. simulate.VAR Simulates a bivariate series from a bivariate VAR (Vector autoregression) model.
The specification of the VAR (Vector autoregression) model is based on the following fact (see Ioannidis (2007))
<doi:10.1016/j.jspi.2005.12.013>:
For any four complex polynomials of degree
and
of degree
, satisfying
EQ(*)
on , there exists a bivariate VAR(p) with marginal spectra
and cross-spectrum
where . The squared Coherency is then given by
The idea in this package is to define the necessary polynomials by specifying their roots, instead of their coefficients. This is an idea borrowed from the Time Series Library of R. Dahlhaus, where it is used for defining ARMA models for univariate time series.
Moreover, the package allows the user to specify only some of the roots of and
, while it attempts to find further non-specified roots in a way such that EQ(*) is satisfied.
By specifying certain roots of and
one can induce desired features in the spectra and in the series. For example,
if one wishes a strong presence of frequency components in series 1,
there should be a root with modulus close to 1 and angle equal to
, the multiplicity of which for
is higher than its multiplicity for
, forcing the spectrum of series 1 to have a peak at
.
If the frequency--components should be strongly correlated between series 1 and series 2, the multiplicity of this root for
should be higher than its multiplicity for
, forcing the Coherency at
close to 1.
Required polynomials (see argument calc.method
of function calculate.VAR
and related Details
) are first passed to function Init.var
, via a data.frame
or a text file, which contains the multiplicities of desired roots (rows) for each required polynomial (columns).
After calling Init.var
, function calculate.VAR
must be called, which attempts to find a VAR model which is compatible with the polynomials specified in its attribute inv.roots
, by making necessary adjustments, calculates its spectra, coefficients and order, makes the necessary checks and plots it's spectra. Then, one can simulate from the specified model calling simulate.VAR
.
Evangelos Ioannidis [cre, aut, cph], Panagiotis Papastamoulis [aut, cph]
Maintainer: Evangelos Ioannidis <[email protected]>
Ioannidis, E. E. (2007). Spectra of bivariate VAR(p) models. Journal of Statistical Planning and Inference 137(2), 554-566.
Ioannidis, E. E. and Chronis, G. A. (2005). Extreme spectra of VAR models and orders of near-cointegration. J. Time Ser. Anal. 26, 399-421.
Init.var
, calculate.VAR
, simulate.VAR
,
plot_VAR.spectra
, plot_VAR.Phase.details
,
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR (a.var = my.var, calc.method="from.det.cross", plot.spectra=TRUE,suppr.spec.check.warn=TRUE) print(my.var$validity.msg)
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR (a.var = my.var, calc.method="from.det.cross", plot.spectra=TRUE,suppr.spec.check.warn=TRUE) print(my.var$validity.msg)
Calculates the spectral matrix for all grid points for any (multivariate) VAR model, represented by an object of class var
, with specified coefficients (in attribute ar.list
).
calc.VAR.spec.from.coefs(a.var)
calc.VAR.spec.from.coefs(a.var)
a.var |
an object of class |
Is being called in calculate.VAR
, so there is no need to call it again after calculate.VAR
has been called. Can also be used to calculate the spectral matrix of a VAR model which has been fitted to data, e.g. using function ar
. See Brockwell and Davis, 1990, Example 11.8.1, Hannan, 1970, Chapter II, Section 5.iv or Brillinger, 2001, Sections 2.8 and 2.9.
Returns the object of class var
after having calculated and set the following attributes:
freq |
A one dimensional array of length |
spec |
A three dimensional array ( |
Brillinger, D.R. (2001). Time Series: Data Analysis and Theory, second ed. Classics in Applied Mathematics, vol. 36. SIAM, Philadelphia.
Brockwell, P. J., Davis, R. A. (1990). Time Series: Theory and Methods, second ed. Springer, New York.
Hannan, E. J. (1970). Multiple Time Series. Wiley, New York.
VAR.spec-package
,Init.var
, calculate.VAR
, simulate.VAR
,
plot_VAR.spectra
, plot_VAR.Phase.details
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR(a.var=my.var,calc.method="from.det.cross", suppr.spec.check.warn=TRUE) print(my.var$validity.msg) my.sample <-simulate.VAR(a.var=my.var, sample.size=250, burn.in = 500) est.var<-list() est.var$ar.outp <- ar(x=my.sample, aic=FALSE, order.max=6, demean=FALSE, method="ols", series=c("ser1","ser2")) est.var$label <-"MY VAR(6)" est.var$order<-dim(est.var$ar.outp$ar)[1] est.var$ar.list$ar <- est.var$ar.outp$ar est.var$ar.list$var.pred <- est.var$ar.outp$var.pred est.var$grid <- 501 est.var <- calc.VAR.spec.from.coefs(est.var) plot_VAR.spectra(a.var=est.var,both=FALSE)
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR(a.var=my.var,calc.method="from.det.cross", suppr.spec.check.warn=TRUE) print(my.var$validity.msg) my.sample <-simulate.VAR(a.var=my.var, sample.size=250, burn.in = 500) est.var<-list() est.var$ar.outp <- ar(x=my.sample, aic=FALSE, order.max=6, demean=FALSE, method="ols", series=c("ser1","ser2")) est.var$label <-"MY VAR(6)" est.var$order<-dim(est.var$ar.outp$ar)[1] est.var$ar.list$ar <- est.var$ar.outp$ar est.var$ar.list$var.pred <- est.var$ar.outp$var.pred est.var$grid <- 501 est.var <- calc.VAR.spec.from.coefs(est.var) plot_VAR.spectra(a.var=est.var,both=FALSE)
Attempts to find a VAR model which is compatible with the polynomials specified in its attribute inv.roots
, makes necessary adjustments, calculates its spectra, coefficients and order, makes the necessary checks and plots the spectra. Finding a VAR model involves finding complex polynomials and
, satisfying
EQ(*):
on . If
calculate.VAR
is successful in finding such polynomials, there exists a bivariate VAR(p) model with marginal spectra
and cross-spectrum
where . The squared Coherency is then given by
calculate.VAR(a.var, calc.method = "from.det.cross", M.fact = 1.1, plot.spectra = TRUE,suppr.spec.check.warn=FALSE)
calculate.VAR(a.var, calc.method = "from.det.cross", M.fact = 1.1, plot.spectra = TRUE,suppr.spec.check.warn=FALSE)
a.var |
An object of class |
calc.method |
One of 'from.det.cross' or 'from.eta.ksi.zeta'. See details for further explanations. |
M.fact |
Numeric. A factor >1, by which the |
plot.spectra |
Logical. If TRUE, the marginal spectra, Coherency and Phase spectra will be plotted. |
suppr.spec.check.warn |
Logical. If TRUE, warnings on whether spectra obtained directly from |
In order to define a VAR model, one seeks to define and
, such that EQ(*) holds. There are two ways implemented for doing so, which are specified by argument
calc.method
:
calc.method
= 'from.det.cross'. (See Ioannidis (2007), Proposition 2). One must first specify the roots for and
. They fix these two polynomials, which will not be modified during the calculation. One may also specify some roots for
and
. If these two latter are compatible with EQ(*) they will be kept. If not, they may be modified during the calculation. Further roots may be added by
compute.VAR
during the calculation to to ensure that EQ(*) holds. All changes are recorded in attribute
inv.roots
. If the user wishes some of the roots of to be rather added to
, he may do so by editing attribute
inv.roots
after running the function once, by increasing the multiplicity of the root for and decreasing it by the same amount for
, and then, re-running the function. With the option
calc.method
= 'from.det.cross' one has more direct control over peaks for the marginal spectra (via and
) and the Coherency being close to 0 or 1 (via
and
), as well as the Phase spectrum, i.e., the lag-/lead- structure between the two series (via
).
calc.method
= 'from.eta.ksi.zeta'. (See Ioannidis (2007), Proposition 1). One must specify the roots of and
. These fix
and
where equals
M.fact
* and
is the maximal common divisor of
and
. Then,
is automatically determined so as that EQ(*) is satisfied. The result is that marginal spectra are given by
and the squared Coherency is given by
With the option calc.method
= 'from.eta.ksi.zeta' one has more direct control over peaks (via ) and zeroes (via
) of the marginal spectra and, partially, over the Coherency (via
and
), but not of the Phase spectrum. However, for certain aspects of the Coherency, a more direct control over the relation of
and
would be required, which is not available with this option. For example, with this option, it is not possible to set the multiplicity of a root to be higher for
than for
.
An object of class var, basically a list including elements:
grid |
The number of equidistant gridpoints in |
p.max.init |
An initial limitation on the order of the VAR model. |
inv.roots |
A |
niter |
An integer specifying the maximal number of iterations for the Innovations algorithm. |
eps.max.for.UIA |
Numeric close to 0. Specifies the threshold for the relative increase in precision achieved at a step of the Innovations algorithm, for accepting that the algorithm has converged. |
eps.for.roots |
Numeric close to 0. A threshold for considering two roots as identical, if a) the inverses of their radii and b) their angles (in their polar representation) differ by less than this threshold. |
eps.for.spectra |
Numeric close to 0. A threshold for checking the validity of the calculation of the VAR model. It's spectra are calculated on the basis of the polynomials used to specify the VAR model in |
validity.msg |
A message containing more precise information on a) the convergence of the Innovations Algorithm and b) on the maximal difference between the spectra of the VAR model as calculated on the basis of the polynomials used to specify it and the spectra obtained on the basis of the VAR model's coefficients. The message should be printed after each call to |
order |
(Integer) The final order of the VAR model. |
ar.list |
A list with entries (calculated solving the Yule-Walker equations):
|
cov.1 , cov.2 , cov.cross , cov.cross.neg
|
Three one dimensional arrays of length |
freq |
A one dimensional array of length |
spec |
A three dimensional array ( |
spec.1 , spec.2
|
Two one dimensional arrays of length |
Coher |
A one dimensional array of length |
Phase |
A one dimensional array of length |
Phase.div.freq , group.delay
|
Two one dimensional arrays of length |
det , cross , chi.1 , chi.2 , ksi.1 , ksi.2 , eta.1 , eta.2 , zeta
|
Contain detailed information on the respective polynomials (the last five only if
|
calculate.VAR
performs a check on the validity of the output and stores relevant information in attribute validity.msg
. There are certain reasons for which the output may not be valid: First, the calculation involves numerical approximations; the relevant algorithms may have not achieved convergence to the desired precision. Second, there may be features in the spectra, which cannot be well represented by a VAR model, resulting in polynomials and
not satisfying EQ(*). Thus, it is imperative to check a) the validity of EQ(*). It is also important to check b) that the spectra obtained directly from
and
(in
spec.1, spec.2, Coher, Phase
) coincide with the spectra (in spec
) obtained from the coefficients of the VAR model (in ar.list
). The checks performed by calculate.VAR
concern exactly the checks under a) and b): the maximum absolute difference between the relevant quantities (in log scale, where appropriate) is passed in validity.msg
. Moreover, warnings are written out to the console if the Innovations algorithm did not converge or if any of the quantities in 'b' exceeds eps.for.spectra
, provided that suppr.spec.check.warn
=FALSE. The same check is conducted visually if plot.spectra
=TRUE: each spectrum is calculated and plotted according to both methods. The two should coincide.
The option method
='from.det.cross' seems generally numerically more stable than the option
method
='from.eta.ksi.zeta'.
Suggestions on how to obtain desired spectral characteristics:
Let , with
close to 1.
For a polynomial
denote by
the multiplicity of
as root of
.
To obtain
a peak in
with method
='from.det.cross': choose .
with method
='from.eta.ksi.zeta': choose .
a trough in
with method
='from.eta.ksi.zeta': choose .
a close to 1
with method
='from.det.cross': choose .
with method
='from.eta.ksi.zeta': choose .
a close to 0
with method
='from.det.cross': choose .
with method
='from.eta.ksi.zeta': choose .
Ioannidis, E. E. (2007). Spectra of bivariate VAR(p) models. Journal of Statistical Planning and Inference 137(2), 554-566.
Ioannidis, E. E. and Chronis, G. A. (2005). Extreme spectra of VAR models and orders of near-cointegration. J. Time Ser. Anal. 26, 399-421.
VAR.spec-package
,Init.var
, simulate.VAR
,
plot_VAR.spectra
, plot_VAR.Phase.details
,
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR (a.var = my.var, calc.method="from.det.cross", plot.spectra=TRUE,suppr.spec.check.warn=TRUE) print(my.var$validity.msg)
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR (a.var = my.var, calc.method="from.det.cross", plot.spectra=TRUE,suppr.spec.check.warn=TRUE) print(my.var$validity.msg)
var
Initializes an object of class var
, representing a VAR (Vector autoregression) model, sets some of its parameters and reads the specification of certain polynomials which determine the VAR model from a data.frame
or from a tab-delimited text file (, which is converted to a data.frame
). In this data.frame
each polynomial is specified via it's (complex) roots and constant. If no such text file or data.frame
is specified, an appropriate default data.frame
is created, which can then be modified by the user.
Init.var(grid = 1001, order.max.init = 10, inv.roots.def = NULL, a.niter = 5000, a.eps.max.for.UIA = 1e-10, a.eps.for.roots = 1e-05,a.eps.for.spectra=1E-4)
Init.var(grid = 1001, order.max.init = 10, inv.roots.def = NULL, a.niter = 5000, a.eps.max.for.UIA = 1e-10, a.eps.for.roots = 1e-05,a.eps.for.spectra=1E-4)
grid |
An integer specifying the number of equidistant gridpoints in |
order.max.init |
An integer providing an initial limitation on the order of the VAR model. The degrees of the polynomials specified in the |
inv.roots.def |
Either NULL or a |
a.niter |
An integer specifying the maximal number of iterations for the Innovations algorithm. |
a.eps.max.for.UIA |
Numeric close to 0. Specifies the threshold for the relative increase in precision achieved at a step of the Innovations algorithm, for accepting that the algorithm has converged. |
a.eps.for.roots |
Numeric close to 0. A threshold for considering two roots as identical, if a) the inverses of their radii and b) their angles (in their polar representation) differ by less than this threshold. |
a.eps.for.spectra |
Numeric close to 0. A threshold for checking the validity of the calculation of the VAR model. It's spectra are calculated on the basis of the polynomials used to specify the VAR model in |
The text file [/ data.frame
] passed in argument inv.roots.def
should have a specific structure:
The first row of the file (headers) [/ names of columns of the data.frame
] should be 'radius angle det cross chi.1 chi.2 chi.1.prod.2 ma.1 ma.2 eta.1 eta.2 ksi.1 ksi.2 ksi.c zeta'.
The second row of the file [/ first row-'observation' in the data.frame] contains the constants of the polynomials, usually set initially to 1, while the first two entries, corresponding to columns radius and angle, are set to '#NA' [/ 'NA'].
Subsequent rows, containing each one the specification of a root and the multiplicity of this root for each relevant polynomial, should have the following entries: The first entry is the inverse of its modulus (radius). For all polynomials, except for cross
, this should be in . The second entry is it's argument (angle). This should be a figure in
. Complex conjugates for each non-real root will be automatically added, in order to ensure real coefficients of the polynomials. Subsequent entries in the row are non-negative integers determining the multiplicity of the given root for the polynomial corresponding to the column of the entry. Not all polynomials need to be specified (see parameter
calc.method
in function calculate.VAR
). Non relevant polynomials should have '0' as entry for their multiplicity of the root.
Subsequent rows containing no specified roots should have the following structure: the first two entries, corresponding to radius and angle, should equal '#NA' [/ 'NA']. The rest of the row should be filled with '0'. The total number of rows should be at least 6*order.max.init
+2 for the file (, including headers) [/ or 6*order.max.init
+1 for the data.frame
].
Two example text files of the appropriate structure, VAR.inv.roots.from.det.cross.txt
and VAR.inv.roots.from.eta.ksi.zeta.txt
may be found in the extdata
folder of the package. A path to them may be obtained via
fpath<-system.file("extdata","text.file",package="VAR.spec").
The corresponding example data.frames
are also directly accessible to the user as
VAR.inv.roots.from.det.cross
and VAR.inv.roots.from.eta.ksi.zeta
.
An object of class var, basically a list including elements:
grid |
The integer contained in argument |
p.max.init |
The integer contained in argument |
inv.roots |
A |
niter |
The integer contained in argument |
eps.max.for.UIA |
Numeric close to 0. Specifies the threshold for the relative increase in precision achieved at a step of the Innovations algorithm, for accepting that the algorithm has converged. |
eps.for.roots |
Numeric close to 0. A threshold for considering two roots as identical, if a) the inverses of their radii and b) their angles (in their polar representation) differ by less than this threshold. |
eps.for.spectra |
Numeric close to 0. A threshold for checking the validity of the calculation of the VAR model. It's spectra are calculated on the basis of the polynomials used to specify the VAR model in |
VAR.spec-package
, calculate.VAR
, simulate.VAR
,
plot_VAR.spectra
, plot_VAR.Phase.details
,
my.var <- Init.var(grid=201, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var$inv.roots
my.var <- Init.var(grid=201, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var$inv.roots
Plots in a 2x2 layout the Phase spectrum of a VAR model for a bivariate series, represented by an object of class var
, the Phase spectrum divided by frequency -which gives the lag-/lead-structure between the two series in units of time –, the derivative of the Phase spectrum with respect to frequency -also known as the group-delay–, and the Coherency spectrum of the VAR model.
plot_VAR.Phase.details(a.var)
plot_VAR.Phase.details(a.var)
a.var |
An object of class |
No return value, called for side effects.
VAR.spec-package
,Init.var
, calculate.VAR
,
simulate.VAR
, plot_VAR.spectra
,
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR(a.var=my.var,calc.method="from.det.cross", suppr.spec.check.warn=TRUE) print(my.var$validity.msg) plot_VAR.Phase.details (a.var=my.var)
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR(a.var=my.var,calc.method="from.det.cross", suppr.spec.check.warn=TRUE) print(my.var$validity.msg) plot_VAR.Phase.details (a.var=my.var)
Plots in a 2x2 layout the marginal spectra, the squared Coherency spectrum and the Phase spectrum of a VAR model, represented by an object of class var
. If both
=TRUE, each one is calculated (and plotted) in two ways: once directly from , and once from the coefficients in
ar.list
. For each quantity the values from the two ways of calculation should coincide, if the calculation of the VAR model undertaken in calculate.VAR
was correct. If both
=FALSE, only the calculation based on the coefficients in attribute ar.list
is plotted.
plot_VAR.spectra(a.var, both = TRUE)
plot_VAR.spectra(a.var, both = TRUE)
a.var |
An object of class |
both |
Logical. If TRUE, each quantity will be plotted calculated in two ways: once directly from |
If both
=TRUE the var should have been obtained from calculate.VAR
. If both
=FALSE only the attributes grid, freq
and spec
are required. Thus, it can also be used to plot spectra of a VAR model fitted to a bivariate series, e.g. using function ar
, the spectra of which have previously been calculated by a call to calc.VAR.spec.from.coefs
.
No return value, called for side effects.
VAR.spec-package
,Init.var
, calculate.VAR
,
simulate.VAR
, plot_VAR.Phase.details
,
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR(a.var=my.var,calc.method="from.det.cross", suppr.spec.check.warn=TRUE) print(my.var$validity.msg) my.var <- calc.VAR.spec.from.coefs(a.var=my.var) plot_VAR.spectra(a.var=my.var)
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR(a.var=my.var,calc.method="from.det.cross", suppr.spec.check.warn=TRUE) print(my.var$validity.msg) my.var <- calc.VAR.spec.from.coefs(a.var=my.var) plot_VAR.spectra(a.var=my.var)
Simulates a Gaussian bivariate series from a VAR model, described by an object of class var
.
simulate.VAR(a.var, sample.size, burn.in = 1000)
simulate.VAR(a.var, sample.size, burn.in = 1000)
a.var |
An object of class |
sample.size |
Integer. The size of the bivariate sample to be generated. |
burn.in |
Integer. The number of initial observations to be discarded. The bivariate series is simulated by iterating the VAR recursion, starting with white noise (with the covariance structure of the innovations, given in |
A numeric array of dimensions sample.size
x2, the bivariate sample series simulated from the VAR model.
VAR.spec-package
, Init.var
, calculate.VAR
,
plot_VAR.spectra
, plot_VAR.Phase.details
,
calc.VAR.spec.from.coefs
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR(a.var=my.var,calc.method="from.det.cross", suppr.spec.check.warn=TRUE) print(my.var$validity.msg) my.sample <-simulate.VAR(a.var=my.var, sample.size=250, burn.in = 500)
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=NULL) my.var$inv.roots[2,]<- c(0.98,0.017261,2,3,1,1,2, rep(0,8)) my.var$inv.roots[3,]<- c(0.92,0.897598,2,1,1,1,2, rep(0,8)) my.var$inv.roots[4,]<- c(0.98,1.795196,1,1,0,1,1, rep(0,8)) my.var <- calculate.VAR(a.var=my.var,calc.method="from.det.cross", suppr.spec.check.warn=TRUE) print(my.var$validity.msg) my.sample <-simulate.VAR(a.var=my.var, sample.size=250, burn.in = 500)
data.frame
defining a VAR (Vector autoregression) model.
An example data.frame
to be used for argument inv.roots.def
of function Init.var
, when subsequently argument method
of function calculate.VAR
is set to "from.det.cross".
VAR.inv.roots.from.det.cross
VAR.inv.roots.from.det.cross
A data.frame
containing 3 roots (rows) and their multiplicities for the polynomials ,
and
, as well as their constants in the first row.
Init.var
, calculate.VAR
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=VAR.inv.roots.from.det.cross) my.var <- calculate.VAR(a.var=my.var,calc.method="from.det.cross", suppr.spec.check.warn=TRUE) print(my.var$validity.msg)
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=VAR.inv.roots.from.det.cross) my.var <- calculate.VAR(a.var=my.var,calc.method="from.det.cross", suppr.spec.check.warn=TRUE) print(my.var$validity.msg)
data.frame
defining a VAR model.
An example data.frame
to be used for argument inv.roots.def
of function Init.var
, when subsequently argument method
of function calculate.VAR
is set to "from.eta.ksi.zeta".
VAR.inv.roots.from.eta.ksi.zeta
VAR.inv.roots.from.eta.ksi.zeta
A data.frame
containing 3 roots (rows) and their multiplicities for the polynomials ,
and
, as well as their constants in the first row.
Init.var
, calculate.VAR
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=VAR.inv.roots.from.eta.ksi.zeta) my.var <- calculate.VAR(a.var=my.var,calc.method="from.eta.ksi.zeta")
my.var <- Init.var(grid=501, order.max.init=10, inv.roots.def=VAR.inv.roots.from.eta.ksi.zeta) my.var <- calculate.VAR(a.var=my.var,calc.method="from.eta.ksi.zeta")