Type: Package
Title: Hypothesis Testing for Markov Switching Models
Date: 2025-02-24
Version: 0.1.5
Maintainer: Gabriel Rodriguez Rondon <gabriel.rodriguezrondon@mail.mcgill.ca>
Description: Implementation of hypothesis testing procedures described in Hansen (1992) <doi:10.1002/jae.3950070506>, Carrasco, Hu, & Ploberger (2014) <doi:10.3982/ECTA8609>, Dufour & Luger (2017) <doi:10.1080/07474938.2017.1307548>, and Rodriguez Rondon & Dufour (2024) https://grodriguezrondon.com/files/RodriguezRondon_Dufour_2024_MonteCarlo_LikelihoodRatioTest_MarkovSwitchingModels_20241015.pdf that can be used to identify the number of regimes in Markov switching models.
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
LazyData: TRUE
RoxygenNote: 7.3.1
Encoding: UTF-8
URL: https://github.com/roga11/MSTest
BugReports: https://github.com/roga11/MSTest/issues
Imports: stats, rlang, nloptr, Rcpp (≥ 1.0.1), numDeriv, pracma, foreach, GenSA, pso, GA, graphics
LinkingTo: Rcpp, RcppArmadillo
Depends: R (≥ 4.0.0)
SystemRequirements: C++17
NeedsCompilation: yes
Packaged: 2025-02-24 18:23:58 UTC; gabrielrodriguez
Author: Gabriel Rodriguez Rondon [cre, aut], Jean-Marie Dufour [aut]
Repository: CRAN
Date/Publication: 2025-02-24 18:40:07 UTC

Testing Markov Switching Models

Description

This package implements hypothesis testing procedures that can be used to identify the number of regimes in a Markov-Switching model.

Author(s)

Gabriel Rodriguez Rondon, gabriel.rodriguezrondon@mail.mcgill.ca (Maintainer)

Jean-Marie Dufour, jean-marie.dufour@mcgill.ca

References

Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.

Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..

Dufour, Jean-Marie, and Richard Luger. 2017. “Identification-robust moment-based tests for Markov switching in autoregressive models.” Econometric Reviews 36 (6-9): 713–727.

Kasahara, Hiroyuk, and Katsum Shimotsu. 2018. “Testing the number of regimes in Markov regime switching models.” arXiv preprint arXiv:1801.06862.

Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.

Hamilton, James D. 1989. “A new approach to the economic analysis of nonstationary time series and the business cycle.” Econometrica 57 (2): 357–384.

Hamilton, James D. 1994. "Time series analysis". Princeton university press.

Hansen, Bruce E. 1992. “The likelihood ratio test under nonstandard conditions: testing the Markov switching model of GNP.” Journal of applied Econometrics 7 (S1): S61–S82.

Rodriguez Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.

Rodriguez Rondon, Gabriel and Jean-Marie Dufour. 2022. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.

Rodriguez Rondon, Gabriel and Jean-Marie Dufour. 2022. “MSTest: An R-package for Testing Markov-Switching Models.” Unpublished manuscript.

Qu, Zhongjun, and Fan Zhuo. 2021. “Likelihood Ratio-Based Tests for Markov Regime Switching.” The Review of Economic Studies 88 (2): 937–968.


AIC of a ARmdl object

Description

This is a method for the function AIC() for objects of the class ARmdl.

Usage

## S3 method for class 'ARmdl'
AIC(object, ..., k = 2)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

k

numeric, the penalty per parameter to be used; the default k = 2 is the classical AIC.

Value

AIC value.


AIC of a HMmdl object

Description

This is a method for the function AIC() for objects of the class HMmdl.

Usage

## S3 method for class 'HMmdl'
AIC(object, ..., k = 2)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

k

numeric, the penalty per parameter to be used; the default k = 2 is the classical AIC.

Value

AIC value.


AIC of a MSARmdl object

Description

This is a method for the function AIC() for objects of the class MSARmdl.

Usage

## S3 method for class 'MSARmdl'
AIC(object, ..., k = 2)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

k

numeric, the penalty per parameter to be used; the default k = 2 is the classical AIC.

Value

AIC value.


AIC of a MSVARmdl object

Description

This is a method for the function AIC() for objects of the class MSVARmdl.

Usage

## S3 method for class 'MSVARmdl'
AIC(object, ..., k = 2)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

k

numeric, the penalty per parameter to be used; the default k = 2 is the classical AIC.

Value

AIC value.


AIC of a Nmdl object

Description

This is a method for the function AIC() for objects of the class Nmdl.

Usage

## S3 method for class 'Nmdl'
AIC(object, ..., k = 2)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

k

numeric, the penalty per parameter to be used; the default k = 2 is the classical AIC.

Value

AIC value.


AIC of a VARmdl object

Description

This is a method for the function AIC() for objects of the class VARmdl.

Usage

## S3 method for class 'VARmdl'
AIC(object, ..., k = 2)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

k

numeric, the penalty per parameter to be used; the default k = 2 is the classical AIC.

Value

AIC value.


Autoregressive X Model

Description

This function estimates an ARX model with p lags. This can be used for the null hypothesis of a linear model against an alternative hypothesis of a Markov switching autoregressive model with k regimes.

Usage

ARXmdl(Y, p, Z, control = list())

Arguments

Y

A (T x 1) matrix of observations.

p

Integer determining the number of autoregressive lags.

Z

A (T x qz) matrix of exogenous regressors.

control

List with model options including:

  • const: Boolean determining whether to estimate model with constant if TRUE or not if FALSE. Default is TRUE.

  • getSE: Boolean determining whether to compute standard errors of parameters if TRUE or not if FALSE. Default is TRUE.

Value

List of class ARmdl (S3 object) with model attributes including:

See Also

MSARmdl

Examples

set.seed(1234)
# Define DGP of AR process
mdl_ar <- list(n     = 500, 
               mu    = 5,
               sigma = 2,
               phi   = c(0.5,0.2))

# Simulate process using simuAR() function
y_simu <- simuAR(mdl_ar)

# Set options for model estimation
control <- list(const  = TRUE, 
                getSE  = TRUE)

# Estimate model
y_ar_mdl <- ARmdl(y_simu$y, p = 2, control)
y_ar_mdl


Autoregressive Model

Description

This function estimates an autoregresive model with p lags. This can be used for the null hypothesis of a linear model against an alternative hypothesis of a Markov switching autoregressive model with k regimes.

Usage

ARmdl(Y, p, control = list())

Arguments

Y

A (T x 1) matrix of observations.

p

Integer determining the number of autoregressive lags.

control

List with model options including:

  • const: Boolean determining whether to estimate model with constant if TRUE or not if FALSE. Default is TRUE.

  • getSE: Boolean determining whether to compute standard errors of parameters if TRUE or not if FALSE. Default is TRUE.

Value

List of class ARmdl (S3 object) with model attributes including:

See Also

MSARmdl

Examples

set.seed(1234)
# Define DGP of AR process
mdl_ar <- list(n     = 500, 
               mu    = 5,
               sigma = 2,
               phi   = c(0.5,0.2))

# Simulate process using simuAR() function
y_simu <- simuAR(mdl_ar)

# Set options for model estimation
control <- list(const  = TRUE, 
                getSE  = TRUE)

# Estimate model
y_ar_mdl <- ARmdl(y_simu$y, p = 2, control)
y_ar_mdl


BIC of a ARmdl object

Description

This is a method for the function BIC() for objects of the class ARmdl.

Usage

## S3 method for class 'ARmdl'
BIC(object, ...)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

Value

BIC value.


BIC of a HMmdl object

Description

This is a method for the function BIC() for objects of the class HMmdl.

Usage

## S3 method for class 'HMmdl'
BIC(object, ...)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

Value

BIC value.


BIC of a MSARmdl object

Description

This is a method for the function BIC() for objects of the class MSARmdl.

Usage

## S3 method for class 'MSARmdl'
BIC(object, ...)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

Value

BIC value.


BIC of a MSVARmdl object

Description

This is a method for the function BIC() for objects of the class MSVARmdl.

Usage

## S3 method for class 'MSVARmdl'
BIC(object, ...)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

Value

BIC value.


BIC of a Nmdl object

Description

This is a method for the function BIC() for objects of the class Nmdl.

Usage

## S3 method for class 'Nmdl'
BIC(object, ...)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

Value

BIC value.


BIC of a VARmdl object

Description

This is a method for the function BIC() for objects of the class VARmdl.

Usage

## S3 method for class 'VARmdl'
BIC(object, ...)

Arguments

object

a fitted model object for which there exists a logLik method to extract the corresponding log-likelihood, or an object inheriting from class logLik.

...

optionally more fitted model objects.

Value

BIC value.


Carrasco, Hu, and Ploberger (2014) parameter stability test

Description

This function performs the CHP (2014) parameter stability test as outline in Carrasco, M., Hu, L. and Ploberger, W. (2014). Original source code can be found here.

Usage

CHPTest(Y, p, control = list())

Arguments

Y

A (T x 1) matrix of observations.

p

Integer determining the number of autoregressive lags.

control

List with test procedure options including:

  • N: Integer determining the number of Bootstrap iterations. Default is set to 3000 as in paper.

  • rho_b: Number determining bounds for distribution of rh0 (i.e. rho ~ [-rho_b,rho_b]).

  • msvar: Boolean indicator. If TRUE, there is a switch in variance. If FALSE only switch in mean is considered.

  • getSE: Boolean indicator. If TRUE, standard errors for restricted model are estimated. If FALSE no standard errors are estimated. Default is TRUE.

Value

List of class CHPTest (S3 object) with model attributes including:

References

Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.

Examples

# load data used in Hamilton 1989 
y84 <- as.matrix(hamilton84GNP$GNP_gr)


# Set test procedure options
control = list(N = 1000, 
               rho_b = 0.7, 
               msvar = FALSE)

# perform test with switch in mean only on Hamilton 1989 data

  mdl_84_msmu <- CHPTest(y84, p = 4, control = control)
  summary(mdl_84_msmu)


Bootstrap critical values for CHP 2014 parameter stability test

Description

This bootstrap procedure is described on pg. 771 of CHP 2014.

Usage

CHPbootCV(mdl, rho_b, N, msvar)

Arguments

mdl

List containing model attributes (see ARmdl).

rho_b

Number determining bounds for distribution of rh0 (i.e. rho ~ [-rho_b,rho_b]).

N

Number of bootstrap simulations.

msvar

Boolean indicator. If TRUE, there is a switch in variance. If FALSE only switch in mean is considered.

Value

Bootstrap critical values

References

Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.


Monte Carlo moment-based test for Markov switching model

Description

This function performs the Local Monte Carlo moment-based test for Markov switching autoregressive models proposed in Dufour & Luger (2017).

Usage

DLMCTest(Y, p, control = list())

Arguments

Y

Series to be tested

p

Number of autoregressive lags.

control

List with test procedure options including:

  • N: Integer determining the number of Monte Carlo simulations. Default is set to 99 as in paper.

  • simdist_N: Integer determining the number of simulations for CDF distribution approximation. Default is set to 10000.

  • getSE: Boolean indicator. If TRUE, standard errors for restricted model are estimated. If FALSE no standard errors are estimated. Default is TRUE.

Value

List of class DLMCTest (S3 object) with attributes including:

References

Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.

Examples

set.seed(1234)
# load data used in Hamilton 1989 and extended data used in CHP 2014 
y84 <- as.matrix(hamilton84GNP$GNP_gr)
y10 <- as.matrix(chp10GNP$GNP_gr)

# Set test procedure options
lmc_control = list(N = 99,
                   simdist_N = 10000,
                   getSE = TRUE)

# perform test on Hamilton 1989 data
lmc_gnp84 <- DLMCTest(y84, p = 4, control = lmc_control)
summary(lmc_gnp84)


Maximized Monte Carlo moment-based test for Markov switching model

Description

This function performs the maximized Monte Carlo moment-based test for Markov switching autoregressive models proposed in Dufour & Luger (2017).

Usage

DLMMCTest(Y, p, control = list())

Arguments

Y

Series to be tested

p

Number of autoregressive lags.

control

List with test procedure options including:

  • N: Integer determining the number of Monte Carlo simulations. Default is set to 99 as in paper.

  • simdist_N: Integer determining the number of simulations for CDF distribution approximation. Default is set to 10000.

  • getSE: Boolean indicator. If TRUE, standard errors for restricted model are estimated. If FALSE no standard errors are estimated. Default is TRUE.

  • eps: Fixed positive constant that does not depend on T used to determine lower and upper bounds on consistent set considered for nuisance parameter space.

  • CI_union: Boolean indicator determining if union between eps and confidence interval is used to determine lower and upper bound on consistent set considered for nuisance parameter space. If TRUE union is used and if FALSE only eps is used. Note that if standard errors obtained are not finite then only eps is used. Default is FALSE.

  • lambda: Numeric value for penalty on stationary constraint not being met. Default is 100.

  • stationary_ind: Boolean indicator determining if only stationary solutions should be considered if TRUE or any solution can be considered if FALSE. Default is TRUE.

  • phi_low: Vector with lower bound for autoregressive parameters when optimizing. Default is NULL.

  • phi_upp: Vector with upper bound for autoregressive parameters when optimizing. Default is NULL.

  • optim_type: String determining type of numerical optimization algorithm to use. Available options are: pso, GenSA, GA. Default is pso.

  • silence: Boolean indicator determining if optimization updates should be silenced if TRUE or not if FALSE. Default is FALSE.

  • threshold_stop: Numeric value determining the maximum possible p-value attainable. Default is 1.

  • maxit: Int determining the maximum number of function evaluations. Default is 1000.

  • optim_control: List containing other optimization options specific to the numerical optimization algorithm used. For other options see documentation of numerical algorithm chosen.

Value

List of class DLMCTest (S3 object) with attributes including:

References

Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.

Examples

set.seed(1234)
# load data used in Hamilton 1989 and extended data used in CHP 2014 
y84 <- as.matrix(hamilton84GNP$GNP_gr)
y10 <- as.matrix(chp10GNP$GNP_gr)

# Set test procedure options
mmc_control <- list(N = 99,
                    simdist_N = 10000,
                    getSE = TRUE,
                    eps = 0, 
                    CI_union = TRUE,
                    lambda = 100,
                    stationary_ind = TRUE,
                    optim_type = "GenSA",
                    silence = FALSE,
                    threshold_stop = 1,
                    maxit = 200)


# perform test on Hamilton 1989 data

  mmc_gnp84 <- DLMMCTest(y84, p = 4, control = mmc_control)
  summary(mmc_gnp84)



MMC nuisance parameter bounds for Moment-based test

Description

This function is used to determine the lower and upper bounds for the MMC LRT parameter search.

Usage

DLMMC_bounds(mdl_h0, con)

Arguments

mdl_h0

List with restricted model properties.

con

List with control options provided to DLMMCTest procedure.

Value

List with theta_low, vector of parameter lower bounds, and theta_upp, vector of parameter upper bounds.


Moment-based MMC test p-value

Description

This functions is used by numerical optimization algorithms for find maximum p-value given parameter vector theta.

Usage

DLMMCpval_fun(
  theta,
  y,
  x,
  params,
  sim_stats,
  pval_type,
  stationary_ind,
  lambda
)

Arguments

theta

Value of nuisance parameters. Specifically, these are the consistent estimates of nuisance parameters as discussed in Dufour & Luger (2017) LMC procedure.

y

series being tested.

x

lagged values of series.

params

A (2 x 4) matrix with parameters to combine test statistics. See approxDistDL.

sim_stats

A (N x 1) vector with test statistics. The last element is the test statistic from observed data.

pval_type

