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("saviviro/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: 16 estimation rounds and seeds for reproducible results
fit <- fitGMVAR(data, p=2, M=2, ncalls=16, seeds=1:16)
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, ncalls=16, seeds=1:16)
fitc

# Further information on the estimated model:
plot(fitc)
summary(fitc)
print_std_errors(fitc)
get_foc(fitc) # The first order condition
get_soc(fitc) # The second order condition (eigenvalues of approximated Hessian)
profile_logliks(fitc) # Profile log-likelihood functions

# 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.3

License

GPL-3

Maintainer

Savi Virolainen

Last Published

March 12th, 2020

Functions in gmvarkit (1.1.3)

GAfit

Genetic algorithm for preliminary estimation of a GMVAR model
change_parametrization

Change parametrization of a parameter vector
calc_gradient

Calculate gradient or Hessian matrix
alt_gmvar

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

Check the data is in the correct form
change_regime

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

Check the constraint matrix has the correct form
add_data

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

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

Check whether all arguments are positive integers
fitGMVAR

Two-phase maximum likelihood estimation of a GMVAR model
check_gmvar

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

Checks whether the given object contains data
cond_moments

Compute conditional moments of a GMVAR model
form_boldA

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

Maximum likelihood estimation of a GMVAR model with preliminary estimates
get_omega_eigens

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

Compute log-likelihood of a GMVAR model using parameter vector
get_regime_autocovs

Calculate regimewise autocovariance matrices
check_pMd

Check that p, M, and d are correctly set
check_parameters

Check that the given parameter vector satisfies the model assumptions
format_valuef

Function factory for value formatting
get_boldA_eigens

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

Calculate AIC, HQIC, and BIC
random_covmat

Create random VAR model error term covariance matrix
is_stationary

Check the stationary condition of a given GMVAR model
pick_phi0

Pick \(\phi_{m,0}\) or \(\mu_{m}\), m=1,..,M vectors
get_minval

Returns the default smallest allowed log-likelihood for given data.
random_coefmats2

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

Pick regime parameters \(\upsilon_{m}\)\( = (\phi_{m,0},\)\(\phi_{m}\)\(,\sigma_{m})\)
in_paramspace_int

Determine whether the parameter vector lies in the parameter space
pick_all_phi0_A

Pick all \(\phi_{m,0}\) or \(\mu_{m}\) and \(A_{m}\) parameter values
smart_covmat

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

plot method for class 'gmvarpred' objects
unvech

Reverse operator of the parsimonious vectorization operator vech
smart_ind

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

Calculate multivariate quantile residuals of GMVAR model
pick_Am

Pick coefficient matrices
plot.qrtest

Quantile residual tests
predict.gmvar

Predict method for class 'gmvar' objects
pick_Ami

Pick coefficient matrix
pick_alphas

Pick mixing weight parameters \(\alpha_{m}, m=1,...,M\)
sort_components

Sort components in parameter vector according to mixing weights into a decreasing order
standard_errors

Calculate standard errors for estimates of GMVAR model
vec

Vectorization operator
random_ind2

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

Create random mean-parametrized parameter vector of a GMVAR model that may not be stationary
get_regime_means

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

Calculate the unconditional mean, variance, the first p autocovariances, and the first p autocorrelations of a GMVAR process
vech

Parsimonious vectorization operator for symmetric matrices
swap_parametrization

Swap the parametrization of a GMVAR model
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.
get_regime_autocovs_int

Calculate regimewise autocovariance matrices
diagnostic_plot

Quantile residual diagnostic plot for a GMVAR model
loglikelihood_int

Compute log-likelihood of a Gaussian Mixture Vector Autoregressive model
pick_Omegas

Pick covariance matrices
n_params

Calculate the number of parameters in GMVAR model parameter vector
get_regime_means_int

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

gmvarkit: Estimate Gaussian Mixture Vector Autoregressive (GMVAR) model
print.gmvarsum

Summary print method from objects of class 'gmvarsum'
in_paramspace

Determine whether the parameter vector lies in the parameter space
print_std_errors

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

Compute covariance matrix Omega used in quantile residual tests
print.gmvarpred

Print method for class 'gmvarpred' objects
profile_logliks

Plot profile log-likehoods around the estimates
regime_distance

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

Simulate from GMVAR process
pick_allA

Pick coefficient all matrices
reform_data

Reform data
unvec

Reverse vectorization operator
quantile_residuals_int

Calculate multivariate quantile residuals of GMVAR model
reform_constrained_pars

Reform constrained parameter vector into the "standard" form
random_coefmats

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

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