Learn R Programming

⚠️There's a newer version (2.2.0) of this package.Take me there.

gmvarkit

The goal of gmvarkit is to provide tools to analyse the Gaussian mixture vector autoregressive (GMVAR) model. gmvarkit provides functions for unconstrained and constrained maximum likelihood estimation of the model parameters, quantile residual based model diagnostics, simulation from the processes, and forecasting.

Installation

You can install the released version of gmvarkit from CRAN with:

install.packages("gmvarkit")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("cran/gmvarkit")

Example

Simple example

This is a basic example how to estimate a GMVAR model to data. The example data is the same that is used by Kalliovirta et al. (2016) in their paper introducing the GMVAR model. The estimation process is computationally demanding and takes advantage of parallel computing. After estimating the model, it’s shown by simple examples how to conduct some further analysis.

# These examples use the data 'eurusd' which comes with the package, but in a scaled form.
data(eurusd, package="gmvarkit")
data <- cbind(10*eurusd[,1], 100*eurusd[,2])
colnames(data) <- colnames(eurusd)

# Estimate a GMVAR(2,2) model
fit <- fitGMVAR(data, p=2, M=2)
fit

# Estimate a GMVAR(2,2) model with autoregressive parameters restricted to be the same for all regimes
C_mat <- rbind(diag(2*2^2), diag(2*2^2))
fitc <- fitGMVAR(data, p=2, M=2, constraints=C_mat)
fitc

# Further information on the estimated model:
plot(fitc)
summary(fitc)
print_std_errors(fitc)
get_gradient(fitc) # The first order condition
get_soc(fitc) # The second order condition (eigenvalues of approximated Hessian)

# Quantile residual diagnostics
diagnostic_plot(fitc, type="series") # type=c("series", "ac", "ch", "norm")
qrt <- quantile_residual_tests(fitc)

# Simulate a sample path form the estimated process
sim <- simulateGMVAR(fitc, nsimu=10)

# Forecast future values of the process
predict(fitc, n_ahead=10)

References

  • Kalliovirta L., Meitz M. and Saikkonen P. (2016) Gaussian mixture vector autoregression. Journal of Econometrics, 192, 485-498.
  • Kalliovirta L. and Saikkonen P. (2010) Reliable Residuals for Multivariate Nonlinear Time Series Models. Unpublished Revision of HECER Discussion Paper No. 247.

Copy Link

Version

Install

install.packages('gmvarkit')

Monthly Downloads

675

Version

1.1.1

License

GPL-3

Maintainer

Savi Virolainen

Last Published

August 28th, 2019

Functions in gmvarkit (1.1.1)

check_gmvar

Checks whether the given object has class attribute "gmvar"
dlogmultinorm

Calculate logarithms of multiple multivariate normal densities with varying mean and constant covariance matrix
eurusd

Euro area and U.S. long-term government bond yields and Euro-U.S. dollar exchange rate.
calc_gradient

Calculate gradient or Hessian matrix
get_regime_autocovs_int

Calculate regimewise autocovariance matrices
get_regime_autocovs

Calculate regimewise autocovariance matrices
check_pMd

Check that p, M and d are correctly set
get_test_Omega

Compute covariance matrix Omega used in quantile residual tests
gmvarkit

gmvarkit: Estimate Gaussian Mixture Vector Autoregressive (GMVAR) model
check_parameters

Check that the given parameter vector satisfies model assumptions
cond_moments

Compute conditional moments of a GMVAR model
diagnostic_plot

Quantile residual diagnostic plot for GMVAR model
is_stationary

Check the stationary condition of given GMVAR model
pick_Am

Pick coefficient matrices
n_params

Calculate the number of parameters in GMVAR model parameter vector
pick_alphas

Pick mixing weight parameters \(\alpha_{m}, m=1,...,M\) from the given parameter vector.
loglikelihood_int

Compute the log-likelihood of Gaussian Mixture Vector Autoregressive model
form_boldA

Form the \(((dp)x(dp))\) "bold A" matrices related to the VAR processes
pick_allA

Pick coefficient all matrices
get_boldA_eigens

Calculate absolute values of the eigenvalues of the "bold A" matrices containing the AR coefficients
get_omega_eigens

Calculate the eigenvalues of the "Omega" error term covariance matrices
fitGMVAR