String determining the type of method used to combine p-values. If set to "min" the min method of combining p-values is used as in Fisher 1932 and Pearson 1933. If set to "prod" the product of p-values is used as in Tippett 1931 and Wilkinson 1951.

stationary_ind

Boolean indicator determining if only stationary solutions should be considered if TRUE or any solution can be considered if FALSE. Default is TRUE.

lambda

Numeric value for penalty on stationary constraint not being met. Default is 100.

Value

Maximized Monte Carlo p-value.

References

Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.


Moment-based MMC test (negative) p-value

Description

This functions is used by numerical optimization algorithms for find negative of maximum p-value given parameter vector theta.

Usage

DLMMCpval_fun_min(
  theta,
  y,
  x,
  params,
  sim_stats,
  pval_type,
  stationary_ind,
  lambda
)

Arguments

theta

Value of nuisance parameters. Specifically, these are the consistent estimates of nuisance parameters as discussed in Dufour & Luger (2017) LMC procedure.

y

series being tested.

x

lagged values of series.

params

A (2 x 4) matrix with parameters to combine test statistics. See approxDistDL.

sim_stats

A (N x 1) vector with test statistics. The last element is the test statistic from observed data.

pval_type

String determining the type of method used to combine p-values. If set to "min" the min method of combining p-values is used as in Fisher 1932 and Pearson 1933. If set to "prod" the product of p-values is used as in Tippett 1931 and Wilkinson 1951.

stationary_ind

Boolean indicator determining if only stationary solutions should be considered if TRUE or any solution can be considered if FALSE. Default is TRUE.

lambda

Numeric value for penalty on stationary constraint not being met. Default is 100.

Value

Negative Maximized Monte Carlo p-value.

References

Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.


Maximization step of EM algorithm for Hidden Markov model

Description

This function performs the maximization step of the Expectation Maximization algorithm for Hidden Markov models.

Usage

