Learn R Programming

uGMAR

uGMAR provides tools for estimating and analyzing Gaussian mixture autoregressive (GMAR), Student’s t mixture Autoregressive (StMAR) and Gaussian and Student’s t mixture autoregressive (G-StMAR) models, including 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 uGMAR from CRAN with:

install.packages("uGMAR")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("saviviro/uGMAR")

Example

This is a basic example how to estimate GSMAR model and further analyze it.. The example data is simulated from a GMAR p=1, M=2 process. The estimation process is computationally demanding and takes advantage of parallel computing.

## Estimate a GMAR(1, 2) model and examine the estimates
data(simudata, package="uGMAR")
fit <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", ncalls=10, seeds=1:10)
fit
summary(fit) # Approximate standard errors in brackets
plot(fit)

get_gradient(fit) # The first order condition
get_soc(fit) # The second order condition (eigenvalues of approximated Hessian)
profile_logliks(fit) # Plot the profile log-likelihood functions

## Quantile residual diagnostics
quantile_residual_plot(fit)
diagnostic_plot(fit)
qrt <- quantile_residual_tests(fit)

## Simulate a sample path from the estimated process
sim <- simulate(fit, nsim=100)
plot.ts(sim$sample)

## Forecast future values of the process
predict(fit, n_ahead=10, pi=c(0.95, 0.8))

# Estimate a GMAR(1, 2) model with the autoregressive coefficients restricted
# to be the same in both regimes:
fitr <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", restricted=TRUE,
                 ncalls=10, seeds=1:10)

# Test with likelihood ratio tests whether the AR parameters are the same in
# both regimes (see also the function 'Wald_test'):
LR_test(fit, fitr)

# Conditional mean and variance plots:
cond_moment_plot(fit, which_moment="mean")
cond_moment_plot(fit, which_moment="variance")

References

  • Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.

  • Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student’s t-distribution. Communications in Statistics - Theory and Methods 52(2), 499-515.

  • Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student’s t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4), 559-580.

Copy Link

Version

Install

install.packages('uGMAR')

Monthly Downloads

392

Version

3.5.2

License

GPL-3

Maintainer

Savi Virolainen

Last Published

April 7th, 2025

Functions in uGMAR (3.5.2)

all_pos_ints

Check whether all arguments are strictly positive natural numbers
Wald_test

Perform Wald test
M10Y1Y

Spread between 10-Year and 1-Year Treasury rates: M10Y1Y
LR_test

Perform likelihood ratio test
alt_gsmar

Construct a GSMAR model based on results from an arbitrary estimation round of fitGSMAR
check_model

Check that the argument 'model' is correctly specified.
check_data

Check that given object contains data
GSMAR

Create object of class 'gsmar' defining a GMAR, StMAR, or G-StMAR model
GAfit

Genetic algorithm for preliminary estimation of GMAR, StMAR, or G-StMAR model
change_regime

Change the specified regime of parameter vector to the given regime-parameter vector
check_pM

Check that p and M are correctly set
change_parametrization

Change parametrization of a parameter vector
check_and_correct_data

Check that the data is set correctly and correct if not
check_gsmar

Check that given object has class attribute 'gsmar'
calc_gradient

Calculate gradient or Hessian matrix
check_constraint_mat

Check the constraint matrices
cond_moment_plot

Conditional mean or variance plot for GMAR, StMAR, and G-StMAR models
diagnostic_plot

Quantile residual based diagnostic plots for GMAR, StMAR, and G-StMAR models
fitGSMAR

Estimate Gaussian or Student's t Mixture Autoregressive model
condmomentPlot

DEPRECATED, USE cond_moment_plot INSTEAD! Conditional mean or variance plot for GMAR, StMAR, and G-StMAR models
check_params_length

Check that the parameter vector has the correct dimension
extract_regime

Extract regime from a parameter vector
cond_moments

Calculate conditional moments of GMAR, StMAR, or G-StMAR model
condMoments

DEPRECATED, USE cond_moments INSTEAD! Calculate conditional moments of GMAR, StMAR, or G-StMAR model
format_valuef

Function factory for formatting values
diagnosticPlot

DEPRECATED, USE diagnostic_plot INSTEAD! Quantile residual based diagnostic plots for GMAR, StMAR, and G-StMAR models
get_ar_roots

Calculate absolute values of the roots of the AR characteristic polynomials
get_IC

Calculate AIC, HQIC and BIC
get_regime_autocovs

Calculate regime specific autocovariances \(\gamma\)\(_{m,p}\)
get_varying_h

Get differences 'h' which are adjusted for overly large degrees of freedom parameters
get_minval

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

Calculate regime specific variances \(\gamma_{m,0}\)
get_alpha_mt

Get mixing weights alpha_mt (this function is for internal use)
get_test_Omega

Generate the covariance matrix Omega for quantile residual tests
isStationary

DEPRECATED, USE is_stationary INSTEAD! Check the stationary condition of specified GMAR, StMAR, or G-StMAR model.
get_regime_means

