IDEAS home Printed from https://ideas.repec.org/p/bca/bocawp/26-7.html

MSTest: An R-Package for Testing Markov Switching Models

Author

Listed:
  • Gabriel Rodriguez Rondon
  • Jean-Marie Dufour

Abstract

We present the R package MSTest, which implements hypothesis testing procedures to determine the number of regimes in Markov switching models. These models have wide ranging applications in economics, finance, and many other fields. MSTest provides several testing frameworks, including Monte Carlo likelihood ratio tests (Rodriguez-Rondon and Dufour (2025)), moment-based tests (Dufour and Luger (2017)), parameter stability tests (Carrasco et al. (2014)), and classical likelihood ratio procedures (Hansen (1992)). In addition, the package offers tools for simulating and estimating univariate and multivariate Markov switching and hidden Markov models using either the expectation–maximization algorithm or maximum likelihood estimation. The functionality of the package is demonstrated through simulation-based examples.

Suggested Citation

  • Gabriel Rodriguez Rondon & Jean-Marie Dufour, 2026. "MSTest: An R-Package for Testing Markov Switching Models," Staff Working Papers 26-7, Bank of Canada.
  • Handle: RePEc:bca:bocawp:26-7
    DOI: 10.34989/swp-2026-7
    as

    Download full text from publisher

    File URL: https://doi.org/10.34989/swp-2026-7
    File Function: Abstract
    Download Restriction: no

    File URL: https://www.bankofcanada.ca/wp-content/uploads/2026/03/swp2026-7.pdf
    File Function: Full text
    Download Restriction: no

    File URL: https://libkey.io/10.34989/swp-2026-7?utm_source=ideas
    LibKey link: if access is restricted and if your library uses this service, LibKey will redirect you to where you can use your library subscription to access this item
    ---><---

    References listed on IDEAS

    as
    1. Jin Seo Cho & Halbert White, 2007. "Testing for Regime Switching," Econometrica, Econometric Society, vol. 75(6), pages 1671-1720, November.
    2. Hansen, Bruce E, 1996. "Erratum: The Likelihood Ratio Test under Nonstandard Conditions: Testing the Markov Switching Model of GNP," Journal of Applied Econometrics, John Wiley & Sons, Ltd., vol. 11(2), pages 195-198, March-Apr.
    3. Dufour, Jean-Marie & Khalaf, Lynda & Bernard, Jean-Thomas & Genest, Ian, 2004. "Simulation-based finite-sample tests for heteroskedasticity and ARCH effects," Journal of Econometrics, Elsevier, vol. 122(2), pages 317-347, October.
    4. Vadim Marmer, 2008. "Testing the null hypothesis of no regime switching with an application to GDP growth rates," Empirical Economics, Springer, vol. 35(1), pages 101-122, August.
    5. Emrah Ismail Cevik & Durmuş Çağrı Yıldırım & Sel Dibooglu, 2021. "Renewable and non-renewable energy consumption and economic growth in the US: A Markov-Switching VAR analysis," Energy & Environment, , vol. 32(3), pages 519-541, May.
    6. Andrew V. Carter & Douglas G. Steigerwald, 2012. "Testing for Regime Switching: A Comment," Econometrica, Econometric Society, vol. 80(4), pages 1809-1812, July.
    7. Hiroyuki Kasahara & Katsumi Shimotsu, 2018. "Testing the Number of Regimes in Markov Regime Switching Models," Papers 1801.06862, arXiv.org, revised Jan 2018.
    8. Chinhui Juhn & Simon Potter & Marcelle Chauvet, 2002. "Markov switching in disaggregate unemployment rates," Empirical Economics, Springer, vol. 27(2), pages 205-232.
    9. Donald W. K. Andrews, 1999. "Estimation When a Parameter Is on a Boundary," Econometrica, Econometric Society, vol. 67(6), pages 1341-1384, November.
    10. Caggiano, Giovanni & Castelnuovo, Efrem & Figueres, Juan Manuel, 2017. "Economic policy uncertainty and unemployment in the United States: A nonlinear approach," Economics Letters, Elsevier, vol. 151(C), pages 31-34.
    11. Goldfeld, Stephen M. & Quandt, Richard E., 1973. "A Markov model for switching regressions," Journal of Econometrics, Elsevier, vol. 1(1), pages 3-15, March.
    12. Marcelle Chauvet & James D. Hamilton, 2006. "Dating Business Cycle Turning Points," Contributions to Economic Analysis, in: Nonlinear Time Series Analysis of Business Cycles, pages 1-54, Emerald Group Publishing Limited.
    13. Charfeddine, Lanouar, 2017. "The impact of energy consumption and economic development on Ecological Footprint and CO2 emissions: Evidence from a Markov Switching Equilibrium Correction Model," Energy Economics, Elsevier, vol. 65(C), pages 355-374.
    14. Dufrénot, Gilles & Mignon, Valérie & Péguin-Feissolle, Anne, 2011. "The effects of the subprime crisis on the Latin American financial markets: An empirical assessment," Economic Modelling, Elsevier, vol. 28(5), pages 2342-2357, September.
    15. Andrews, Donald W K & Ploberger, Werner, 1994. "Optimal Tests When a Nuisance Parameter Is Present Only under the Alternative," Econometrica, Econometric Society, vol. 62(6), pages 1383-1414, November.
    16. Herwartz, Helmut & Lütkepohl, Helmut, 2014. "Structural vector autoregressions with Markov switching: Combining conventional with statistical identification of shocks," Journal of Econometrics, Elsevier, vol. 183(1), pages 104-116.
    17. Helmut Lütkepohl & Mika Meitz & Aleksei Netšunajev & Pentti Saikkonen, 2021. "Testing identification via heteroskedasticity in structural vector autoregressive models," The Econometrics Journal, Royal Economic Society, vol. 24(1), pages 1-22.
    18. Hiroyuki Kasahara & Tatsuyoshi Okimoto & Katsumi Shimotsu, 2014. "Modified Quasi-Likelihood Ratio Test for Regime Switching," The Japanese Economic Review, Japanese Economic Association, vol. 65(1), pages 25-41, March.
    19. Simon Dietz & Nicholas Stern, 2015. "Endogenous Growth, Convexity of Damage and Climate Risk: How Nordhaus' Framework Supports Deep Cuts in Carbon Emissions," Economic Journal, Royal Economic Society, vol. 0(583), pages 574-620, March.
    20. Hamilton, James D., 1990. "Analysis of time series subject to changes in regime," Journal of Econometrics, Elsevier, vol. 45(1-2), pages 39-70.
    21. Marine Carrasco & Liang Hu & Werner Ploberger, 2014. "Optimal Test for Markov Switching Parameters," Econometrica, Econometric Society, vol. 82(2), pages 765-784, March.
    22. Gabriel Rodriguez-Rondon, 2024. "Underlying Core Inflation with Multiple Regimes," Papers 2411.12845, arXiv.org.
    23. Chang-Jin Kim & Charles R. Nelson, 1999. "Has The U.S. Economy Become More Stable? A Bayesian Approach Based On A Markov-Switching Model Of The Business Cycle," The Review of Economics and Statistics, MIT Press, vol. 81(4), pages 608-616, November.
    24. Dufour, Jean-Marie, 2006. "Monte Carlo tests with nuisance parameters: A general approach to finite-sample inference and nonstandard asymptotics," Journal of Econometrics, Elsevier, vol. 133(2), pages 443-477, August.
    25. Jean-Marie Dufour & Richard Luger, 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models," Econometric Reviews, Taylor & Francis Journals, vol. 36(6-9), pages 713-727, October.
    26. Andrews, Donald W K, 2001. "Testing When a Parameter Is on the Boundary of the Maintained Hypothesis," Econometrica, Econometric Society, vol. 69(3), pages 683-734, May.
    27. Scrucca, Luca, 2013. "GA: A Package for Genetic Algorithms in R," Journal of Statistical Software, Foundation for Open Access Statistics, vol. 53(i04).
    28. Victor Aguirregabiria & Pedro Mira, 2007. "Sequential Estimation of Dynamic Discrete Games," Econometrica, Econometric Society, vol. 75(1), pages 1-53, January.
    29. Lanne, Markku & Lütkepohl, Helmut, 2010. "Structural Vector Autoregressions With Nonnormal Residuals," Journal of Business & Economic Statistics, American Statistical Association, vol. 28(1), pages 159-168.
    30. Markus Haas, 2004. "A New Approach to Markov-Switching GARCH Models," Journal of Financial Econometrics, Oxford University Press, vol. 2(4), pages 493-530.
    31. James Morley & Jeremy Piger, 2012. "The Asymmetric Business Cycle," The Review of Economics and Statistics, MIT Press, vol. 94(1), pages 208-221, February.
    32. Andrew Sweeting, 2013. "Dynamic Product Positioning in Differentiated Product Markets: The Effect of Fees for Musical Performance Rights on the Commercial Radio Industry," Econometrica, Econometric Society, vol. 81(5), pages 1763-1803, September.
    33. Mikhail Golosov & John Hassler & Per Krusell & Aleh Tsyvinski, 2014. "Optimal Taxes on Fossil Fuel in General Equilibrium," Econometrica, Econometric Society, vol. 82(1), pages 41-88, January.
    34. Kahn, James A. & Rich, Robert W., 2007. "Tracking the new economy: Using growth theory to detect changes in trend productivity," Journal of Monetary Economics, Elsevier, vol. 54(6), pages 1670-1701, September.
    35. Diebold, Francis X & Rudebusch, Glenn D, 1996. "Measuring Business Cycles: A Modern Perspective," The Review of Economics and Statistics, MIT Press, vol. 78(1), pages 67-77, February.
    36. Christopher A. Sims & Tao Zha, 2006. "Were There Regime Switches in U.S. Monetary Policy?," American Economic Review, American Economic Association, vol. 96(1), pages 54-81, March.
    37. Lanne, Markku & Lütkepohl, Helmut & Maciejowska, Katarzyna, 2010. "Structural vector autoregressions with Markov switching," Journal of Economic Dynamics and Control, Elsevier, vol. 34(2), pages 121-131, February.
    38. Hamilton, James D, 1989. "A New Approach to the Economic Analysis of Nonstationary Time Series and the Business Cycle," Econometrica, Econometric Society, vol. 57(2), pages 357-384, March.
    39. So, Mike K P & Lam, K & Li, W K, 1998. "A Stochastic Volatility Model with Markov Switching," Journal of Business & Economic Statistics, American Statistical Association, vol. 16(2), pages 244-253, April.
    40. Garcia, Rene, 1998. "Asymptotic Null Distribution of the Likelihood Ratio Test in Markov Switching Models," International Economic Review, Department of Economics, University of Pennsylvania and Osaka University Institute of Social and Economic Research Association, vol. 39(3), pages 763-788, August.
    41. Pelletier, Denis, 2006. "Regime switching for dynamic correlations," Journal of Econometrics, Elsevier, vol. 131(1-2), pages 445-473.
    42. Dietz, Simon & Stern, Nicholas, 2015. "Endogenous growth, convexity of damage and climate risk: how Nordhaus’ framework supports deep cuts in carbon emissions," LSE Research Online Documents on Economics 58406, London School of Economics and Political Science, LSE Library.
    43. Garcia, Rene & Perron, Pierre, 1996. "An Analysis of the Real Interest Rate under Regime Shifts," The Review of Economics and Statistics, MIT Press, vol. 78(1), pages 111-125, February.
    44. Zhongjun Qu & Fan Zhuo, 2021. "Likelihood Ratio-Based Tests for Markov Regime Switching," The Review of Economic Studies, Review of Economic Studies Ltd, vol. 88(2), pages 937-968.
    Full references (including those not matched with items on IDEAS)

    Most related items

    These are the items that most often cite the same works as this one and are cited by the same works as this one.
    1. Gabriel Rodriguez-Rondon & Jean-Marie Dufour, 2024. "MSTest: An R-Package for Testing Markov Switching Models," Papers 2411.08188, arXiv.org.
    2. Hiroyuki Kasahara & Katsumi Shimotsu, 2018. "Testing the Number of Regimes in Markov Regime Switching Models," Papers 1801.06862, arXiv.org, revised Jan 2018.
    3. Masaru Chiba, 2023. "Robust and efficient specification tests in Markov-switching autoregressive models," Statistical Inference for Stochastic Processes, Springer, vol. 26(1), pages 99-137, April.
    4. Jean-Marie Dufour & Richard Luger, 2017. "Identification-robust moment-based tests for Markov switching in autoregressive models," Econometric Reviews, Taylor & Francis Journals, vol. 36(6-9), pages 713-727, October.
    5. Edoardo Otranto & Luca Scaffidi Domianello, 2025. "On using fuzzy clustering for detecting the number of states in Markov switching models," Annals of Operations Research, Springer, vol. 349(3), pages 1855-1890, June.
    6. Kasahara, Hiroyuki & Shimotsu, Katsumi, 2019. "Asymptotic properties of the maximum likelihood estimator in regime switching econometric models," Journal of Econometrics, Elsevier, vol. 208(2), pages 442-467.
    7. Sergei Koulayev & Marc Rysman & Scott Schuh & Joanna Stavins, 2016. "Explaining adoption and use of payment instruments by US consumers," RAND Journal of Economics, RAND Corporation, vol. 47(2), pages 293-325, May.
    8. Chung-Ming Kuan, 2013. "Markov switching model (in Russian)," Quantile, Quantile, issue 11, pages 13-40, December.
    9. Hamilton, J.D., 2016. "Macroeconomic Regimes and Regime Shifts," Handbook of Macroeconomics, in: J. B. Taylor & Harald Uhlig (ed.), Handbook of Macroeconomics, edition 1, volume 2, chapter 0, pages 163-201, Elsevier.
    10. Odendahl, Florens & Rossi, Barbara & Sekhposyan, Tatevik, 2023. "Evaluating forecast performance with state dependence," Journal of Econometrics, Elsevier, vol. 237(2).
    11. Maddalena Cavicchioli, 2021. "OLS Estimation of Markov switching VAR models: asymptotics and application to energy use," AStA Advances in Statistical Analysis, Springer;German Statistical Society, vol. 105(3), pages 431-449, September.
    12. Garcia, René & Tsafack, Georges, 2011. "Dependence structure and extreme comovements in international equity and bond markets," Journal of Banking & Finance, Elsevier, vol. 35(8), pages 1954-1970, August.
    13. Meitz, Mika & Saikkonen, Pentti, 2021. "Testing for observation-dependent regime switching in mixture autoregressive models," Journal of Econometrics, Elsevier, vol. 222(1), pages 601-624.
    14. Dante Amengual & Gabriele Fiorentini & Enrique Sentana, 2025. "The information matrix test for Markov switching autoregressive models with covariate-dependent transition probabilities," Working Papers wp2025_2502, CEMFI.
    15. Gabriel Rodriguez-Rondon, 2024. "Underlying Core Inflation with Multiple Regimes," Papers 2411.12845, arXiv.org.
    16. Marjan Petreski, 2010. "An Overhaul of a Doctrine: Has Inflation Targeting Opened a New Era in Developing-country Peggers?," FIW Working Paper series 057, FIW.
    17. Magnus Reif, 2020. "Macroeconomics, Nonlinearities, and the Business Cycle," ifo Beiträge zur Wirtschaftsforschung, ifo Institute - Leibniz Institute for Economic Research at the University of Munich, number 87, September.
    18. Nan Li & Simon S. Kwok, 2021. "Jointly determining the state dimension and lag order for Markov‐switching vector autoregressive models," Journal of Time Series Analysis, Wiley Blackwell, vol. 42(4), pages 471-491, July.
    19. Kim, Chang-Jin & Nelson, Charles R, 2001. "A Bayesian Approach to Testing for Markov-Switching in Univariate and Dynamic Factor Models," International Economic Review, Department of Economics, University of Pennsylvania and Osaka University Institute of Social and Economic Research Association, vol. 42(4), pages 989-1013, November.
    20. Maddalena Cavicchioli, 2015. "Likelihood Ratio Test and Information Criteria for Markov Switching Var Models: An Application to the Italian Macroeconomy," Italian Economic Journal: A Continuation of Rivista Italiana degli Economisti and Giornale degli Economisti, Springer;Società Italiana degli Economisti (Italian Economic Association), vol. 1(3), pages 315-332, November.

    More about this item

    Keywords

    ;
    ;
    ;
    ;
    ;
    ;

    JEL classification:

    • C12 - Mathematical and Quantitative Methods - - Econometric and Statistical Methods and Methodology: General - - - Hypothesis Testing: General
    • C15 - Mathematical and Quantitative Methods - - Econometric and Statistical Methods and Methodology: General - - - Statistical Simulation Methods: General
    • C18 - Mathematical and Quantitative Methods - - Econometric and Statistical Methods and Methodology: General - - - Methodolical Issues: General
    • C63 - Mathematical and Quantitative Methods - - Mathematical Methods; Programming Models; Mathematical and Simulation Modeling - - - Computational Techniques
    • C87 - Mathematical and Quantitative Methods - - Data Collection and Data Estimation Methodology; Computer Programs - - - Econometric Software

    NEP fields

    This paper has been announced in the following NEP Reports:

    Statistics

    Access and download statistics

    Corrections

    All material on this site has been provided by the respective publishers and authors. You can help correct errors and omissions. When requesting a correction, please mention this item's handle: RePEc:bca:bocawp:26-7. See general information about how to correct material in RePEc.

    If you have authored this item and are not yet registered with RePEc, we encourage you to do it here. This allows to link your profile to this item. It also allows you to accept potential citations to this item that we are uncertain about.

    If CitEc recognized a bibliographic reference but did not link an item in RePEc to it, you can help with this form .

    If you know of missing items citing this one, you can help us creating those links by adding the relevant references in the same way as above, for each refering item. If you are a registered author of this item, you may also want to check the "citations" tab in your RePEc Author Service profile, as there may be some citations waiting for confirmation.

    For technical questions regarding this item, or to correct its authors, title, abstract, bibliographic or download information, contact: the person in charge (email available below). General contact details of provider: https://edirc.repec.org/data/bocgvca.html .

    Please note that corrections may take a couple of weeks to filter through the various RePEc services.

    IDEAS is a RePEc service. RePEc uses bibliographic data supplied by the respective publishers.