Learn R Programming

MSTest (version 0.1.9)

MMCLRTest: Maximized Monte Carlo Likelihood Ratio Test

Description

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

Usage

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

Value

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

  • mdl_h0: List with restricted model attributes.

  • mdl_h1: List with unrestricted model attributes.

  • mdl_h0_mmc: List with restricted model attributes at the maximizing nuisance parameter values.

  • mdl_h1_mmc: List with unrestricted model attributes (same as mdl_h1).

  • LRT_0: Value of test statistic from observed data.

  • pval: Maximized p-value of the Maximized Monte Carlo Likelihood Ratio Test.

  • theta_h0: Maximizing nuisance parameter vector for the restricted model.

  • theta_h1: Parameter vector of the unrestricted model.

  • control: List with test procedure options used.

  • mmc_optimout: Optimization output object returned by the selected optimizer (pso, GenSA, or GA).

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. Default is 0 (sequential). If workers > N, the effective count is capped at N and an informational message is printed (unless silence = TRUE).

  • mc_seed: Integer seed for reproducible Monte Carlo simulations and fixed-error MMC (Dufour 2006, Prop. 4.2). When set, seeds the RNG before observed-data estimation, pre-draws innovations once and holds them fixed across all optimizer evaluations, ensuring full reproducibility (including the observed LRT statistic) and theoretical size control. Default is NULL (non-reproducible).

  • 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 list() (an empty list); the maximum number of optimizer iterations is instead controlled by the separate maxit argument (default 50).

References

Rodriguez-Rondon, G., & Dufour, J.-M. 2026a. "Monte Carlo Likelihood-Ratio Tests for Markov Switching Models." Bank of Canada Staff Working Paper, No. 2026-23. doi: 10.34989/swp-2026-23.

Examples

Run this code

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 = 50,
                   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)




Run the code above in your browser using DataLab