Calculate regime specific means \(\mu_{m}\)
n_params

Calculate the number of parameters
is_stationary

Check the stationary condition of specified GMAR, StMAR, or G-StMAR model.
loglikelihood_int

Compute the log-likelihood of GMAR, StMAR, or G-StMAR model
iterate_more

Maximum likelihood estimation of GMAR, StMAR, or G-StMAR model with preliminary estimates
mixingWeights

DEPRECATED, USE mixing_weights INSTEAD! Calculate mixing weights of GMAR, StMAR or G-StMAR model
parameter_checks

Check the parameter vector is specified correctly
loglikelihood

Compute the log-likelihood of GMAR, StMAR, or G-StMAR model
mixing_weights

Calculate mixing weights of GMAR, StMAR or G-StMAR model
is_stationary_int

Check the stationarity and identification conditions of specified GMAR, StMAR, or G-StMAR model.
mixing_weights_int

Calculate mixing weights of a GMAR, StMAR, or G-StMAR model
print.gsmarpred

Print method for class 'gsmarpred' objects
pick_alphas

Pick mixing weights parameters from parameter vector
profile_logliks

Plot profile log-likelihoods around the estimates
pick_pars

Pick \(\phi_0\) (or \(\mu\)), AR-coefficients, and variance parameters from a parameter vector
plot.gsmarpred

Plot method for class 'gsmarpred' objects
quantileResidualPlot

DEPRECATED, USE quantile_residual_plot INSTEAD! Plot quantile residual time series and histogram
print.gsmarsum

Print method from objects of class 'gsmarsum'
pick_dfs

Pick degrees of freedom parameters from a parameter vector
pick_phi0

Pick phi0 or mean parameters from parameter vector
predict.gsmar

Forecast GMAR, StMAR, or G-StMAR process
quantile_residuals

Compute quantile residuals of GMAR, StMAR, or G-StMAR model
quantile_residuals_int

Compute quantile residuals of GMAR, StMAR, or G-StMAR model
randomIndividual

DEPRECATED, USE random_ind OR smart_ind INSTEAD! Create random GMAR, StMAR, or G-StMAR model compatible parameter vector
random_ind

Create random GMAR, StMAR, or G-StMAR model compatible parameter vector
quantile_residual_plot

Plot quantile residual time series and histogram
quantileResidualTests

DEPRECATED, USE quantile_residual_tests INSTEAD! Quantile residual tests for GMAR, StMAR , and G-StMAR models
plot.qrtest

Quantile residual tests for GMAR, StMAR , and G-StMAR models
random_arcoefs

Create random AR coefficients
random_ind_int

Create random GMAR, StMAR, or G-StMAR model compatible parameter vector
quantileResiduals

DEPRECATED, USE quantile_residuals INSTEAD! Compute quantile residuals of GMAR, StMAR, or G-StMAR model
random_regime

Create random regime parameters
simulate.gsmar

Simulate obsercations from GMAR, StMAR, and G-StMAR processes
simulateGSMAR

DEPRECATED, USE simulate.gsmar INSTEAD! Simulate observations from GMAR, StMAR, and G-StMAR processes
simudata

Simulated data
regime_distance

Calculate "distance" between two regimes
reform_constrained_pars

Reform parameter vector with linear constraints to correspond non-constrained parameter vector.
reform_parameters

Reform any parameter vector into standard form.
reform_restricted_pars

Reform parameter vector with restricted autoregressive parameters to correspond non-restricted parameter vector.
sort_components

Sort the mixture components of a GMAR, StMAR, or G-StMAR model
remove_all_constraints

Transform constrained and restricted parameter vector into the regular form
standard_errors

Calculate standard errors for estimates of a GMAR, StMAR, or G-StMAR model
stmar_to_gstmar

Estimate a G-StMAR model based on a StMAR model with large degrees of freedom parameters
uncond_moments

Calculate unconditional mean, variance, first p autocovariances and autocorrelations of the GSMAR process.
uGMAR-package

uGMAR: Estimate Univariate Gaussian and Student's t Mixture Autoregressive Models
stmarpars_to_gstmar

Transform a StMAR or G-StMAR model parameter vector to a corresponding G-StMAR model parameter vector with large dfs parameters reduced.
swap_parametrization

Swap the parametrization of object of class 'gsmar' defining a GMAR, StMAR, or G-StMAR model
warn_dfs

Warn about large degrees of freedom parameter values
warn_ar_roots

Warn about near-unit-roots in some regimes
uncond_moments_int

Calculate unconditional mean, variance, and the first p autocovariances and autocorrelations of a GSMAR process.
T10Y1Y

Spread between 10-Year and 1-Year Treasury rates: T10Y1Y
add_data

Add data to object of class 'gsmar' defining a GMAR, StMAR, or G-StMAR model
TBFF

Spread between the 3-month Treasury bill rate and the effective federal funds rate: TBFF
add_dfs

Add random dfs to a vector