Two-phase maximum likelihood estimation of GMVAR model
loglikelihood

Compute log-likelihood of GMVAR model using parameter vector
check_null_data

Checks whether the given object contains data or not
pick_phi0

Pick \(\phi_{m,0}\) or \(\mu_{m}\), m=1,..,M vectors from the given parameter vector
pick_all_phi0_A

Pick all \(\phi_{m,0}\) or \(\mu_{m}\) and \(A_{m}\) parameter values from the given parameter vector.
iterate_more

Maximum likelihood estimation of GMVAR model with preliminary estimates
plot.gmvarpred

plot method for class 'gmvarpred' objects
get_IC

Calculate AIC, HQIC and BIC
reform_data

Reform data
pick_Omegas

Pick covariance matrices
format_valuef

Function factory for value formatting
pick_Ami

Pick coefficient matrix
pick_regime

Pick regime parameters \(\upsilon_{m}\)\( = (\phi_{m,0},\)\(\phi_{m}\)\(,\sigma_{m})\) from the given parameter vector.
reform_constrained_pars

Reform constrained parameter vector into the "standard" form
smart_ind

Create somewhat random parameter vector of GMVAR model fairly close to a given parameter vector
smart_covmat

Create somewhat random VAR-model \((dxd)\) error term covariance matrix \(\Omega\) fairly close to a given positive definite covariance matrix using (scaled) Wishart distribution.
get_regime_means

Calculate regime means \(\mu_{m}\)
print_std_errors

Print standard errors of GMVAR model in the same form as the model estimates are printed
unvec

Reverse vectorization operator.
random_covmat

Create somewhat random VAR model error term covariance matrix
print.gmvarsum

Summary print method from objects of class 'gmvarsum'
uncond_moments_int

Calculate the unconditional mean, variance, the first p autocovariances, and the first p autocorrelations of the GMVAR process.
random_coefmats2

Create somewhat random stationary VAR model \((dxd)\) coefficient matrices \(A\).
swap_parametrization

Swap the parametrization of object of class 'gmvar' defining a GMVAR model
random_coefmats

Create random VAR-model \((dxd)\) coefficient matrices \(A\).
quantile_residuals_int

Calculate multivariate quantile residuals of GMVAR model
sort_components

Sort components in parameter vector by mixing weights into a decreasing order
vech

Parsimonious vectorization operator for symmetric matrices.
uncond_moments

Calculate the unconditional mean, variance, the first p autocovariances, and the first p autocorrelations of the GMVAR process.
in_paramspace

Determine whether the parameter vector lies in the parameter space or not
predict.gmvar

Predict method for class 'gmvar' objects
in_paramspace_int

Determine whether the parameter vector lies in the parameter space or not
get_regime_means_int

Calculate regime means \(\mu_{m}\)
regime_distance

Calculate "distance" between two (scaled) regimes \(\upsilon_{m}\)\( = (\phi_{m,0},\)\(\phi_{m}\)\(,\sigma_{m})\)
print.gmvarpred

print method for class 'gmvarpred' objects
plot.qrtest

Quantile residual tests
quantile_residuals

Calculate multivariate quantile residuals of GMVAR model
random_ind

Create somewhat random mean-parametrized parameter vector of GMVAR model, that may not be stationary!
random_ind2

Create somewhat random parameter vector of GMVAR model that is always stationary
standard_errors

Calculate standard errors for estimates of GMVAR model
unvech

Reverse operator of the parsimonious vectorization operator vech.
vec

Vectorization operator.
simulateGMVAR

Simulate from GMVAR process
GMVAR

Create object of class 'gmvar' defining a GMVAR model
all_pos_ints

Check whether all arguments are positive scalar whole numbers
change_parametrization

Change parametrization of the parameter vector
change_regime

Change regime parameters \(\upsilon_{m}\)\( = (\phi_{m,0},\)\(\phi_{m}\)\(,\sigma_{m})\) of the given parameter vector.
check_data

Check the data is in the correct form
check_constraints

Check the constraint matrix has the correct form
add_data

Add data to object of class 'gmvar' defining a GMVAR model
alt_gmvar

Construct a GMVAR model based on results from an arbitrary estimation round of fitGMVAR
GAfit

Genetic algorithm for preliminary estimation of GMVAR model