EMaximization_HMmdl(theta, mdl, MSloglik_output, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

MSloglik_output

List with output from ExpectationM_HMmdl.

k

Integer determining the number of regimes.

Value

List with new maximized parameters.


Maximization step of EM algorithm for Markov-switching ARX model

Description

This function performs the maximization step of the Expectation Maximization algorithm for Markov-switching ARX model.

Usage

EMaximization_MSARXmdl(theta, mdl, MSloglik_output, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

MSloglik_output

List with output from ExpectationM_MSARmdl.

k

Integer determining the number of regimes.

Value

List with new maximized parameters.


Maximization step of EM algorithm for Markov-switching autoregressive model

Description

This function performs the maximization step of the Expectation Maximization algorithm for Markov-switching autoregressive model.

Usage

EMaximization_MSARmdl(theta, mdl, MSloglik_output, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

MSloglik_output

List with output from ExpectationM_MSARmdl.

k

Integer determining the number of regimes.

Value

List with new maximized parameters.


Maximization step of EM algorithm for Markov-switching VARX model

Description

This function performs the maximization step of the Expectation Maximization algorithm for Markov-switching VARX model.

Usage

EMaximization_MSVARXmdl(theta, mdl, MSloglik_output, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

MSloglik_output

List with output from ExpectationM_MSVARmdl.

k

Integer determining the number of regimes.

Value

List with new maximized parameters.


Maximization step of EM algorithm for Markov-switching vector autoregressive model

Description

This function performs the maximization step of the Expectation Maximization algorithm for Markov-switching vector autoregressive model.

Usage

EMaximization_MSVARmdl(theta, mdl, MSloglik_output, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

MSloglik_output

List with output from ExpectationM_MSVARmdl.

k

Integer determining the number of regimes.

Value

List with new maximized parameters.


EM algorithm iteration for Hidden Markov model

Description

This function performs the one iteration (E-step and M-step) of the Expectation Maximization algorithm for a Hidden Markov model.

Usage

EMiter_HMmdl(mdl, EMest_output, k)

Arguments

mdl

List with model attributes.

EMest_output

List with attributes from previous iteration.

k

Integer determining the number of regimes.

Value

List with attributes from new iteration.


EM algorithm iteration for Markov-switching ARX model

Description

This function performs the one iteration (E-step and M-step) of the Expectation Maximization algorithm for Markov-switching ARX model.

Usage

EMiter_MSARXmdl(mdl, EMest_output, k)

Arguments

mdl

List with model attributes.

EMest_output

List with attributes from previous iteration.

k

Integer determining the number of regimes.

Value

List with attributes from new iteration.


EM algorithm iteration for Markov-switching autoregressive model

Description

This function performs the one iteration (E-step and M-step) of the Expectation Maximization algorithm for Markov-switching autoregressive model.

Usage

EMiter_MSARmdl(mdl, EMest_output, k)

Arguments

mdl

List with model attributes.

EMest_output

List with attributes from previous iteration.

k

Integer determining the number of regimes.

Value

List with attributes from new iteration.


EM algorithm iteration for Markov-switching VARX model

Description

This function performs the one iteration (E-step and M-step) of the Expectation Maximization algorithm for Markov-switching VARX model.

Usage

EMiter_MSVARXmdl(mdl, EMest_output, k)

Arguments

mdl

List with model attributes.

EMest_output

List with attributes from previous iteration.

k

Integer determining the number of regimes.

Value

List with attributes from new iteration.


EM algorithm iteration for Markov-switching vector autoregressive model

Description

This function performs the one iteration (E-step and M-step) of the Expectation Maximization algorithm for Markov-switching vector autoregressive model.

Usage

EMiter_MSVARmdl(mdl, EMest_output, k)

Arguments

mdl

List with model attributes.

EMest_output

List with attributes from previous iteration.

k

Integer determining the number of regimes.

Value

List with attributes from new iteration.


Hidden Markov model log-likelihood function

Description

This function computes the log-likelihood for a Hidden Markov model and uses the Hamilton smoother to obtain smoothed probabilities of each state. This is also the expectation step in the Expectation Maximization algorithm for a Markov-switching autoregressive model.

Usage

ExpectationM_HMmdl(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

List which includes log-likelihood value and smoothed probabilities of each regime.


Markov-switching ARX log-likelihood function

Description

This function computes the log-likelihood for a markov-switching autoregressive model and uses the Hamilton smoother to obtain smoothed probabilities of each state. This is also the expectation step in the Expectation Maximization algorithm for a Markov-switching ARX model.

Usage

ExpectationM_MSARXmdl(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

List which includes log-likelihood and smoothed probabilities of each regime.


Markov-switching autoregressive log-likelihood function

Description

This function computes the log-likelihood for a markov-switching autoregressive model and uses the Hamilton smoother to obtain smoothed probabilities of each state. This is also the expectation step in the Expectation Maximization algorithm for a Markov-switching autoregressive model.

Usage

ExpectationM_MSARmdl(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

List which includes log-likelihood and smoothed probabilities of each regime.


Markov-switching VARX log-likelihood function

Description

This function computes the log-likelihood for a markov-switching VARX model and uses the Hamilton smoother to obtain smoothed probabilities of each state. This is also the expectation step in the Expectation Maximization algorithm for a Markov-switching autoregressive model.

Usage

ExpectationM_MSVARXmdl(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

List which includes log-likelihood and smoothed probabilities of each regime.


Markov-switching vector autoregressive log-likelihood function

Description

This function computes the log-likelihood for a markov-switching vector autoregressive model and uses the Hamilton smoother to obtain smoothed probabilities of each state. This is also the expectation step in the Expectation Maximization algorithm for a Markov-switching autoregressive model.

Usage

ExpectationM_MSVARmdl(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

List which includes log-likelihood and smoothed probabilities of each regime.


Hansen (1992) likelihood ratio test

Description

This function performs Hansen's likelihood ratio test as described in Hansen (1992). Original source code can be found here.

Usage

HLRTest(Y, p, control = list())

Arguments

Y

A (T x 1) matrix of observations.

p

Integer determining the number of autoregressive lags.

control

List with test procedure options including:

  • ix: List of Markov Switching parameters. 1 = just mean c(1,2) = mean and first param, (default: 1).

  • msvar: Boolean indicator. If TRUE, there is a switch in variance. If FALSE only switch in mean is considered. Default is FALSE.

  • qbound: Indicator that bounds q by 1-p (default: FALSE).

  • gridsize: Integer determining the number of grid points for markov switching parameters. Default is 20.

  • pgrid_from: Double determining the initial grid point for transition probabilities. Default is 0.1.

  • pgrid_by: Double determining the step size for grid points of transition probabilities. This, along with p_gridsize will determine the bounds of search space. Default is 0.075.

  • pgrid_to: Double determining the end grid point for transition probabilities. Default is 0.925.

  • mugrid_from: Double determining the minimum value of mean in second regime. Default is 0.1.

  • mugrid_by: Double determining the step size for grid points of mean in second regime. This, along with gridsize will determine the max value of mean in second regime. Default is 0.1.

  • siggrid_from: Double determining the minimum value of sigma in second regime (if msvar = TRUE). Default is 0.1.

  • siggrid_by: Double determining the step size for grid points of sigma in second regime. This, along with gridsize will determine the max value of sigma in second regime. Default is 0.1.

  • N: Integer determining the number of replications. Default is 1000.

  • nwband: Integer determining maximum bandwidth in Bartlett kernel. Critical values and p-values are returned for each bandwidth from 0:nwband as suggested in Hansen (1996). Default is 4.

  • theta_null_low: Vector determining lower bound on parameters under the null hypothesis. Length of vector should be number of model coefficients + 1 for variance. Default is to only bound variance at 0.01.

  • theta_null_upp: Vector determining upper bound on parameters under the null hypothesis. Length of vector should be number of model coefficients + 1 for variance. Default is to no bounds (i.e. Inf).

  • optim_method: String determining the type of optimization procedure used. Allowed options are "gp-optim" for general purpose optimization using optim from or slsqp. Default is "gp-optim".

Value

List of class HLRTest (S3 object) with model attributes including:

References

Hansen, Bruce E. 1992. “The likelihood ratio test under nonstandard conditions: testing the Markov switching model of GNP.” Journal of applied Econometrics 7 (S1): S61–S82.

Hansen, Bruce E. 1996. “Erratum: The likelihood ratio test under nonstandard conditions: testing the Markov switching model of GNP.” Journal of applied Econometrics 7 (S1): S61–S82.

Examples

# --------------------------- Use simulated process ----------------------------
set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n     = 200, 
                mu    = c(5,1),
                sigma = c(1,1),
                phi   = c(0.5),
                k     = 2,
                P     = rbind(c(0.90, 0.10),
                              c(0.10, 0.90)))

# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)

hlrt_control  <- list(ix          = 1, 
                      gridsize    = 7,
                      pgrid_from  = 0.05,
                      pgrid_by    = 0.05,
                      pgrid_to    = 0.95,
                      mugrid_from = 0,
                      mugrid_by   = 1)


  hlrt <- HLRTest(y_ms_simu$y, p = 1, control = hlrt_control)
  summary(hlrt)



HLR param search

Description

This function performs the parameter grid search needed for the likelihood ratio test described in Hansen (1992).

Usage

HLRparamSearch(gx, gp, gq, b, null, HLR_opt_ls)

Arguments

gx

matrix/grid containing values for switching parameters in second regime.

gp

matrix/grid containing values for probability of going from regime 1 at (t) to regime 1 at (t+1).

gq

matrix/grid containing values for probability of going from regime 2 at (t) to regime 2 at (t+1) (if not bounded to be 1-p i.e., qbound=FALSE).

b

vector of initial parameter values of restricted model.

null

vector with likelihood under the null hypothesis.

HLR_opt_ls

List with model properties and test controls defined in HLRTest().

Value

List which contains:


Hidden Markov model

Description

This function estimates a Hidden Markov model with k regimes.

Usage

HMmdl(Y, k, Z = NULL, control = list())

Arguments

Y

a (T x q) matrix of observations.

k

integer determining the number of regimes to use in estimation. Must be greater than or equal to 2.

Z

an otpional (T x qz) matrix of exogenous regressors. Default is NULL.

control

List with model options including:

  • getSE: Boolean. If TRUE standard errors are computed and returned. If FALSE standard errors are not computed. Default is TRUE.

  • msmu: Boolean. If TRUE model is estimated with switch in mean. If FALSE model is estimated with constant mean. Default is TRUE.

  • msvar: Boolean. If TRUE model is estimated with switch in variance. If FALSE model is estimated with constant variance. Default is TRUE.

  • init_theta: vector of initial values. vector must contain (1 x q) vector mu, vech(sigma), and vec(P) where sigma is a (q x q) covariance matrix.This is optional. Default is NULL, in which case initVals_MSARmdl is used to generate initial values.

  • method: string determining which method to use. Options are 'EM' for EM algorithm or 'MLE' for Maximum Likelihood Estimation. Default is 'EM'.

  • maxit: integer determining the maximum number of EM iterations.

  • thtol: double determining the convergence criterion for the absolute difference in parameter estimates theta between iterations. Default is 1e-6.

  • maxit_converge: integer determining the maximum number of initial values attempted until solution is finite. For example, if parameters in theta or logLike are NaN another set of initial values (up to maxit_converge) is attempted until finite values are returned. This does not occur frequently for most types of data but may be useful in some cases. Once finite values are obtained, this counts as one iteration towards use_diff_init. Default is 500.

  • use_diff_init: integer determining how many different initial values to try (that do not return NaN; see maxit_converge). Default is 1.

  • mle_variance_constraint: double used to determine the lower bound on the smallest eigenvalue for the covariance matrix of each regime. Default is 1e-3.

  • mle_theta_low: Vector with lower bounds on parameters (Used only if method = "MLE"). Default is NULL.

  • mle_theta_upp: Vector with upper bounds on parameters (Used only if method = "MLE"). Default is NULL.

Value

List of class HMmdl (S3 object) with model attributes including:

References

Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..

Hamilton, James D. 1990. “Analysis of time series subject to changes in regime.” Journal of econometrics, 45 (1-2): 39–70.

Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.

See Also

Nmdl


Estimation of Hidden Markov model by EM Algorithm

Description

Estimate Hidden Markov model by EM algorithm. This function is used by HMmdl which organizes the output and takes raw data as input.

Usage

HMmdl_em(theta_0, mdl, k, optim_options)

Arguments

theta_0

vector with initial values for parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

optim_options

List with optimization options.

Value

List with model results.

References

Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38.


Hidden Markov model maximum likelihood estimation

Description

This function computes estimate a Hidden Markov model using MLE.

Usage

HMmdl_mle(theta_0, mdl_in, k, optim_options)

Arguments

theta_0

vector containing initial values to use in optimization

mdl_in

List with model properties (can be obtained from estimating linear model i.e., using ARmdl)

k

integer determining the number of regimes

optim_options

List containing

  • maxit: maximum number of iterations.

  • thtol: convergence criterion.

Value

List with model attributes


Monte Carlo Likelihood Ratio Test

Description

This function performs the Local Monte Carlo likelihood ratio test (LMC-LRT) proposed in Rodriguez-Rondon & Dufour (2024). As discussed in their work, this test can be applied in very general settings and can be used to compare varioous regimes under the null and under the alternative.

Usage

LMCLRTest(Y, p, k0, k1, Z = NULL, control = list())

Arguments

Y

Series to be tested. Must be a (T x q) matrix where T is the number of time observations and q is the number of variables.

p

Number of autoregressive lags. Must be greater than or equal to 0.

k0

Number of regimes under null hypothesis. Must be greater than or equal to 1.

k1

Number of regimes under alternative hypothesis. Must be greater than k0.

Z

Exogenous regressors. Optional input and default is NULL. When used, it should be a (T x qz) matrix where T is the number of time observations and q is the number of exogenous variables.

control

List with test procedure options including:

  • N: Integer determining the number of Monte Carlo simulations. Default is set to 99 as in paper.

  • burnin: Number of simulated observations to remove from beginning. Default is 100.

  • converge_check: String or NULL determining if convergence of model(s) should be verified. Allowed inputs are: "null", "alt", "both", or NULL. If NULL (default) no model convergence is verified.

  • workers: Integer determining the number of workers to use for parallel computing version of test. Note that parallel pool must already be open. Default is 0.

  • mdl_h0_control: List with restricted model options. See Nmdl, ARmdl, VARmdl, HMmdl, MSARmdl, or MSVARmdl documentation for available and default values.

  • mdl_h1_control: List with unrestricted model options. See HMmdl, MSARmdl, or MSVARmdl documentation for available and default values.

  • use_diff_init_sim: Value which determines the number of initial values to use when estimating models for null distribution. Default is set to use the same as specified in mdl_h0_control and mdl_h1_control.

Value

List of class LMCLRTest (S3 object) with attributes including:

References

Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.

Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2024. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.

Examples

set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n     = 200, 
                mu    = c(5,10),
                sigma = c(1,4),
                phi   = c(0.5),
                k     = 2,
                P     = rbind(c(0.90, 0.10),
                              c(0.10, 0.90)))

# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)


# ------ MS-AR example ----- #
# Set test procedure options
lmc_control = list(N = 19,
                   burnin = 100,
                   converge_check = NULL,
                   mdl_h0_control = list(const  = TRUE, 
                                         getSE  = TRUE),
                   mdl_h1_control = list(msmu   = TRUE, 
                                         msvar  = TRUE,
                                         getSE  = TRUE,
                                         method = "EM",
                                         use_diff_init = 1))


  lmctest <- LMCLRTest(y_ms_simu$y, p = 1, k0 = 1 , k1 = 2, control = lmc_control)
  summary(lmctest)


Likelihood Ratio Test Statistic Sample Distribution

Description

This function simulates the sample distribution under the null hypothesis.

Usage

LR_samp_dist(mdl_h0, k1, N, burnin, Z, mdl_h0_control, mdl_h1_control)

Arguments

mdl_h0

List with restricted model properties.

k1

integer specifying the number of regimes under the alternative hypothesis.

N

integer specifying the number of replications.

burnin

integer specifying the number of observations to drop from beginning of simulation.

mdl_h0_control

List with controls/options used to estimate restricted model.

mdl_h1_control

List with controls/options used to estimate unrestricted model.

Value

vector of simulated LRT statistics

References

Rodriguez Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.

Rodriguez Rondon, Gabriel and Jean-Marie Dufour. 2022. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.


Monte Carlo Likelihood Ratio Test sample distribution (parallel version)

Description

This function simulates the sample distribution under the null hypothesis using a parallel pool.

Usage

LR_samp_dist_par(
  mdl_h0,
  k1,
  N,
  burnin,
  Z,
  mdl_h0_control,
  mdl_h1_control,
  workers
)

Arguments

mdl_h0

List with restricted model properties.

k1

integer specifying the number of regimes under the alternative hypothesis.

N

integer specifying the number of replications.

burnin

integer specifying the number of observations to drop from beginning of simulation.

mdl_h0_control

List with controls/options used to estimate restricted model.

mdl_h1_control

List with controls/options used to estimate unrestricted model.

workers

Integer determining the number of workers to use for parallel computing version of test. Note that parallel pool must already be open.

Value

vector of simulated LRT statistics

References

Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.

Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2023. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.


Monte Carlo P-value

Description

This function computes the Monte Carlo P-value.

Usage

MCpval(test_stat, null_vec, type = "geq")

Arguments

test_stat

Test statistic under the alternative (e.g. S_0).

null_vec

A (N x 1) vector with test statistic under the null hypothesis.

type

String determining type of test. options are: "geq" for right-tail test, "leq" for left-tail test, "abs" for absolute value test and "two-tail" for two-tail test.

Value

MC p-value of test

References

Dufour, Jean-Marie 2006. "Monte Carlo tests with nuisance parameters: A general approach to finite-sample inference and nonstandard asymptotics". Journal of Econometrics, 133(2), 443-477.

Dufour, Jean-Marie, and Richard Luger. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models". Econometric Reviews, 36(6-9), 713-727.


Maximized Monte Carlo Likelihood Ratio Test

Description

This function performs the Maximized Monte Carlo likelihood ratio test (MMC-LRT) proposed in Rodriguez-Rondon & Dufour (2024).

Usage

MMCLRTest(Y, p, k0, k1, Z = NULL, control = list())

Arguments

Y

Series to be tested. Must be a (T x q) matrix where T is the number of time observations and q is the number of variables.

p

Number of autoregressive lags. Must be greater than or equal to 0.

k0

Number of regimes under null hypothesis. Must be greater than or equal to 1.

k1

Number of regimes under alternative hypothesis. Must be greater than k0.

Z

Exogenous regressors. Optional input and default is NULL. When used, it should be a (T x qz) matrix where T is the number of time observations and q is the number of exogenous variables.

control

List with test procedure options including:

  • N: Integer determining the number of Monte Carlo simulations. Default is set to 99 as in paper.

  • burnin: Number of simulated observations to remove from beginning. Default is 100.

  • converge_check: String of NULL determining if convergence of model(s) should be verified. Allowed inputs are: "null", "alt", "both", or NULL. If NULL (default) no model convergence is verified.

  • workers: Integer determining the number of workers to use for parallel computing version of test. Note that parallel pool must already be open. Default is 0.

  • type: String that determines the type of optimization algorithm used. Arguments allowed are: "pso", "GenSA", and "GA". Default is "pso".

  • eps: Double determining the constant value that defines a consistent set for search. Default is 0.1.

  • CI_union: Boolean determining if union of set determined by eps and confidence set should be used to define consistent set for search. Default is TRUE.

  • lambda: Double determining penalty on nonlinear constraint. Default is 100.

  • stationary_constraint: Boolean determining if only stationary solutions are considered (if TRUE) or not (if FALSE). Default is TRUE.

  • phi_low: Vector with lower bound for autoregressive parameters when optimizing. Default is NULL.

  • phi_upp: Vector with upper bound for autoregressive parameters when optimizing. Default is NULL.

  • P_low: Value with lower bound for transition probabilities when optimizing. Default is 0.

  • P_upp: Value with upper bound for transition probabilities when optimizing. Default is 1.

  • variance_constraint: Double used to determine the lower bound for variance in parameter set for search. Value should be between 0 and 1 as it is multiplied by consistent point estimates of variances. Default is 0.01 (i.e., 1% of consistent point estimates.

  • silence: Boolean determining if optimization steps should be silenced (if TRUE) or not (if FALSE). Default is FALSE.

  • threshold_stop: Double determining the global optimum of function. Default is 1.

  • mdl_h0_control: List with restricted model options. See Nmdl, ARmdl, VARmdl, HMmdl, MSARmdl, or MSVARmdl documentation for available and default values.

  • mdl_h1_control: List with unrestricted model options. See HMmdl, MSARmdl, or MSVARmdl documentation for available and default values.

  • use_diff_init_sim: Value which determines the number of initial values to use when estimating models for null distribution. Default is set to use the same as specified in mdl_h0_control and mdl_h1_control.

  • optim_control: List with optimization algorithm options. See psoptim, GenSA, ga. Default is to set list(maxit = 200) so that maximum number of iterations is 200.

Value

List of class LMCLRTest (S3 object) with attributes including:

References

Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.

Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2024. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.

Examples


set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n     = 200, 
                mu    = c(5,10),
                sigma = c(1,4),
                phi   = c(0.5),
                k     = 2,
                P     = rbind(c(0.90, 0.10),
                              c(0.10, 0.90)))

# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)


# Set test procedure options
mmc_control = list(N = 19,
                   burnin = 100,
                   converge_check = NULL,
                   eps = 0.1,
                   CI_union = TRUE,
                   silence = FALSE,
                   threshold_stop = 0.05 + 1e-6,
                   type = "pso",
                   maxit = 100,
                   mdl_h0_control = list(const  = TRUE, 
                                         getSE  = TRUE),
                   mdl_h1_control = list(msmu   = TRUE, 
                                         msvar  = TRUE,
                                         getSE  = TRUE,
                                         method = "EM",
                                         use_diff_init = 1))

  MMCtest <- MMCLRTest(y_ms_simu$y, p = 1 , k0 = 1 , k1 = 2, control = mmc_control)
  summary(MMCtest)





Monte Carlo Likelihood Ratio Test P-value Function

Description

This function computes the Maximum Monte Carlo P-value.

Usage

MMCLRpval_fun(
  theta_h0,
  mdl_h0,
  k1,
  LT_h1,
  N,
  burnin,
  workers,
  lambda,
  stationary_constraint,
  thtol,
  Z,
  exog,
  mdl_h0_control,
  mdl_h1_control
)

Arguments

theta_h0

vector of parameter values under the null being considered.

mdl_h0

List with restricted model properties.

k1

integer determining the number of regimes under the alternative.

LT_h1

double specifying maximum log likelihood under alternative.

N

integer specifying the number of replications.

burnin

integer specifying the number of observations to drop from beginning of simulation.

workers

Integer determining the number of workers to use for parallel computing version of test. Note that parallel pool must already be open.

lambda

Double determining penalty on nonlinear constraint.

stationary_constraint

Boolean determining if only stationary solutions are considered (if TRUE) or not (if FALSE).

thtol

double determining the convergence criterion used during estimation.

mdl_h0_control

List with controls/options used to estimate restricted model.

mdl_h1_control

List with controls/options used to estimate unrestricted model.

Value

MMC p-value


Monte Carlo Likelihood Ratio Test P-value Function

Description

This function computes the (negative) Maximum Monte Carlo P-value.

Usage

MMCLRpval_fun_min(
  theta,
  mdl_h0,
  k1,
  LT_h1,
  N,
  burnin,
  workers,
  lambda,
  stationary_constraint,
  thtol,
  Z,
  exog,
  mdl_h0_control,
  mdl_h1_control
)

Arguments

theta

vector of parameter values being considered.

mdl_h0

List with restricted model properties.

k1

integer determining the number of regimes under the alternative.

LT_h1

double specifying maximum log likelihood under alternative.

N

integer specifying the number of replications.

burnin

integer specifying the number of observations to drop from beginning of simulation.

workers

Integer determining the number of workers to use for parallel computing version of test. Note that parallel pool must already be open.

lambda

Double determining penalty on nonlinear constraint.

stationary_constraint

Boolean determining if only stationary solutions are considered (if TRUE) or not (if FALSE).

thtol

double determining the convergence criterion used during estimation.

mdl_h0_control

List with controls/options used to estimate restricted model.

mdl_h1_control

List with controls/options used to estimate unrestricted model.

Value

negative MMC p-value


MMC nuisance parameter bounds

Description

This function is used to determine the lower and upper bounds for the MMC LRT parameter search.

Usage

MMC_bounds(mdl_h0, con)

Arguments

mdl_h0

List with restricted model properties.

con

List with control options provided to MMC LRT procedure.

Value

List with theta_low, vector of parameter lower bounds, and theta_upp, vector of parameter upper bounds.

References

Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2022. "Simulation-Based Inference for Markov Switching Models” JSM Proceedings, Business and Economic Statistics Section: American Statistical Association.

Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2024. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.


Markov-switching autoregressive model

Description

This function estimates a Markov-switching autoregressive model

Usage

MSARXmdl(Y, p, k, Z, control = list())

Arguments

Y

a (T x 1) vector with observational data.

p

integer for the number of lags to use in estimation. Must be greater than or equal to 1.

k

integer for the number of regimes to use in estimation. Must be greater than or equal to 2.

Z

a (T x qz) matrix of exogenous regressors.

control

List with model options including:

  • getSE: Boolean. If TRUE standard errors are computed and returned. If FALSE standard errors are not computed. Default is TRUE.

  • msmu: Boolean. If TRUE model is estimated with switch in mean. If FALSE model is estimated with constant mean. Default is TRUE.

  • msvar: Boolean. If TRUE model is estimated with switch in variance. If FALSE model is estimated with constant variance. Default is TRUE.

  • init_theta: vector of initial values. vector must contain (1 x q) vector mu, vech(sigma), and vec(P) where sigma is a (q x q) covariance matrix.This is optional. Default is NULL, in which case initVals_MSARmdl is used to generate initial values.

  • method: string determining which method to use. Options are 'EM' for EM algorithm or 'MLE' for Maximum Likelihood Estimation. Default is 'EM'.

  • maxit: integer determining the maximum number of EM iterations.

  • thtol: double determining the convergence criterion for the absolute difference in parameter estimates theta between iterations. Default is 1e-6.

  • maxit_converge: integer determining the maximum number of initial values attempted until solution is finite. For example, if parameters in theta or logLike are NaN another set of initial values (up to maxit_converge) is attempted until finite values are returned. This does not occur frequently for most types of data but may be useful in some cases. Once finite values are obtained, this counts as one iteration towards use_diff_init. Default is 500.

  • use_diff_init: integer determining how many different initial values to try (that do not return NaN; see maxit_converge). Default is 1.

  • mle_stationary_constraint: Boolean determining if only stationary solutions are considered (if TRUE) or not (if FALSE). Default is TRUE.

  • mle_variance_constraint: Double used to determine the lower bound for variance in each regime. Value should be between 0 and 1 as it is multiplied by single regime variance. Default is 0.01 (i.e., 1% of single regime variance.

  • mle_theta_low: Vector with lower bounds on parameters (Used only if method = "MLE"). Default is NULL.

  • mle_theta_upp: Vector with upper bounds on parameters (Used only if method = "MLE"). Default is NULL.

Value

List of class MSARmdl (S3 object) with model attributes including:

References

Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..

Hamilton, James D. 1990. “Analysis of time series subject to changes in regime.” Journal of econometrics, 45 (1-2): 39–70.

See Also

ARmdl

Examples

# --------------------------- Use simulated process ----------------------------
set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n     = 200, 
                mu    = c(5,10),
                sigma = c(1,4),
                phi   = c(0.5),
                k     = 2,
                P     = rbind(c(0.90, 0.10),
                              c(0.10, 0.90)))

# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)

# Set options for model estimation
control <- list(msmu   = TRUE, 
                msvar  = TRUE, 
                method = "EM",
                use_diff_init = 1)

# Estimate model

  ms_mdl <- MSARmdl(y_ms_simu$y, p = 1, k = 2, control = control)
  summary(ms_mdl)





Estimation of Markov-switching ARX model by EM Algorithm

Description

Estimate Markov-switching ARX model by EM algorithm. This function is used by MSARmdl which organizes the output and takes raw data as input.

Usage

MSARXmdl_em(theta_0, mdl, k, optim_options)

Arguments

theta_0

vector with initial values for parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

optim_options

List with optimization options.

Value

List with model results.

References

Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38.

Hamilton, James D. 1990. “Analysis of time series subject to changes in regime.” Journal of econometrics, 45 (1-2): 39–70.


Markov-switching autoregressive model

Description

This function estimates a Markov-switching autoregressive model

Usage

MSARmdl(Y, p, k, control = list())

Arguments

Y

(T x 1) vector with observational data.

p

integer for the number of lags to use in estimation. Must be greater than or equal to 1.

k

integer for the number of regimes to use in estimation. Must be greater than or equal to 2.

control

List with model options including:

  • getSE: Boolean. If TRUE standard errors are computed and returned. If FALSE standard errors are not computed. Default is TRUE.

  • msmu: Boolean. If TRUE model is estimated with switch in mean. If FALSE model is estimated with constant mean. Default is TRUE.

  • msvar: Boolean. If TRUE model is estimated with switch in variance. If FALSE model is estimated with constant variance. Default is TRUE.

  • init_theta: vector of initial values. vector must contain (1 x q) vector mu, vech(sigma), and vec(P) where sigma is a (q x q) covariance matrix.This is optional. Default is NULL, in which case initVals_MSARmdl is used to generate initial values.

  • method: string determining which method to use. Options are 'EM' for EM algorithm or 'MLE' for Maximum Likelihood Estimation. Default is 'EM'.

  • maxit: integer determining the maximum number of EM iterations.

  • thtol: double determining the convergence criterion for the absolute difference in parameter estimates theta between iterations. Default is 1e-6.

  • maxit_converge: integer determining the maximum number of initial values attempted until solution is finite. For example, if parameters in theta or logLike are NaN another set of initial values (up to maxit_converge) is attempted until finite values are returned. This does not occur frequently for most types of data but may be useful in some cases. Once finite values are obtained, this counts as one iteration towards use_diff_init. Default is 500.

  • use_diff_init: integer determining how many different initial values to try (that do not return NaN; see maxit_converge). Default is 1.

  • mle_stationary_constraint: Boolean determining if only stationary solutions are considered (if TRUE) or not (if FALSE). Default is TRUE.

  • mle_variance_constraint: Double used to determine the lower bound for variance in each regime. Value should be between 0 and 1 as it is multiplied by single regime variance. Default is 0.01 (i.e., 1% of single regime variance.

  • mle_theta_low: Vector with lower bounds on parameters (Used only if method = "MLE"). Default is NULL.

  • mle_theta_upp: Vector with upper bounds on parameters (Used only if method = "MLE"). Default is NULL.

Value

List of class MSARmdl (S3 object) with model attributes including:

References

Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..

Hamilton, James D. 1990. “Analysis of time series subject to changes in regime.” Journal of econometrics, 45 (1-2): 39–70.

See Also

ARmdl

Examples

# --------------------------- Use simulated process ----------------------------
set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n     = 200, 
                mu    = c(5,10),
                sigma = c(1,4),
                phi   = c(0.5),
                k     = 2,
                P     = rbind(c(0.90, 0.10),
                              c(0.10, 0.90)))

# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)

# Set options for model estimation
control <- list(msmu   = TRUE, 
                msvar  = TRUE, 
                method = "EM",
                use_diff_init = 1)

# Estimate model

  ms_mdl <- MSARmdl(y_ms_simu$y, p = 1, k = 2, control = control)
  summary(ms_mdl)





Estimation of Markov-switching autoregressive model by EM Algorithm

Description

Estimate Markov-switching autoregressive model by EM algorithm. This function is used by MSARmdl which organizes the output and takes raw data as input.

Usage

MSARmdl_em(theta_0, mdl, k, optim_options)

Arguments

theta_0

vector with initial values for parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

optim_options

List with optimization options.

Value

List with model results.

References

Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38.

Hamilton, James D. 1990. “Analysis of time series subject to changes in regime.” Journal of econometrics, 45 (1-2): 39–70.


Markov-switching autoregressive maximum likelihood estimation

Description

This function computes estimate a Markov-switching autoregressive model using MLE.

Usage

MSARmdl_mle(theta_0, mdl_in, k, optim_options)

Arguments

theta_0

vector containing initial values to use in optimization

mdl_in

List with model properties (can be obtained from estimating linear model i.e., using ARmdl)

k

integer determining the number of regimes

optim_options

List containing

  • maxit: maximum number of iterations.

  • thtol: convergence criterion.

Value

List with model attributes


Markov-switching vector autoregressive model

Description

This function estimates a Markov-switching vector autoregressive model

Usage

MSVARXmdl(Y, p, k, Z, control = list())

Arguments

Y

(T x q) vector with observational data.

p

integer for the number of lags to use in estimation. Must be greater than or equal to 0.

k

integer for the number of regimes to use in estimation. Must be greater than or equal to 2.

Z

a (T x qz) matrix of exogenous regressors.

control

List with optimization options including:

  • getSE: Boolean. If TRUE standard errors are computed and returned. If FALSE standard errors are not computed. Default is TRUE.

  • msmu: Boolean. If TRUE model is estimated with switch in mean. If FALSE model is estimated with constant mean. Default is TRUE.

  • msvar: Boolean. If TRUE model is estimated with switch in variance. If FALSE model is estimated with constant variance. Default is TRUE.

  • init_theta: vector of initial values. vector must contain (1 x q) vector mu, vech(sigma), and vec(P) where sigma is a (q x q) covariance matrix. This is optional. Default is NULL, in which case initVals_MSARmdl is used to generate initial values.

  • method: string determining which method to use. Options are 'EM' for EM algorithm or 'MLE' for Maximum Likelihood Estimation. Default is 'EM'.

  • maxit: integer determining the maximum number of EM iterations.

  • thtol: double determining the convergence criterion for the absolute difference in parameter estimates theta between iterations. Default is 1e-6.

  • maxit_converge: integer determining the maximum number of initial values attempted until solution is finite. For example, if parameters in theta or logLike are NaN another set of initial values (up to maxit_converge) is attempted until finite values are returned. This does not occur frequently for most types of data but may be useful in some cases. Once finite values are obtained, this counts as one iteration towards use_diff_init. Default is 500.

  • use_diff_init: integer determining how many different initial values to try (that do not return NaN; see maxit_converge). Default is 1.

  • mle_stationary_constraint: Boolean determining if only stationary solutions are considered (if TRUE) or not (if FALSE). Default is TRUE.

  • mle_variance_constraint: double used to determine the lower bound on the smallest eigenvalue for the covariance matrix of each regime. Default is 1e-3.

  • mle_theta_low: Vector with lower bounds on parameters (Used only if method = "MLE"). Default is NULL.

  • mle_theta_upp: Vector with upper bounds on parameters (Used only if method = "MLE"). Default is NULL.

Value

List of class MSVARmdl (S3 object) with model attributes including:

List with model characteristics

References

Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..

Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.

See Also

VARmdl

Examples

set.seed(123)
# Define DGP of MS VAR process
mdl_msvar2 <- list(n     = 200, 
                   p     = 1,
                   q     = 2,
                   mu    = rbind(c(5, -2),
                                 c(10, 2)),
                   sigma = list(rbind(c(5.0, 1.5),
                                      c(1.5, 1.0)),
                                rbind(c(7.0, 3.0),
                                      c(3.0, 2.0))),
                   phi   = rbind(c(0.50, 0.30),
                                 c(0.20, 0.70)),
                   k     = 2,
                   P     = rbind(c(0.90, 0.10),
                                 c(0.10, 0.90)))

# Simulate process using simuMSVAR() function
y_msvar_simu <- simuMSVAR(mdl_msvar2)

# Set options for model estimation
control <- list(msmu   = TRUE, 
                msvar  = TRUE,
                method = "EM",
                use_diff_init = 1)
                
# Estimate model

  y_msvar_mdl <- MSVARmdl(y_msvar_simu$y, p = 1, k = 2, control = control)
  summary(y_msvar_mdl)


Estimation of Markov-switching VARX model by EM Algorithm

Description

Estimate Markov-switching VARX model by EM algorithm. This function is used by MSVARmdl which organizes the output and takes raw data as input.

Usage

MSVARXmdl_em(theta_0, mdl, k, optim_options)

Arguments

theta_0

vector with initial values for parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

optim_options

List with optimization options.

Value

List with model results.

References

Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38.

Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.


Markov-switching vector autoregressive model

Description

This function estimates a Markov-switching vector autoregressive model

Usage

MSVARmdl(Y, p, k, control = list())

Arguments

Y

(T x q) vector with observational data.

p

integer for the number of lags to use in estimation. Must be greater than or equal to 0.

k

integer for the number of regimes to use in estimation. Must be greater than or equal to 2.

control

List with optimization options including:

  • getSE: Boolean. If TRUE standard errors are computed and returned. If FALSE standard errors are not computed. Default is TRUE.

  • msmu: Boolean. If TRUE model is estimated with switch in mean. If FALSE model is estimated with constant mean. Default is TRUE.

  • msvar: Boolean. If TRUE model is estimated with switch in variance. If FALSE model is estimated with constant variance. Default is TRUE.

  • init_theta: vector of initial values. vector must contain (1 x q) vector mu, vech(sigma), and vec(P) where sigma is a (q x q) covariance matrix. This is optional. Default is NULL, in which case initVals_MSARmdl is used to generate initial values.

  • method: string determining which method to use. Options are 'EM' for EM algorithm or 'MLE' for Maximum Likelihood Estimation. Default is 'EM'.

  • maxit: integer determining the maximum number of EM iterations.

  • thtol: double determining the convergence criterion for the absolute difference in parameter estimates theta between iterations. Default is 1e-6.

  • maxit_converge: integer determining the maximum number of initial values attempted until solution is finite. For example, if parameters in theta or logLike are NaN another set of initial values (up to maxit_converge) is attempted until finite values are returned. This does not occur frequently for most types of data but may be useful in some cases. Once finite values are obtained, this counts as one iteration towards use_diff_init. Default is 500.

  • use_diff_init: integer determining how many different initial values to try (that do not return NaN; see maxit_converge). Default is 1.

  • mle_stationary_constraint: Boolean determining if only stationary solutions are considered (if TRUE) or not (if FALSE). Default is TRUE.

  • mle_variance_constraint: double used to determine the lower bound on the smallest eigenvalue for the covariance matrix of each regime. Default is 1e-3.

  • mle_theta_low: Vector with lower bounds on parameters (Used only if method = "MLE"). Default is NULL.

  • mle_theta_upp: Vector with upper bounds on parameters (Used only if method = "MLE"). Default is NULL.

Value

List of class MSVARmdl (S3 object) with model attributes including:

List with model characteristics

References

Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38..

Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.

See Also

VARmdl

Examples

set.seed(123)
# Define DGP of MS VAR process
mdl_msvar2 <- list(n     = 200, 
                   p     = 1,
                   q     = 2,
                   mu    = rbind(c(5, -2),
                                 c(10, 2)),
                   sigma = list(rbind(c(5.0, 1.5),
                                      c(1.5, 1.0)),
                                rbind(c(7.0, 3.0),
                                      c(3.0, 2.0))),
                   phi   = rbind(c(0.50, 0.30),
                                 c(0.20, 0.70)),
                   k     = 2,
                   P     = rbind(c(0.90, 0.10),
                                 c(0.10, 0.90)))

# Simulate process using simuMSVAR() function
y_msvar_simu <- simuMSVAR(mdl_msvar2)

# Set options for model estimation
control <- list(msmu   = TRUE, 
                msvar  = TRUE,
                method = "EM",
                use_diff_init = 1)
                
# Estimate model

  y_msvar_mdl <- MSVARmdl(y_msvar_simu$y, p = 1, k = 2, control = control)
  summary(y_msvar_mdl)


Estimation of Markov-switching vector autoregressive model by EM Algorithm

Description

Estimate Markov-switching vector autoregressive model by EM algorithm. This function is used by MSVARmdl which organizes the output and takes raw data as input.

Usage

MSVARmdl_em(theta_0, mdl, k, optim_options)

Arguments

theta_0

vector with initial values for parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

optim_options

List with optimization options.

Value

List with model results.

References

Dempster, A. P., N. M. Laird, and D. B. Rubin. 1977. “Maximum Likelihood from Incomplete Data via the EM Algorithm.” Journal of the Royal Statistical Society. Series B 39 (1): 1–38.

Krolzig, Hans-Martin. 1997. “The markov-switching vector autoregressive model.”. Springer.


Markov-switching vector autoregressive maximum likelihood estimation

Description

This function computes estimate a Markov-switching vector autoregressive model using MLE.

Usage

MSVARmdl_mle(theta_0, mdl_in, k, optim_options)

Arguments

theta_0

vector containing initial values to use in optimization

mdl_in

List with model properties (can be obtained from estimating linear model i.e., using VARmdl)

k

integer determining the number of regimes

optim_options

List containing

  • maxit: maximum number of iterations.

  • thtol: convergence criterion.

Value

List with model attributes


Normal distribution model

Description

This function estimates a univariate or multivariate normally distributed model. This can be used for the null hypothesis of a linear model against an alternative hypothesis of a HMM with k regimes.

Usage

Nmdl(Y, Z = NULL, control = list())

Arguments

Y

a (T x q) matrix of observations.

Z

an otpional (T x qz) matrix of exogenous regressors. Default is NULL.

control

List with model options including:

  • const: Boolean determining whether to estimate model with constant if TRUE or not if FALSE. Default is TRUE.

  • getSE: Boolean determining whether to compute standard errors of parameters if TRUE or not if FALSE. Default is TRUE.

Value

List of class Nmdl (S3 object) with model attributes including:

Examples

set.seed(1234)

# ----- Univariate ----- # 
# Define DGP 
mdl_norm <- list(n     = 1000, 
                 q     = 1,
                 mu    = as.matrix(5),
                 sigma = as.matrix(5.0))

# Simulate process using simuNorm() function
y_norm_simu <- simuNorm(mdl_norm)

# estimate parameters
y_norm_mdl <- Nmdl(y_norm_simu$y)
summary(y_norm_mdl)


# ----- Multivariate ----- # 
# Define DGP 
mdl_norm <- list(n     = 1000, 
                 q     = 2,
                 mu    = c(5, -2),
                 sigma = rbind(c(5.0, 1.5),
                               c(1.5, 1.0)))

# Simulate process using simuNorm() function
y_norm_simu <- simuNorm(mdl_norm)

# estimate parameters
y_norm_mdl <- Nmdl(y_norm_simu$y)
summary(y_norm_mdl)

US GNP data 1947Q2 - 2024Q2

Description

US GNP data 1947Q2 - 2024Q2

Usage

USGNP

Format

This data is used in Rodriguez-Rondon & Dufour (2024). The series ranges from 1947Q2 to 2024Q2.

Date

Vector of dates

GNP

US GNP series

GNP_gr

log difference of US GNP series

Source

https://fred.stlouisfed.org/graph/?g=UKDQ

References

U.S. Bureau of Economic Analysis, Gross National Product [GNP], retrieved from FRED, Federal Reserve Bank of St. Louis; https://fred.stlouisfed.org/series/GNP, September, 2024.

Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2024. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.


US Real GDP data 1947Q2 - 2024Q2

Description

US Real GDP data 1947Q2 - 2024Q2

Usage

USRGDP

Format

This data is used in Rodriguez-Rondon & Dufour (2024). The series ranges from 1947Q2 to 2024Q2.

Date

Vector of dates

RGDP

US Real GDP series

RGDP_gr

log difference of US Real GDP series

Source

https://fred.stlouisfed.org/series/GDPC1

References

U.S. Bureau of Economic Analysis, Real Gross Domestic Product [GDPC1], retrieved from FRED, Federal Reserve Bank of St. Louis; https://fred.stlouisfed.org/series/GDPC1, September, 2024.

Rodriguez-Rondon, Gabriel and Jean-Marie Dufour. 2024. “Monte Carlo Likelihood Ratio Tests for Markov Switching Models.” Unpublished manuscript.


Vector X autoregressive model

Description

This function estimates a vector autoregresive model with p lags. This can be used for the null hypothesis of a linear model against an alternative hypothesis of a Markov switching vector autoregressive model with k regimes.

Usage

VARXmdl(Y, p, Z, control = list())

Arguments

Y

a (T x q) matrix of observations.

p

integer determining the number of autoregressive lags.

Z

a (T x qz) matrix of exogenous regressors.

control

List with model options including:

  • const: Boolean determining whether to estimate model with constant if TRUE or not if FALSE. Default is TRUE.

  • getSE: Boolean determining whether to compute standard errors of parameters if TRUE or not if FALSE. Default is TRUE.

Value

List of class VARmdl (S3 object) with model attributes including:

See Also

MSVARmdl

Examples

# ----- Bivariate VAR(1) process ----- #
set.seed(1234)
# Define DGP of VAR process
mdl_var <- list(n     = 1000, 
                p     = 1,
                q     = 2,
                mu    = c(5,-2),
                sigma = rbind(c(5.0, 1.5),
                              c(1.5, 1.0)),
                phi   = rbind(c(0.50, 0.30),
                              c(0.20, 0.70)))

# Simulate process using simuVAR() function
y_simu <- simuVAR(mdl_var)

# Set options for model estimation
control <- list(const  = TRUE, 
                getSE  = TRUE)

# Estimate model
y_var_mdl <- VARmdl(y_simu$y, p = 2, control = control)
summary(y_var_mdl)

Vector autoregressive model

Description

This function estimates a vector autoregresive model with p lags. This can be used for the null hypothesis of a linear model against an alternative hypothesis of a Markov switching vector autoregressive model with k regimes.

Usage

VARmdl(Y, p, control = list())

Arguments

Y

a (T x q) matrix of observations.

p

integer determining the number of autoregressive lags.

control

List with model options including:

  • const: Boolean determining whether to estimate model with constant if TRUE or not if FALSE. Default is TRUE.

  • getSE: Boolean determining whether to compute standard errors of parameters if TRUE or not if FALSE. Default is TRUE.

Value

List of class VARmdl (S3 object) with model attributes including:

See Also

MSVARmdl

Examples

# ----- Bivariate VAR(1) process ----- #
set.seed(1234)
# Define DGP of VAR process
mdl_var <- list(n     = 1000, 
                p     = 1,
                q     = 2,
                mu    = c(5,-2),
                sigma = rbind(c(5.0, 1.5),
                              c(1.5, 1.0)),
                phi   = rbind(c(0.50, 0.30),
                              c(0.20, 0.70)))

# Simulate process using simuVAR() function
y_simu <- simuVAR(mdl_var)

# Set options for model estimation
control <- list(const  = TRUE, 
                getSE  = TRUE)

# Estimate model
y_var_mdl <- VARmdl(y_simu$y, p = 2, control = control)
summary(y_var_mdl)

Approximate CDF distribution

Description

This function obtains the parameters in eq. 16 of the CDF distribution needed for combining moment-based test statistics.

Usage

approxDistDL(Tsize, simdist_N)

Arguments

Tsize

Sample size.

simdist_N

Number of simulations to approximate CDF distribution.

Value

A (2 x 4) matrix with parameters of CDF distributions. The first row contains \gamma_0 for each moment and the second row contains \gamma_1 for each moment.

References

Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.


Loop for approxDistDL

Description

This function performs the loop in required in approxDistDL.

Usage

approx_dist_loop(SN2)

Arguments

SN2

A (T x 4) matrix of test-statistics.

Value

The test statistics from simulated data. Used for NLS to get params needed to combine p-values.

References

Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.


Autoregressive transition matrix

Description

This function converts a transition matrix to the transition matrix consistent with a Markov-switching autoregressive model.

Usage

arP(P, k, ar)

Arguments

P

original transition matrix.

k

integer determining the number of regimes.

ar

number of autoregressive lags.

Value

transformed transition matrix.


Autoregressive moment grid

Description

This function creates a grid of mean and variance consistent with a Markov-switching autoregressive model.

Usage

argrid_MSARmdl(mu, sig, k, ar, msmu, msvar)

Arguments

mu

vector (k x 1) of mu in each regime.

sig

vector (k x 1) of sigma in each regime.

k

integer determining the number of regimes.

ar

number of autoregressive lags.

msmu

Boolean indicator. If TRUE mean is subject to change. If FALSE mean is constant across regimes.

msvar

Boolean indicator. If TRUE variance is subject to change. If FALSE variance is constant across regimes.

Value

List with (M x ar+1) matrix of means for each regime M (where M = k^(ar+1)) and each time t,... t-ar, vector with variance for each regime M, and vector indicating the corresponded 1,..., k regime.


Vector autoregressive moment grid

Description

Creates grid of means and covariance matrices consistent with a Markov-switching vector autoregressive model.

Usage

argrid_MSVARmdl(mu, sigma, k, ar, msmu, msvar)

Arguments

mu

a (k x q) matrix of means in each regime (for k regimes and q time series).

sigma

list with k regime specific (q x q) covariance matrices.

k

integer determining the number of regimes.

ar

number of autoregressive lags.

msmu

Boolean indicator. If TRUE mean is subject to change. If FALSE mean is constant across regimes.

msvar

Boolean indicator. If TRUE variance is subject to change. If FALSE variance is constant across regimes.

Value

List with M regime specific (q x k) matrices of means, List with M regime specific covariance matrices, and vector indicating the corresponded 1,..., k regime.


Markov-switching autoregressive model residuals

Description

This function computes residuals of a Markov-switching autoregressive model.

Usage

calcResid_MSARXmdl(mdl, mu, k)

Arguments

mdl

List containing relevant parameters.

mu

Vector with mean in each regime.

k

number of regimes. Must be greater than or equal to 2.

Value

A (TxM) matrix of residuals in each regime M where M=k^(ar+1).


Markov-switching autoregressive model residuals

Description

This function computes residuals of a Markov-switching autoregressive model.

Usage

calcResid_MSARmdl(mdl, mu, k)

Arguments

mdl

List containing relevant parameters.

mu

Vector with mean in each regime.

k

number of regimes. Must be greater than or equal to 2.

Value

A (TxM) matrix of residuals in each regime M where M=k^(ar+1).


Markov-switching VARX model residuals

Description

This function computes residuals of a Markov-switching VARX model.

Usage

calcResid_MSVARXmdl(mdl, mu, k)

Arguments

mdl

List containing relevant parameters.

mu

Vector with mean in each regime.

k

Number of regimes. Must be greater than or equal to 2.

Value

List with M (Txq) matrices of residuals in each regime M where M=k^(ar+1).


Markov-switching vector autoregressive model residuals

Description

This function computes residuals of a Markov-switching vector autoregressive model.

Usage

calcResid_MSVARmdl(mdl, mu, k)

Arguments

mdl

List containing relevant parameters.

mu

Vector with mean in each regime.

k

Number of regimes. Must be greater than or equal to 2.

Value

List with M (Txq) matrices of residuals in each regime M where M=k^(ar+1).


Moment-based test statistics

Description

This function computes the four moment-based test statistics (eq. 11 - 14) discussed in Dufour & Luger 2017.

Usage

calc_DLmoments(ehat)

Arguments

ehat

A (T x 1) vector of restricted model residuals.

Value

Vector containing the four test statistics.

References

Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.


Test statistic for switch in mean only

Description

This function computes part of the test statistic given by eq. 2.5 of CHP 2014 when the alternative has switching mean only. The output is used in chpStat which computes the full test statistics.

Usage

calc_mu2t(mdl, rho, ltmt)

Arguments

mdl

List containing model attributes (see ARmdl).

rho

Number determining value of rho.

ltmt

List containing derivatives output from chpDmat.

Value

Part of test statistic given rho and hv value.

References

Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.


Test statistic for switch in mean and variance

Description

This function computes part of the test statistic given by eq. 2.5 of CHP 2014 when the alternative has switching mean and variance. The output is used in chpStat which computes the full test statistics.

Usage

calc_mu2t_mv(mdl, rho, ltmt, hv)

Arguments

mdl

List containing model attributes (see ARmdl).

rho

Number determining value of rho.

ltmt

List containing derivatives output from chpDmat.

hv

Number determining value of h.

Value

Part of test statistic given rho and hv value.

References

Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.


Carrasco, Hu, & Ploberger 2010 GNP data

Description

Carrasco, Hu, & Ploberger 2010 GNP data

Usage

chp10GNP

Format

This data is the extension of the GNP series used in CHP (2014), Econometrica. This series ranges from 1951Q2 to 2010Q4.

Date

Vector of dates

GNP

US GNP series

GNP_gr

log difference of US GNP series

Source

https://www.econometricsociety.org/content/supplement-optimal-test-markov-switching-parameters

References

Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.


Derivative matrix

Description

This function organizes the first and second derivatives of the log-likelihood.

Usage

chpDmat(mdl, msvar)

Arguments

mdl

List containing output from ARmdl.

msvar

Boolean indicator. If TRUE, there is a switch in variance. If FALSE only switch in mean is considered.

Value

List containing relevant first and second derivatives of log-likelihood function.

References

Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.


Test statistic for CHP 2014 parameter stability test

Description

This function computes the supTS and expTS test-statistics proposed in CHP 2014.

Usage

chpStat(mdl, rho_b, ltmt, msvar)

Arguments

mdl

List containing model attributes (see ARmdl).

rho_b

Number determining bounds for distribution of rh0 (i.e. rho ~ [-rho_b,rho_b]).

ltmt

List containing derivatives output from chpDmat.

msvar

Boolean indicator. If TRUE, there is a switch in variance. If FALSE only switch in mean is considered.

Value

A (2 x 1) vector with supTS test statistic as first element and expTS test-statistics as second element.

References

Carrasco, Marine, Liang Hu, and Werner Ploberger. 2014. “Optimal test for Markov switching parameters.” Econometrica 82 (2): 765–784.


Parameter vector & likelihood function used by HLRTest()

Description

This function combines parameters of restricted model with parameters of unrestricted model and then computes the likelihood using marklike().

Usage

clike(b, HLR_opt_ls)

Arguments

b

vector of parameters from restricted model.

HLR_opt_ls

List with model properties and test controls defined in HLRTest().

Value

Value of likelihood at each period t.


coef of a ARmdl object

Description

This is a method for the function coef() for objects of the class ARmdl.

Usage

## S3 method for class 'ARmdl'
coef(object, ...)

Arguments

object

an object for which the extraction of model coefficients is meaningful.

...

other arguments.

Value

vector of coefficients.


coef of a HMmdl object

Description

This is a method for the function coef() for objects of the class HMmdl.

Usage

## S3 method for class 'HMmdl'
coef(object, ...)

Arguments

object

an object for which the extraction of model coefficients is meaningful.

...

other arguments.

Value

vector of coefficients.


coef of a MSARmdl object

Description

This is a method for the function coef() for objects of the class MSARmdl.

Usage

## S3 method for class 'MSARmdl'
coef(object, ...)

Arguments

object

an object for which the extraction of model coefficients is meaningful.

...

other arguments.

Value

vector of coefficients.


coef of a MSVARmdl object

Description

This is a method for the function coef() for objects of the class MSVARmdl.

Usage

## S3 method for class 'MSVARmdl'
coef(object, ...)

Arguments

object

an object for which the extraction of model coefficients is meaningful.

...

other arguments.

Value

vector of coefficients.


coef of a Nmdl object

Description

This is a method for the function coef() for objects of the class Nmdl.

Usage

## S3 method for class 'Nmdl'
coef(object, ...)

Arguments

object

an object for which the extraction of model coefficients is meaningful.

...

other arguments.

Value

vector of coefficients.


coef of a VARmdl object

Description

This is a method for the function coef() for objects of the class VARmdl.

Usage

## S3 method for class 'VARmdl'
coef(object, ...)

Arguments

object

an object for which the extraction of model coefficients is meaningful.

...

other arguments.

Value

vector of coefficients.


Combine p-values

Description

This function is used to combine the four moment-based p-values as in eq. 17 and 18 of Dufour & Luger 2017.

Usage

combine_stat(stats, params, type)

Arguments

stats

A (l x 4) matrix where l is the number of moment-based test statistics.

params

A (2 x 4) matrix with parameters to combine test statistics. See approxDistDL.

type

String determining the type of method used to combine p-values. If set to "min" the min method of combining p-values is used as in Fisher 1932 and Pearson 1933. If set to "prod" the product of p-values is used as in Tippett 1931 and Wilkinson 1951.

Value

A (N x 1) vector with test statistics. The last element is the test statistic from observed data.

References

Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.

Tippett, L. 1931. "The Method of Statistics". London: Williams & Norgate.

Wilkinson, B. 1951. "A statistical consideration in psychological research." Psychology Bulletin 48:156–158.

Pearson, K. 1933. "On a method of determining whether a sample of size n supposed to have been drawn from a parent population having a known probability integral has probably been drawn at random". Biometrika 25:379–410.

Fisher, R. 1932. "Statistical Methods for Research Workers." Edinburgh: Oliver and Boyd.


Companion Matrix

Description

This function converts the (q x 1) vector of constants and (q x qp) matrix of autoregressive coefficients into (qp x qp) matrix belonging to the companion form

Usage

companionMat(phi, p, q)

Arguments

phi

matrix of dimension (q x qp) containing autoregressive coefficients.

p

integer for number of autoregressive lags.

q

integer for number of series.

Value

matrix of dimension (qp x qp) of companion form.


Computes test stat using new parameter vectors

Description

This function computes the LRT statistic.

Usage

compu_tstat(theta_h0, mdl_h0, LT_h1, p, q, k0, exog)

Arguments

theta_h0

estimated parameter values for restricted model.

mdl_h0

List with restricted model properties.

LT_h1

Double specifying maximum log likelihood under alternative.

p

integer specifying the number of autoregressive lags.

q

integer specifying the number of series.

k0

integer specifying the number of regimes under the null hypothesis.

Value

LRT statistic


Covariance to correlation matrix

Description

This function takes an (n x n) covariance matrix and returns the associated (n x n) correlation matrix.

Usage

cov2corr(cov_mat)

Arguments

cov_mat

A (n x n) covariance matrix.

Value

A (n x n) correlation matrix.


Covariance vech to matrix

Description

This function undoes the half-vectorization of a covariance matrix.

Usage

covar_unvech(sig, n)

Arguments

sig

A (n+1)*n/2 vector.

n

Integer determining shape of the original matrix.

Value

A (n x n) covariance matrix.


Covariance vech function

Description

This function returns the half-vectorization of an input matrix as a column vector.

Usage

covar_vech(mat)

Arguments

mat

A (n x n) covariance matrix.

Value

A (n+1)*n/2 column vector.


Gradient of likelihood function.

Description

this function computes the score vector.

Usage

dmclike(th, HLR_opt_ls)

Arguments

th

vector of parameter values.

HLR_opt_ls

List with model properties and test controls defined in HLRTest().

Value

vector with gradient of likelihood function for each parameter. Used in HLRpramSearch().


Estimate model for likelihood ratio test

Description

This function is used by the Monte Carlo testing procedures to estimate restricted and unrestricted models.

Usage

estimMdl(Y, p, q, k, Z = NULL, control = list())

Arguments

Y

Series to be tested. Must be a (T x q) matrix.

p

integer specifying the number of autoregressive lags.

q

integer specifying the number of series.

k

integer specifying the number of regimes.

Z

exogeneous regressors. Defualt is NULL.

control

List with control options for model estimation. For default values, see description of model being estimated.

Value

List with estimated model properties.


fitted values of a ARmdl object

Description

This is a method for the function fitted() for objects of the class ARmdl.

Usage

## S3 method for class 'ARmdl'
fitted(object, ...)

Arguments

object

an object for which the extraction of model fitted values is meaningful.

...

other arguments.

Value

matrix with fitted values


fitted values of a HMmdl object

Description

This is a method for the function fitted() for objects of the class HMmdl.

Usage

## S3 method for class 'HMmdl'
fitted(object, ...)

Arguments

object

an object for which the extraction of model fitted values is meaningful.

...

other arguments.

Value

matrix with fitted values


fitted values of a MSARmdl object

Description

This is a method for the function fitted() for objects of the class MSARmdl.

Usage

## S3 method for class 'MSARmdl'
fitted(object, ...)

Arguments

object

an object for which the extraction of model fitted values is meaningful.

...

other arguments.

Value

matrix with fitted values


fitted values of a MSVARmdl object

Description

This is a method for the function fitted() for objects of the class MSVARmdl.

Usage

## S3 method for class 'MSVARmdl'
fitted(object, ...)

Arguments

object

an object for which the extraction of model fitted values is meaningful.

...

other arguments.

Value

matrix with fitted values


fitted values of a Nmdl object

Description

This is a method for the function fitted() for objects of the class Nmdl.

Usage

## S3 method for class 'Nmdl'
fitted(object, ...)

Arguments

object

an object for which the extraction of model fitted values is meaningful.

...

other arguments.

Value

matrix with fitted values


fitted values of a VARmdl object

Description

This is a method for the function fitted() for objects of the class VARmdl.

Usage

## S3 method for class 'VARmdl'
fitted(object, ...)

Arguments

object

an object for which the extraction of model fitted values is meaningful.

...

other arguments.

Value

matrix with fitted values


Hessian matrix

Description

This function is used to obtain a numerical approximation of a Hessian matrix.

Usage

getHessian(mdl)

Arguments

mdl

List with model properties.

Value

Hessian matrix.


Hessian matrix of autoregressive model

Description

This function is used to obtain a numerical approximation of a Hessian matrix for an autoregressive model.

Usage

## S3 method for class 'ARmdl'
getHessian(mdl)

Arguments

mdl

List with model properties.

Value

Hessian matrix.


Hessian matrix of Hidden Markov model

Description

This function is used to obtain a numerical approximation of a Hessian matrix for a Hidden Markov model.

Usage

## S3 method for class 'HMmdl'
getHessian(mdl)

Arguments

mdl

List with model properties.

Value

Hessian matrix.


Hessian matrix of Markov-switching autoregressive model

Description

This function is used to obtain a numerical approximation of a Hessian matrix for a Markov-switching autoregressive model.

Usage

## S3 method for class 'MSARmdl'
getHessian(mdl)

Arguments

mdl

List with model properties.

Value

Hessian matrix.


Hessian matrix of Markov-switching vector autoregressive model

Description

This function is used to obtain a numerical approximation of a Hessian matrix for a Markov-switching vector autoregressive model.

Usage

## S3 method for class 'MSVARmdl'
getHessian(mdl)

Arguments

mdl

List with model properties.

Value

Hessian matrix.


Hessian matrix of normal model

Description

This function is used to obtain a numerical approximation of a Hessian matrix for a normally distributed model.

Usage

## S3 method for class 'Nmdl'
getHessian(mdl)

Arguments

mdl

List with model properties.

Value

Hessian matrix.


Hessian matrix of vector autoregressive model

Description

This function is used to obtain a numerical approximation of a Hessian matrix for a vector autoregressive model.

Usage

## S3 method for class 'VARmdl'
getHessian(mdl)

Arguments

mdl

List with model properties.

Value

Hessian matrix.


Hamilton 1984 & Hansen 1992 GNP data

Description

Hamilton 1984 & Hansen 1992 GNP data

Usage

hamilton84GNP

Format

This data set is used in Hansen (1992) to test the US GNP model proposed by Hamilton (1989). This series ranges from 1951Q2 to 1984Q4.

Date

Vector of dates

GNP

US GNP series

GNP_gr

US GNP log difference

Source

https://www.ssc.wisc.edu/~bhansen/progs/jae_92.html

References

Hansen, Bruce E. 1992. “The likelihood ratio test under nonstandard conditions: testing the Markov switching model of GNP.” Journal of applied Econometrics 7 (S1): S61–S82.

Hamilton, James D. 1989. “A new approach to the economic analysis of nonstationary time series and the business cycle.” Econometrica 57 (2): 357–384.


Initial values for Hidden Markov model

Description

This function generates a random parameter vector to be used as initial values for a Hidden Markov model.

Usage

initVals_HMmdl(mdl, k)

Arguments

mdl

List with parameter values of simple (one-regime) model. This includes:

  • mu: Vector of means.

  • sigma: covariance matrix.

  • msmu: Boolean indicator. If TRUE, mean is function of markov process. If FALSE, mean is constant across regimes.

  • msvar: Boolean indicator. If TRUE, standard deviation is function of markov process. If FALSE, standard deviation is constant across regimes.

k

Number of regimes.

Value

Vector of initial parameter values.


Initial values for Markov-switching ARX model

Description

This function generates a random parameter vector to be used as initial values for a Markov-switching ARX model.

Usage

initVals_MSARXmdl(mdl, k)

Arguments

mdl

List with parameter values of simple (one-regime) autoregressive model. This includes:

  • phi: Vector autoregressive coefficients.

  • mu: Mean of process.

  • betaZ: vector of coefficients for exogenous regressors

  • stdev: Standard deviation.

  • msmu: Boolean indicator. If TRUE, mean is function of markov process. If FALSE, mean is constant across regimes.

  • msvar: Boolean indicator. If TRUE, standard deviation is function of markov process. If FALSE, standard deviation is constant across regimes.

k

Number of regimes.

Value

Vector of initial parameter values.


Initial values for Markov-switching autoregressive model

Description

This function generates a random parameter vector to be used as initial values for a Markov-switching autoregressive model.

Usage

initVals_MSARmdl(mdl, k)

Arguments

mdl

List with parameter values of simple (one-regime) autoregressive model. This includes:

  • phi: Vector autoregressive coefficients.

  • mu: Mean of process.

  • stdev: Standard deviation.

  • msmu: Boolean indicator. If TRUE, mean is function of markov process. If FALSE, mean is constant across regimes.

  • msvar: Boolean indicator. If TRUE, standard deviation is function of markov process. If FALSE, standard deviation is constant across regimes.

k

Number of regimes.

Value

Vector of initial parameter values.


Initial values for Markov-switching VARX model

Description

This function generates a random parameter vector to be used as initial values for a Markov-switching VARX model.

Usage

initVals_MSVARXmdl(mdl, k)

Arguments

mdl

List with parameter values of simple (one-regime) VARX model. This includes:

  • phi: Matrix autoregressive coefficients.

  • mu: Vector of means.

  • betaZ: vector of coefficients for exogenous regressors

  • sigma: Covariance matrix.

  • msmu: Boolean indicator. If TRUE, mean is function of markov process. If FALSE, mean is constant across regimes.

  • msvar: Boolean indicator. If TRUE, standard deviation is function of markov process. If FALSE, standard deviation is constant across regimes.

k

Number of regimes.

Value

Vector of initial parameter values.


Initial values for Markov-switching vector autoregressive model

Description

This function generates a random parameter vector to be used as initial values for a Markov-switching vector autoregressive model.

Usage

initVals_MSVARmdl(mdl, k)

Arguments

mdl

List with parameter values of simple (one-regime) vector autoregressive model. This includes:

  • phi: Matrix autoregressive coefficients.

  • mu: Vector of means.

  • sigma: Covariance matrix.

  • msmu: Boolean indicator. If TRUE, mean is function of markov process. If FALSE, mean is constant across regimes.

  • msvar: Boolean indicator. If TRUE, standard deviation is function of markov process. If FALSE, standard deviation is constant across regimes.

k

Number of regimes.

Value

Vector of initial parameter values.


Intercept from mu for MSARmdl

Description

This function computes the intercept for each regime k for an Markov switching AR model

Usage

interMSARmdl(mdl)

Arguments

mdl

List with model properties

Value

a (k x 1) vector of intercepts


Intercept from mu for MSVARmdl

Description

This function computes the intercept for each regime k for an Markov switching VAR model

Usage

interMSVARmdl(mdl)

Arguments

mdl

List with model properties

Value

a (k x q) vector of intercepts


Ergodic (limiting) probabilities of states

Description

Takes a transition matrix and returns the limiting probabilities.

Usage

limP(P)

Arguments

P

Matrix with transition probabilities.

Value

A (k x 1) vector of limiting probabilities.


Log likelihood for autoregressive model

Description

This function is used to compute the log-likelihood for an autoregressive model.

Usage

## S3 method for class 'ARmdl'
logLik(object, ...)

Arguments

object

any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted.

...

some methods for this generic function require additional arguments.

Value

Log-likelihood value.


Log likelihood for Hidden Markov model

Description

This function is used to compute the log-likelihood for a Hidden Markov model.

Usage

## S3 method for class 'HMmdl'
logLik(object, ...)

Arguments

object

any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted.

...

some methods for this generic function require additional arguments.

Value

Log-likelihood value.


Log likelihood for Markov-switching autoregressive model

Description

This function is used to compute the log-likelihood for a Markov-switching autoregressive model.

Usage

## S3 method for class 'MSARmdl'
logLik(object, ...)

Arguments

object

any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted.

...

some methods for this generic function require additional arguments.

Value

Log-likelihood value.


Log likelihood for Markov-switching vector autoregressive model

Description

This function is used to compute the log-likelihood for a Markov-switching vector autoregressive model.

Usage

## S3 method for class 'MSVARmdl'
logLik(object, ...)

Arguments

object

any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted.

...

some methods for this generic function require additional arguments.

Value

Log-likelihood value.


Log likelihood for Normal model

Description

This function is used to compute the log-likelihood for a normally distributed model.

Usage

## S3 method for class 'Nmdl'
logLik(object, ...)

Arguments

object

any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted.

...

some methods for this generic function require additional arguments.

Value

Log-likelihood value.


Log likelihood for vector autoregressive model

Description

This function is used to compute the log-likelihood for a vector autoregressive model.

Usage

## S3 method for class 'VARmdl'
logLik(object, ...)

Arguments

object

any object from which a log-likelihood value, or a contribution to a log-likelihood value, can be extracted.

...

some methods for this generic function require additional arguments.

Value

Log-likelihood value.


ARX log-likelihood objective function

Description

This function computes the log-likelihood for an autoregressive model with exogenous regressors.

Usage

logLike_ARXmdl(theta, mdl)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

Value

Log-likelihood value.


Autoregressive log-likelihood objective function

Description

This function computes the log-likelihood for an autoregressive model.

Usage

logLike_ARmdl(theta, mdl)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

Value

Log-likelihood value.


Hidden Markov model log-likelihood function

Description

This function computes the log-likelihood for a markov-switching autoregressive model.

Usage

logLike_HMmdl(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

Log-likelihood value.


Hidden Markov model log-likelihood function (minimization version)

Description

This function computes the (negative) log-likelihood for a markov-switching autoregressive model.

Usage

logLike_HMmdl_min(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

integer determining the number of regimes.

Value

Negative log-likelihood value.


Markov-switching ARX log-likelihood objective function

Description

This function computes the log-likelihood for a markov-switching ARX model.

Usage

logLike_MSARXmdl(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

Log-likelihood value.


Markov-switching ARX log-likelihood objective function (minimization version)

Description

This function computes the (negative) log-likelihood for a markov-switching ARX model.

Usage

logLike_MSARXmdl_min(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

integer determining the number of regimes.

Value

Negative log-likelihood value.


Markov-switching autoregressive log-likelihood objective function

Description

This function computes the log-likelihood for a markov-switching autoregressive model.

Usage

logLike_MSARmdl(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

Log-likelihood value.


Markov-switching autoregressive log-likelihood objective function (minimization version)

Description

This function computes the (negative) log-likelihood for a markov-switching autoregressive model.

Usage

logLike_MSARmdl_min(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

integer determining the number of regimes.

Value

Negative log-likelihood value.


Markov-switching VARX log-likelihood objective function

Description

This function computes the log-likelihood for a markov-switching VARX model.

Usage

logLike_MSVARXmdl(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

Log-likelihood value.


Markov-switching VARX log-likelihood objective function (minimization version)

Description

This function computes the (negative) log-likelihood for a markov-switching VARX model

Usage

logLike_MSVARXmdl_min(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

Negative log-likelihood value.


Markov-switching vector autoregressive log-likelihood objective function

Description

This function computes the log-likelihood for a markov-switching vector autoregressive model.

Usage

logLike_MSVARmdl(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

Log-likelihood value.


Markov-switching vector autoregressive log-likelihood objective function (minimization version)

Description

This function computes the (negative) log-likelihood for a markov-switching vector autoregressive model

Usage

logLike_MSVARmdl_min(theta, mdl, k)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

k

Integer determining the number of regimes.

Value

Negative log-likelihood value.


Normal log-likelihood objective function

Description

This function computes the log-likelihood for a normally distributed model.

Usage

logLike_Nmdl(theta, mdl)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

Value

Log-likelihood value.


VARX log-likelihood objective function

Description

This function computes the log-likelihood for a VARX model.

Usage

logLike_VARXmdl(theta, mdl)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

Value

Log-likelihood value.


Vector autoregressive log-likelihood objective function

Description

This function computes the log-likelihood for a vector autoregressive model.

Usage

logLike_VARmdl(theta, mdl)

Arguments

theta

Vector of model parameters.

mdl

List with model attributes.

Value

Log-likelihood value.


Likelihood function used by HLRTest()

Description

this function computes the sum Markov likelihood

Usage

marklike(ths, HLR_opt_ls)

Arguments

ths

vector of parameter values.

HLR_opt_ls

List with model properties and test controls defined in HLRTest().

Value

Vector of likelihood values.


Sum of likelihood used by HLRTest()

Description

This function computes the sum of the likelihood.

Usage

mclike(th, HLR_opt_ls)

Arguments

th

vector of parameter values.

HLR_opt_ls

List with model properties and test controls defined in HLRTest().

Value

Sum of likelihood.


Change model List with new parameters

Description

This function is used by the MMC LRT procedure. It makes a copy of the restricted model under the null hypothesis and changes the parameters used to simulate the process under the null with values being considered in the search/optimization.

Usage

mdledit(mdl_h0, theta_h0, p, q, k0, exog)

Arguments

mdl_h0

List with restricted model properties.

theta_h0

vector of parameter values under null being considered.

p

integer specifying the number of autoregressive lags.

q

integer specifying the number of series.

k0

integer specifying the number of regimes.

Value

List with model properties


Nobs of a ARmdl object

Description

This is a method for the function nobs() for objects of the class ARmdl.

Usage

## S3 method for class 'ARmdl'
nobs(object, ...)

Arguments

object

a fitted model object.

...

further arguments to be passed to methods.

Value

Number of time series observations.


Nobs of a HMmdl object

Description

This is a method for the function nobs() for objects of the class HMmdl.

Usage

## S3 method for class 'HMmdl'
nobs(object, ...)

Arguments

object

a fitted model object.

...

further arguments to be passed to methods.

Value

Number of time series observations.


Nobs of a MSARmdl object

Description

This is a method for the function nobs() for objects of the class MSARmdl.

Usage

## S3 method for class 'MSARmdl'
nobs(object, ...)

Arguments

object

a fitted model object.

...

further arguments to be passed to methods.

Value

Number of time series observations.


Nobs of a MSVARmdl object

Description

This is a method for the function nobs() for objects of the class MSVARmdl.

Usage

## S3 method for class 'MSVARmdl'
nobs(object, ...)

Arguments

object

a fitted model object.

...

further arguments to be passed to methods.

Value

Number of time series observations.


Nobs of a Nmdl object

Description

This is a method for the function nobs() for objects of the class Nmdl.

Usage

## S3 method for class 'Nmdl'
nobs(object, ...)

Arguments

object

a fitted model object.

...

further arguments to be passed to methods.

Value

Number of time series observations.


Nobs of a VARmdl object

Description

This is a method for the function nobs() for objects of the class VARmdl.

Usage

## S3 method for class 'VARmdl'
nobs(object, ...)

Arguments

object

a fitted model object.

...

further arguments to be passed to methods.

Value

Number of time series observations.


Parameter list for Markov-switching ARX model

Description

This function takes the parameter vector of interest and converts it to a list with specific parameter vectors needed for univariate Markov-switching functions.

Usage

paramList_MSARXmdl(theta, p, k, qz, msmu, msvar)

Arguments

theta

Vector of parameters.

p

Number of autoregressive lags.

k

Number of regimes.

qz

Number of exogenous variables.

msmu

Boolean indicating if the mean switches with regime.

msvar

Boolean indicating if the variance switches with regime.

Value

List with the mean, variance, transition matrix, limiting probabilities, and a vector of state indicators.


Parameter list for Markov-switching autoregressive model

Description

This function takes the parameter vector of interest and converts it to a list with specific parameter vectors needed for univariate Markov-switching functions.

Usage

paramList_MSARmdl(theta, p, k, msmu, msvar)

Arguments

theta

Vector of parameters.

p

Number of autoregressive lags.

k

Number of regimes.

msmu

Boolean indicating if the mean switches with regime.

msvar

Boolean indicating if the variance switches with regime.

Value

List with the mean, variance, transition matrix, limiting probabilities, and a vector of state indicators.


Parameter list for Markov-switching VARX model

Description

This function takes the parameter vector of interest and converts it to a list with specific parameter vectors needed for multivariate Markov-switching functions.

Usage

paramList_MSVARXmdl(theta, q, p, k, qz, msmu, msvar)

Arguments

theta

Vector of parameters.

q

Number of time series.

p

Number of autoregressive lags.

k

Number of regimes.

qz

Number of exogenous variables.

msmu

Boolean indicating if the mean switches with regime.

msvar

Boolean indicating if the variance switches with regime.

Value

List with the mean, variance, transition matrix, limiting probabilities, and a vector of state indicators.


Parameter list for Markov-switching vector autoregressive model

Description

This function takes the parameter vector of interest and converts it to a list with specific parameter vectors needed for multivariate Markov-switching functions.

Usage

paramList_MSVARmdl(theta, q, p, k, msmu, msvar)

Arguments

theta

Vector of parameters.

q

Number of time series.

p

Number of autoregressive lags.

k

Number of regimes.

msmu

Boolean indicating if the mean switches with regime.

msvar

Boolean indicating if the variance switches with regime.

Value

List with the mean, variance, transition matrix, limiting probabilities, and a vector of state indicators.


Plot of a ARmdl object

Description

This is a method for the function plot() for objects of the class ARmdl.

Usage

## S3 method for class 'ARmdl'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The ARmdl object is returned invisibly.


Plot of a HMmdl object

Description

This is a method for the function plot() for objects of the class HMmdl.

Usage

## S3 method for class 'Hmmdl'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The Hmmdl object is returned invisibly.


Plot of a MSARmdl object

Description

This is a method for the function plot() for objects of the class MSARmdl.

Usage

## S3 method for class 'MSARmdl'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The MSARmdl object is returned invisibly.


Plot of a MSVARmdl object

Description

This is a method for the function plot() for objects of the class MSVARmdl.

Usage

## S3 method for class 'MSVARmdl'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The MSVARmdl object is returned invisibly.


Plot of a Nmdl object

Description

This is a method for the function plot() for objects of the class Nmdl.

Usage

## S3 method for class 'Nmdl'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The Nmdl object is returned invisibly.


Plot of a VARmdl object

Description

This is a method for the function plot() for objects of the class VARmdl.

Usage

## S3 method for class 'VARmdl'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The VARmdl object is returned invisibly.


Plot of a simuAR object

Description

This is a method for the function plot() for objects of the class simuAR.

Usage

## S3 method for class 'simuAR'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The simuAR object is returned invisibly.


Plot of a simuARX object

Description

This is a method for the function plot() for objects of the class simuAR.

Usage

## S3 method for class 'simuARX'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The simuARX object is returned invisibly.


Plot of a simuHMM object

Description

This is a method for the function plot() for objects of the class simuHMM.

Usage

## S3 method for class 'simuHMM'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The simuHMM object is returned invisibly.


Plot of a simuMSAR object

Description

This is a method for the function plot() for objects of the class simuMSAR.

Usage

## S3 method for class 'simuMSAR'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The simuMSAR object is returned invisibly.


Plot of a simuMSARX object

Description

This is a method for the function plot() for objects of the class simuMSAR.

Usage

## S3 method for class 'simuMSARX'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The simuMSARX object is returned invisibly.


Plot of a simuMSVAR object

Description

This is a method for the function plot() for objects of the class simuMSVAR.

Usage

## S3 method for class 'simuMSVAR'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The simuMSVAR object is returned invisibly.


Plot of a simuMSVARX object

Description

This is a method for the function plot() for objects of the class simuMSVAR.

Usage

## S3 method for class 'simuMSVARX'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The simuMSVARX object is returned invisibly.


Plot of a simuNorm object

Description

This is a method for the function plot() for objects of the class simuNorm.

Usage

## S3 method for class 'simuNorm'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The simuNorm object is returned invisibly.


Plot of a simuVAR object

Description

This is a method for the function plot() for objects of the class simuVAR.

Usage

## S3 method for class 'simuVAR'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The simuVAR object is returned invisibly.


Plot of a simuVARX object

Description

This is a method for the function plot() for objects of the class simuVAR.

Usage

## S3 method for class 'simuVARX'
plot(x, ...)

Arguments

x

the coordinates of points in the plot. Alternatively, a single plotting structure, function or any R object with a plot method can be provided.

...

arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

type

what type of plot should be drawn. Possible types are

  • "p" for points,

  • "l" for lines,

  • "b" for both,

  • "c" for the lines part alone of "b",

  • "o" for both ‘overplotted’,

  • "h" for ‘histogram’ like (or ‘high-density’) vertical lines,

  • "s" for stair steps,

  • "S" for other steps, see ‘Details’ below,

  • "n" for no plotting.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main

an overall title for the plot: see title.

sub

a subtitle for the plot: see title.

xlab

a title for the x axis: see title.

ylab

a title for the y axis: see title.

asp

the y/x aspect ratio, see plot.window.

Value

The simuVARX object is returned invisibly.


Predict for a ARmdl object

Description

This is a method for the function predict() for objects of the class ARmdl.

Usage

## S3 method for class 'ARmdl'
predict(object, ..., h = 10)

Arguments

object

a model object for which prediction is desired.

...

additional arguments affecting the predictions produced.

h

max number of prediction periods

Value

a (h x q) matrix with predicted value values.


Predict for a HMmdl object

Description

This is a method for the function predict() for objects of the class HMmdl.

Usage

## S3 method for class 'HMmdl'
predict(object, ..., h = 10)

Arguments

object

a model object for which prediction is desired.

...

additional arguments affecting the predictions produced.

h

max number of prediction periods

Value

a (h x q) matrix with predicted value values.


Predict for a MSARmdl object

Description

This is a method for the function predict() for objects of the class MSARmdl.

Usage

## S3 method for class 'MSARmdl'
predict(object, ..., h = 10)

Arguments

object

a model object for which prediction is desired.

...

additional arguments affecting the predictions produced.

h

max number of prediction periods

Value

a (h x q) matrix with predicted value values.


Predict for a MSVARmdl object

Description

This is a method for the function predict() for objects of the class MSVARmdl.

Usage

## S3 method for class 'MSVARmdl'
predict(object, ..., h = 10)

Arguments

object

a model object for which prediction is desired.

...

additional arguments affecting the predictions produced.

h

max number of prediction periods

Value

a (h x q) matrix with predicted value values.


Predict for a Nmdl object

Description

This is a method for the function predict() for objects of the class Nmdl.

Usage

## S3 method for class 'Nmdl'
predict(object, ..., h = 10)

Arguments

object

a model object for which prediction is desired.

...

additional arguments affecting the predictions produced.

h

max number of prediction periods

Value

a (h x q) matrix with predicted value values.


Predict for a VARmdl object

Description

This is a method for the function predict() for objects of the class VARmdl.

Usage

## S3 method for class 'VARmdl'
predict(object, ..., h = 10)

Arguments

object

a model object for which prediction is desired.

...

additional arguments affecting the predictions produced.

h

max number of prediction periods

Value

a (h x q) matrix with predicted value values.


Print summary of an ARmdl object

Description

This is a method for the function print() for objects of the class ARmdl.

Usage

## S3 method for class 'ARmdl'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The ARmdl object is returned invisibly.


Print summary of a BootLRTest object

Description

This is a method for the function print() for objects of the class BootLRTest.

Usage

## S3 method for class 'BootLRTest'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The BootLRTest object is returned invisibly.


Print summary of a CHPTest object

Description

This is a method for the function print() for objects of the class CHPTest.

Usage

## S3 method for class 'CHPTest'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The CHPTest object is returned invisibly.


Print summary of a DLMCTest object

Description

This is a method for the function print() for objects of the class DLMCTest.

Usage

## S3 method for class 'DLMCTest'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The DLMCTest object is returned invisibly.


Print summary of a DLMMCTest object

Description

This is a method for the function print() for objects of the class DLMMCTest.

Usage

## S3 method for class 'DLMMCTest'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The DLMMCTest object is returned invisibly.


Print summary of a CHPTest object

Description

This is a method for the function print() for objects of the class CHPTest.

Usage

## S3 method for class 'HLRTest'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The CHPTest object is returned invisibly.


Print summary of a HMmdl object

Description

This is a method for the function print() for objects of the class HMmdl.

Usage

## S3 method for class 'HMmdl'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The HMmdl object is returned invisibly.


Print summary of a LMCLRTest object

Description

This is a method for the function print() for objects of the class LMCLRTest.

Usage

## S3 method for class 'LMCLRTest'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The LMCLRTest object is returned invisibly.


Print summary of a MMCLRTest object

Description

This is a method for the function print() for objects of the class MMCLRTest.

Usage

## S3 method for class 'MMCLRTest'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The MMCLRTest object is returned invisibly.


Print summary of a MSARmdl object

Description

This is a method for the function print() for objects of the class MSARmdl.

Usage

## S3 method for class 'MSARmdl'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The MSARmdl object is returned invisibly.


Print summary of a MSVARmdl object

Description

This is a method for the function print() for objects of the class MSVARmdl.

Usage

## S3 method for class 'MSVARmdl'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The MSVARmdl object is returned invisibly.


Print summary of a Nmdl object

Description

This is a method for the function print() for objects of the class Nmdl.

Usage

## S3 method for class 'Nmdl'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The Nmdl object is returned invisibly.


Print summary of an VARmdl object

Description

This is a method for the function print() for objects of the class VARmdl.

Usage

## S3 method for class 'VARmdl'
print(x, digits = getOption("digits"), ...)

Arguments

x

an object used to select a method.

digits

minimal number of significant digits, see print.default.

...

further arguments passed to or from other methods.

Value

The VARmdl object is returned invisibly.


Random Transition Matrix

Description

This function creates a random transition matrix.

Usage

randP(k)

Arguments

k

Number of regimes. Must be greater than or equal to 2.

Value

Transition matrix with randomly generated entries.


Standard normal errors using box Muller

Description

This function generates uncorrelated standard normal processes using box Muller method.

Usage

randSN(n, q)

Arguments

n

Integer determining the length of the process to be simulated

q

Integer determining the number of processes to be simulated

Value

A (T x q) matrix of standard normal distributed errors


residuals of a ARmdl object

Description

This is a method for the function residuals() for objects of the class ARmdl.

Usage

## S3 method for class 'ARmdl'
residuals(object, ...)

Arguments

object

an object for which the extraction of model residuals is meaningful.

...

other arguments.

Value

vector of residuals.


residuals of a HMmdl object

Description

This is a method for the function residuals() for objects of the class HMmdl.

Usage

## S3 method for class 'HMmdl'
residuals(object, ...)

Arguments

object

an object for which the extraction of model residuals is meaningful.

...

other arguments.

Value

vector of residuals.


residuals of a MSARmdl object

Description

This is a method for the function residuals() for objects of the class MSARmdl.

Usage

## S3 method for class 'MSARmdl'
residuals(object, ...)

Arguments

object

an object for which the extraction of model residuals is meaningful.

...

other arguments.

Value

vector of residuals.


residuals of a MSVARmdl object

Description

This is a method for the function residuals() for objects of the class MSVARmdl.

Usage

## S3 method for class 'MSVARmdl'
residuals(object, ...)

Arguments

object

an object for which the extraction of model residuals is meaningful.

...

other arguments.

Value

vector of residuals.


residuals of a Nmdl object

Description

This is a method for the function residuals() for objects of the class Nmdl.

Usage

## S3 method for class 'Nmdl'
residuals(object, ...)

Arguments

object

an object for which the extraction of model residuals is meaningful.

...

other arguments.

Value

vector of residuals.


residuals of a VARmdl object

Description

This is a method for the function residuals() for objects of the class VARmdl.

Usage

## S3 method for class 'VARmdl'
residuals(object, ...)

Arguments

object

an object for which the extraction of model residuals is meaningful.

...

other arguments.

Value

vector of residuals.


Simulated moment-based test statistics

Description

This function computes the four moment-based test statistics (eq. 11 - 14) discussed in Dufour & Luger 2017 for N different simulated series.

Usage

sim_DLmoments(Tsize, N)

Arguments

Tsize

Length of sample size for simulation.

N

Number of simulated samples.

Value

A (N x 4) matrix with N different simulated moment-based test statistics.

References

Dufour, J. M., & Luger, R. 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models." Econometric Reviews, 36(6-9), 713-727.


Simulate autoregressive process

Description

This function simulates an autoregresive process.

Usage

simuAR(mdl_h0, burnin = 100)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • mu: Mean of process.

  • sigma: Standard deviation of process.

  • phi: Vector of autoregressive coefficients.

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated autoregressive series and its DGP parameters.

Examples

set.seed(1234)
# Define DGP of AR process
mdl_ar <- list(n     = 500, 
               mu    = 5,
               sigma = 2,
               phi   = c(0.5,0.2))

# Simulate process using simuAR() function
y_simu <- simuAR(mdl_ar)

plot(y_simu)

Simulate autoregressive X process

Description

This function simulates an autoregresive X process.

Usage

simuARX(mdl_h0, burnin = 100)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • mu: Mean of process.

  • sigma: Standard deviation of process.

  • phi: Vector of autoregressive coefficients.

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x 1) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated autoregressive series and its DGP parameters.

Examples

set.seed(1234)
# Define DGP of AR process
mdl_ar <- list(n     = 500, 
               mu    = 5,
               sigma = 2,
               phi   = c(0.5,0.2))

# Simulate process using simuAR() function
y_simu <- simuAR(mdl_ar)

plot(y_simu)

Simulate autoregressive process with exogenous regressors

Description

This function simulates an ARX process.

Usage

simuARX_cpp(mdl_h0, burnin = 100L)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • mu: Mean of process.

  • sigma: variance of process.

  • phi: Vector of autoregressive coefficients.

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x 1) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated autoregressive series and its DGP parameters.


Simulate autoregressive process

Description

This function simulates an autoregresive process.

Usage

simuAR_cpp(mdl_h0, burnin = 100L)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • mu: Mean of process.

  • sigma: variance of process.

  • phi: Vector of autoregressive coefficients.

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated autoregressive series and its DGP parameters.


Simulate Hidden Markov model with normally distributed errors

Description

This function simulates a Hidden Markov Model process.

Usage

simuHMM(mdl_h0, burnin = 100)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • k: Number of regimes.

  • mu: A (k x q) vector of means.

  • sigma: A (q x q) covariance matrix.

  • q: Number of series.

  • P: A (k x k) transition matrix (columns must sum to one).

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x q) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated series and its DGP parameters.

Examples

set.seed(1234)

# ----- Univariate ----- #
# Define DGP 
mdl_hmm <- list(n     = 1000, 
                q     = 1,
                mu    = as.matrix(c(5,
                                   -2)),
                sigma = list(as.matrix(5.0),
                             as.matrix(7.0)),
                k     = 2,
                P     = rbind(c(0.90, 0.10),
                              c(0.10, 0.90)))

# Simulate process using simuHMM() function
y_hmm_simu <- simuHMM(mdl_hmm)

plot(y_hmm_simu)

# ----- Multivariate ----- #
# Define DGP 
mdl_hmm <- list(n     = 1000, 
                q     = 2,
                mu    = rbind(c(5, -2),
                              c(10, 2)),
                sigma = list(rbind(c(5.0, 1.5),
                                   c(1.5, 1.0)),
                             rbind(c(7.0, 3.0),
                                   c(3.0, 2.0))),
                k     = 2,
                P     = rbind(c(0.90, 0.10),
                              c(0.10, 0.90)))

# Simulate process using simuHMM() function
y_hmm_simu <- simuHMM(mdl_hmm)


plot(y_hmm_simu)

Simulate Hidden Markov model with normally distributed errors

Description

This function simulates a Hidden Markov Model process.

Usage

simuHMM_cpp(mdl_h0, burnin = 100L, exog = FALSE)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • k: Number of regimes.

  • mu: A (k x q) vector of means.

  • sigma: A (q x q) covariance matrix.

  • q: Number of series.

  • P: A (k x k) transition matrix (columns must sum to one).

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x q) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

exog

bool determining if there are exogenous variables (true) or not (false). Default is false.

Value

List with simulated series and its DGP parameters.


Simulate Markov-switching autoregressive process

Description

This function simulates a Markov-switching autoregressive process.

Usage

simuMSAR(mdl_h0, burnin = 100)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • k: Number of regimes.

  • mu: A (k x 1) vector with mean of process in each regime.

  • sigma: A (k x 1) vector with standard deviation of process in each regime.

  • phi: Vector of autoregressive coefficients.

  • P: A (k x k) transition matrix (columns must sum to one).

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated Markov-switching autoregressive process and its DGP properties.

Examples

set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n     = 500, 
                mu    = c(5,10),
                sigma = c(1,2),
                phi   = c(0.5, 0.2),
                k     = 2,
                P     = rbind(c(0.90, 0.10),
                              c(0.10, 0.90)))

# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)

plot(y_ms_simu)

Simulate Markov-switching ARX process

Description

This function simulates a Markov-switching autoregressive process.

Usage

simuMSARX(mdl_h0, burnin = 100)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • k: Number of regimes.

  • mu: A (k x 1) vector with mean of process in each regime.

  • sigma: A (k x 1) vector with standard deviation of process in each regime.

  • phi: Vector of autoregressive coefficients.

  • P: A (k x k) transition matrix (columns must sum to one).

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x 1) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated Markov-switching autoregressive process and its DGP properties.

Examples

set.seed(1234)
# Define DGP of MS AR process
mdl_ms2 <- list(n     = 500, 
                mu    = c(5,10),
                sigma = c(1,2),
                phi   = c(0.5, 0.2),
                k     = 2,
                P     = rbind(c(0.90, 0.10),
                              c(0.10, 0.90)))

# Simulate process using simuMSAR() function
y_ms_simu <- simuMSAR(mdl_ms2)

plot(y_ms_simu)

Simulate Markov-switching ARX process

Description

This function simulates a Markov-switching ARX process.

Usage

simuMSARX_cpp(mdl_h0, burnin = 100L)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • k: Number of regimes.

  • mu: A (k x 1) vector with mean of process in each regime.

  • sigma: A (k x 1) vector with variance of process in each regime.

  • phi: Vector of autoregressive coefficients.

  • P: A (k x k) transition matrix (columns must sum to one).

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x 1) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated Markov-switching autoregressive process and its DGP properties.


Simulate Markov-switching autoregressive process

Description

This function simulates a Markov-switching autoregressive process.

Usage

simuMSAR_cpp(mdl_h0, burnin = 100L)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • k: Number of regimes.

  • mu: A (k x 1) vector with mean of process in each regime.

  • sigma: A (k x 1) vector with variance of process in each regime.

  • phi: Vector of autoregressive coefficients.

  • P: A (k x k) transition matrix (columns must sum to one).

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated Markov-switching autoregressive process and its DGP properties.


Simulate Markov-switching vector autoregressive process

Description

This function simulates a Markov-switching vector autoregressive process.

Usage

simuMSVAR(mdl_h0, burnin = 100)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • k: Number of regimes.

  • mu: A (k x q) matrix of means.

  • sigma: List with k (q x q) covariance matrices.

  • phi: A (q x qp) matrix of autoregressive coefficients.

  • p: Number of autoregressive lags.

  • q: Number of series.

  • P: A (k x k) transition matrix (columns must sum to one).

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated vector autoregressive series and its DGP parameters.

Examples

set.seed(1234)
# Define DGP of MS VAR process
mdl_msvar2 <- list(n     = 1000, 
                   p     = 1,
                   q     = 2,
                   mu    = rbind(c(5, -2),
                                 c(10, 2)),
                   sigma = list(rbind(c(5.0, 1.5),
                                      c(1.5, 1.0)),
                                rbind(c(7.0, 3.0),
                                      c(3.0, 2.0))),
                   phi   = rbind(c(0.50, 0.30),
                                 c(0.20, 0.70)),
                   k     = 2,
                   P     = rbind(c(0.90, 0.10),
                                 c(0.10, 0.90)))

# Simulate process using simuMSVAR() function
y_msvar_simu <- simuMSVAR(mdl_msvar2)

plot(y_msvar_simu)

Simulate Markov-switching VARX process

Description

This function simulates a Markov-switching VARX process.

Usage

simuMSVARX(mdl_h0, burnin = 100)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • k: Number of regimes.

  • mu: A (k x q) matrix of means.

  • sigma: List with k (q x q) covariance matrices.

  • phi: A (q x qp) matrix of autoregressive coefficients.

  • p: Number of autoregressive lags.

  • q: Number of series.

  • P: A (k x k) transition matrix (columns must sum to one).

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x q) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated vector autoregressive series and its DGP parameters.

Examples

set.seed(1234)
# Define DGP of MS VAR process
mdl_msvar2 <- list(n     = 1000, 
                   p     = 1,
                   q     = 2,
                   mu    = rbind(c(5, -2),
                                 c(10, 2)),
                   sigma = list(rbind(c(5.0, 1.5),
                                      c(1.5, 1.0)),
                                rbind(c(7.0, 3.0),
                                      c(3.0, 2.0))),
                   phi   = rbind(c(0.50, 0.30),
                                 c(0.20, 0.70)),
                   k     = 2,
                   P     = rbind(c(0.90, 0.10),
                                 c(0.10, 0.90)))

# Simulate process using simuMSVAR() function
y_msvar_simu <- simuMSVAR(mdl_msvar2)

plot(y_msvar_simu)

Simulate Markov-switching VARX process

Description

This function simulates a Markov-switching VARX process.

Usage

simuMSVARX_cpp(mdl_h0, burnin = 100L)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • k: Number of regimes.

  • mu: A (k x q) matrix of means.

  • sigma: List with k (q x q) covariance matrices.

  • phi: A (q x qp) matrix of autoregressive coefficients.

  • p: Number of autoregressive lags.

  • q: Number of series.

  • P: A (k x k) transition matrix (columns must sum to one).

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x q) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated vector autoregressive series and its DGP parameters.


Simulate Markov-switching vector autoregressive process

Description

This function simulates a Markov-switching vector autoregressive process.

Usage

simuMSVAR_cpp(mdl_h0, burnin = 100L)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • k: Number of regimes.

  • mu: A (k x q) matrix of means.

  • sigma: List with k (q x q) covariance matrices.

  • phi: A (q x qp) matrix of autoregressive coefficients.

  • p: Number of autoregressive lags.

  • q: Number of series.

  • P: A (k x k) transition matrix (columns must sum to one).

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated vector autoregressive series and its DGP parameters.


Likelihood ratio test statistic sample distribution

Description

This function is used by Monte Carlo Likelihood ratio testing procedures to simulate processes under the null hypothesis.

Usage

simuMdl(mdl_h0, p, q, k, burnin, exog)

Arguments

mdl_h0

List with restricted model properties.

p

integer specifying the number of autoregressive lags.

q

integer specifying the number of series.

k

integer specifying the number of regimes.

burnin

integer specifying the number of observations to drop from beginning of simulation.

Value

List with simulated process properties.


Simulate normally distributed process

Description

This function simulates a normally distributed process.

Usage

simuNorm(mdl_h0, burnin = 0)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • mu: A (q x 1) vector of means.

  • sigma: A (q x q) covariance matrix.

  • q: Number of series.

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x q) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated series and its DGP parameters.

Examples

set.seed(1234)
# Define DGP 
mdl_norm <- list(n     = 1000, 
                 q     = 2,
                 mu    = c(5, -2),
                 sigma = rbind(c(5.0, 1.5),
                               c(1.5, 1.0)))

# Simulate process using simuNorm() function
y_norm_simu <- simuNorm(mdl_norm)

plot(y_norm_simu)

Simulate normally distributed process

Description

This function simulates a normally distributed process.

Usage

simuNorm_cpp(mdl_h0, burnin = 0L, exog = FALSE)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • mu: A (q x 1) vector of means.

  • sigma: A (q x q) covariance matrix.

  • q: Number of series.

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x q) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

exog

bool determining if there are exogenous variables (true) or not (false). Default is false.

Value

List with simulated series and its DGP parameters.


Simulate VAR process

Description

This function simulates a vector autoregresive process.

Usage

simuVAR(mdl_h0, burnin = 100)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • mu: A (q x 1) vector of means.

  • sigma: A (q x q) covariance matrix.

  • phi: A (q x qp) matrix of autoregressive coefficients.

  • p: Number of autoregressive lags.

  • q: Number of series.

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated vector autoregressive series and its DGP parameters.


Simulate VAR process

Description

This function simulates a vector autoregresive process.

Usage

simuVARX(mdl_h0, burnin = 100)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • mu: A (q x 1) vector of means.

  • sigma: A (q x q) covariance matrix.

  • phi: A (q x (q x p)) matrix of autoregressive coefficients.

  • p: Number of autoregressive lags.

  • q: Number of series.

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x q) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated vector autoregressive series and its DGP parameters.


Simulate VARX process

Description

This function simulates a VARX process.

Usage

simuVARX_cpp(mdl_h0, burnin = 100L)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • mu: A (q x 1) vector of means.

  • sigma: A (q x q) covariance matrix.

  • phi: A (q x qp) matrix of autoregressive coefficients.

  • p: Number of autoregressive lags.

  • q: Number of series.

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

  • Z: A (T x qz) matrix with exogenous regressors (Optional) and where qz is the number of exogenous variables.

  • betaZ: A (qz x q) matrix true coefficients on exogenous regressors (Optional) and where qz is the number of exogenous variables.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated vector autoregressive series and its DGP parameters.


Simulate VAR process

Description

This function simulates a vector autoregresive process.

Usage

simuVAR_cpp(mdl_h0, burnin = 100L)

Arguments

mdl_h0

List containing the following DGP parameters

  • n: Length of series.

  • mu: A (q x 1) vector of means.

  • sigma: A (q x q) covariance matrix.

  • phi: A (q x qp) matrix of autoregressive coefficients.

  • p: Number of autoregressive lags.

  • q: Number of series.

  • eps: An optional (T+burnin x q) matrix with standard normal errors to be used. Errors will be generated if not provided.

burnin

Number of simulated observations to remove from beginning. Default is 100.

Value

List with simulated vector autoregressive series and its DGP parameters.


Summary of an ARmdl object

Description

This is a method for the function summary() for objects of the class ARmdl.

Usage

## S3 method for class 'ARmdl'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The ARmdl object is returned invisibly.


Summary of a BootLRTest object

Description

This is a method for the function summary() for objects of the class BootLRTest.

Usage

## S3 method for class 'BootLRTest'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The BootLRTest object is returned invisibly.


Summary of a CHPTest object

Description

This is a method for the function summary() for objects of the class CHPTest.

Usage

## S3 method for class 'CHPTest'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The CHPTest object is returned invisibly.


summaryummary of a DLMCTest object

Description

This is a method for the function summary() for objects of the class DLMCTest.

Usage

## S3 method for class 'DLMCTest'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The DLMCTest object is returned invisibly.


Summary of a DLMMCTest object

Description

This is a method for the function summary() for objects of the class DLMMCTest.

Usage

## S3 method for class 'DLMMCTest'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The DLMMCTest object is returned invisibly.


Summary of a CHPTest object

Description

This is a method for the function summary() for objects of the class CHPTest.

Usage

## S3 method for class 'HLRTest'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The CHPTest object is returned invisibly.


Summary of a HMmdl object

Description

This is a method for the function summary() for objects of the class HMmdl.

Usage

## S3 method for class 'HMmdl'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The HMmdl object is returned invisibly.


Summary of a LMCLRTest object

Description

This is a method for the function summary() for objects of the class LMCLRTest.

Usage

## S3 method for class 'LMCLRTest'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The LMCLRTest object is returned invisibly.


Summary of a MMCLRTest object

Description

This is a method for the function summary() for objects of the class MMCLRTest.

Usage

## S3 method for class 'MMCLRTest'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The MMCLRTest object is returned invisibly.


Summary of a MSARmdl object

Description

This is a method for the function summary() for objects of the class MSARmdl.

Usage

## S3 method for class 'MSARmdl'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The MSARmdl object is returned invisibly.


Summary of a MSVARmdl object

Description

This is a method for the function summary() for objects of the class MSVARmdl.

Usage

## S3 method for class 'MSVARmdl'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The MSVARmdl object is returned invisibly.


Summary of a Nmdl object

Description

This is a method for the function summary() for objects of the class Nmdl.

Usage

## S3 method for class 'Nmdl'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The Nmdl object is returned invisibly.


Summary of an VARmdl object

Description

This is a method for the function summary() for objects of the class VARmdl.

Usage

## S3 method for class 'VARmdl'
summary(object, digits = getOption("digits"), ...)

Arguments

object

an object for which a summary is desired.

digits

integer, used for number formatting with signif() (for summary.default) or format() (for summary.data.frame). In summary.default, if not specified (i.e., missing(.)), signif() will not be called anymore (since R >= 3.4.0, where the default has been changed to only round in the print and format methods).

...

additional arguments affecting the summary produced.

Value

The VARmdl object is returned invisibly.


Theta standard errors

Description

This function computes the standard errors of the parameters in vector theta. This is done using an approximation of the Hessian matrix (using hessian and nearPD if info_mat is not PD).

Usage

thetaSE(mdl)

Arguments

mdl

List with model properties

Value

List provided as input with additional attributes HESS,theta_se, info_mat, and nearPD_used.


Lagged Time Series Data

Description

This function takes a (T x 1) vector Y and returns the (T-p x 1) vector y and the (T-p x p) matrix of lagged observations.

Usage

ts_lagged(Y, p)

Arguments

Y

Vector with time series observations.

p

integer for the number of lags to use in estimation. Must be greater than or equal to 1.

Value

List with vector y (vector of lagged Y) and matrix X of lagged observations.