A Bayesian Markov Switching Autoregressive Model with Time-Varying Parameters for Dynamic Economic Forecasting
Highlights
- A Bayesian Markov switching autoregressive model with time-varying parameters (Bayesian MSAR-TVP) is proposed for forecasting nonlinear time series data with stochastic structural variations.
- The Bayesian MSAR-TVP model outperforms the Classical MSAR, Classical MSAR-TVP, and Bayesian AR-TVP models in forecasting U.S. real GNP, particularly in handling complex datasets and out-of-sample forecasting.
- The proposed model addresses parameter uncertainty and adapts dynamically to regime shifts, enhancing the accuracy and reliability of economic forecasting.
- Its ability to capture economic volatility and structural breaks makes it an important tool for policy formulation and long-term economic predictions.
Abstract
1. Introduction
2. Materials and Methods
2.1. MSAR-TVP Model
2.2. Bayesian Method
2.3. Gibbs Sampling
| Algorithm 1. General Gibbs Sampling Algorithm |
|
- Single-Move Gibbs SamplingIn this approach, the elements of the parameter vector are updated one at a time. In each iteration, every element is updated based on its full conditional distribution , assuming the other elements remain fixed. Here, represents the parameter vector excluding . In other words, Algorithm 1 represents the single-move Gibbs sampling approach. This approach requires relatively simple computations, as only one parameter is updated at a time, and its conditional distribution is straightforward to calculate. However, this method tends to require more iterations to achieve convergence, particularly when the parameters exhibit high correlations.
- Multi-Move Gibbs SamplingUnlike the single-move approach, in multi-move Gibbs sampling, the entire parameter vector is updated simultaneously in a single iteration step. The parameters are jointly updated from the joint distribution . This approach is more efficient, especially when the parameters exhibit high correlations, as the entire vector is updated together. However, the computations become more complex because evaluating the joint distribution requires additional considerations, which can be analytically or numerically challenging.
2.4. Estimation Procedures
- Determine the initial value and for the Kalman filter, as well as for the Hamilton filter, for .
- Run the Kalman filter to estimate for .
- Run the Hamilton filter to compute and for .
- Apply the Kim collapsing procedure, utilizing the probability terms from Step 3, to reduce the posterior matrix size from to
- Calculate the log-likelihood function for .
- Conditional on the state vector , the model hyperparameters, and the observation data vector generate the time-varying parameter vector from:
- 2.
- Conditional on the time-varying parameter vector , the model hyperparameters, and the observation data vector , generate the state vector from:
- 3.
- Generate the transition probability parameters and , conditional on the state vector .
- 4.
- Generate the parameter , conditional on the time-varying parameter vector and the state vector .
- 5.
- Compute the parameters , conditional on the observation data and the parameters generated in the previous steps
2.4.1. Generating Conditioned on , the Hyperparameter Model, and
- Execute the Kim filter algorithm to compute and for and store the results. The final iteration of the Kim filter provides and , which are then used to generate based on the following equation:
- 2.
- For given and , if elements of , previously generated, are treated as additional observation vectors in the system, the distribution can be derived by applying the Kalman filter update equations for as follows:where the update equations for and are given by:Thus, the parameter , , can be generated based on the following equation:
2.4.2. Generating Conditioned on , the Hyperparameter Model, and
- Run the Hamilton filter to obtain for , and store the results. The final iteration of the filter provides the estimate , which is then used to generate .
- To generate conditional on and , for use the following expression:where is the transition probability, and is the result stored from Step 1. Using Equation (20), the generation of follows the same procedure as single-move Gibbs sampling. First, calculate follows the same process as in the case of single-move Gibbs sampling. First, calculate:and then, as in single-move Gibbs sampling, use a random number drawn from a uniform distribution to generate . For example, generate a random number from a uniform distribution between 1 and 2. If the random number is less than or equal to the value calculated from , set ; otherwise, set .
2.4.3. Generating Parameters and Conditional on
- Prior:
- Likelihood:
- Posterior:
2.4.4. Generating Conditional on and
- Prior:
- Likelihood:
- Posterior:
2.4.5. Generating Conditional on and Other Model Parameters
2.5. MSAR-TVP Forecasting Model
2.6. Evaluation Techniques
3. Results
3.1. Bayesian MSAR-TVP Model
- Mathematical Representation of the MSAR-TVP Model for :
- Mathematical Representation of the MSAR-TVP Model for :
3.2. Model Comparison
3.3. Forecasting Using the Bayesian MSAR-TVP Model
4. Discussion and Future Research Directions
5. Conclusions
Author Contributions
Funding
Data Availability Statement
Acknowledgments
Conflicts of Interest
Appendix A
| Dataset 1 (U.S. Real GNP 1952–1984) | Dataset 2 (U.S. Real GNP 1947–2022) |
|---|---|
Appendix B
Appendix B.1


Appendix B.2


References
- Meyler, A.; Kenny, G.; Quinn, T. Forecasting Irish Inflation Using ARIMA Models. Econ. Anal. Res. Publ. Dep. Cent. Bank Irel. 1998, 1998, 1–48. [Google Scholar]
- Tzagkarakis, G.; Dionysopoulos, T.; Achim, A. Recurrence Quantification Analysis of Denoised Index Returns via Alpha-Stable Modeling of Wavelet Coefficients: Detecting Switching Volatility Regimes. Stud. Nonlinear Dyn. Econom. 2016, 20, 75–96. [Google Scholar] [CrossRef]
- Hamilton, J.D. A New Approach to the Economic Analysis of Nonstationary Time Series and the Business Cycle. Econometrica 1989, 57, 357–384. [Google Scholar] [CrossRef]
- Adejumo, O.A.; Albert, S.; Asemota, O.J. Markov Regime-Switching Autoregressive Model of Stock Market Returns in Nigeria. CBN J. Appl. Stat. 2020, 11, 65–83. [Google Scholar] [CrossRef] [PubMed][Green Version]
- Stillwagon, J.; Sullivan, P. Markov Switching in Exchange Rate Models: Will More Regimes Help? Empir. Econ. 2020, 59, 413–436. [Google Scholar] [CrossRef]
- Lukianenko, I.; Nasachenko, M. Inflation Expectations Modeling: The Application of Markov Switching Autoregression. Sci. Pap. Nauk. Econ. 2020, 5, 82–88. [Google Scholar] [CrossRef]
- Zhang, X.; Liu, P.; Cheng, L.; Zhou, L.; Liu, W.; Luo, X. Time-Varying Parameters from the Same Period in Previous Years to Improve Runoff Forecasting. J. Hydrol. 2024, 631, 130685. [Google Scholar] [CrossRef]
- Zivot, E.; Wang, J. Modeling Financial Time Series with S_PLUS®, 2nd ed.; Springer: New York, NY, USA, 2006. [Google Scholar]
- Doornik, J.A. A Markov-Switching Model with Component Structure for US GNP. Econ. Lett. 2013, 118, 265–268. [Google Scholar] [CrossRef]
- Pok-sang, L. The Hamilton Model with a General Autoregressive Component: Estimation and Comparison with Other Models of Economic Time Series. J. Monet. Econ. 1990, 26, 409–432. [Google Scholar] [CrossRef]
- Kim, C.J. Dynamic Linear Models with Markov-Switching. J. Econom. 1994, 60, 1–22. [Google Scholar] [CrossRef]
- Cai, Y. A Quantile Approach to US GNP. Econ. Model. 2007, 24, 969–979. [Google Scholar] [CrossRef]
- Inayati, S.; Iriawan, N.; Irhamah, A. Markov Switching Autoregressive Model with Time-Varying Parameters. Forecasting 2024, 6, 568–590. [Google Scholar] [CrossRef]
- Kim, C.J.; Nelson, C.R. State-Space Models with Regime Switching: Classical and Gibbs-Sampling Approaches with Applications; The MIT Press: Cambridge, MA, USA, 2000. [Google Scholar]
- Geman, S.; Geman, D. Stochastic Relaxation, Gibbs Distributions, and the Bayesian Restoration of Images. IEEE Trans. Pattern Anal. Mach. Intell. 1984, 6, 721–741. [Google Scholar] [CrossRef] [PubMed]
- Kim, C.J.; Nelson, C.R. Has the U.S. Economy Become More Stable? A Bayesian Approach Based on a Markov-Switching Model of the Business Cycle. Rev. Econ. Stat. 1999, 81, 608–616. [Google Scholar] [CrossRef]
- Kim, C.J.; Nelson, C.R. A Bayesian Approach to Testing for Markov-Switching in Univariate and Dynamic Factor Models. Int. Econ. Rev. 2001, 42, 989–1013. [Google Scholar] [CrossRef]
- Kaufmann, S. Measuring Business Cycles with a Dynamic Markov Switching Factor Model: An Assessment Using Bayesian Simulation Methods. Econom. J. 2000, 3, 39–65. [Google Scholar] [CrossRef]
- Hartmann, A.; Vinga, S.; Lemos, J.M. Online Bayesian Time-Varying Parameter Estimation of HIV-1 Time-Series. IFAC Proc. Vol. 2012, 45, 1294–1299. [Google Scholar] [CrossRef]
- Yümlü, M.S.; Gürgen, F.S.; Cemgil, A.T.; Okay, N. Bayesian Changepoint and Time-Varying Parameter Learning in Regime Switching Volatility Models. Digit. Signal Process. 2015, 40, 198–212. [Google Scholar] [CrossRef]
- Rajan, J.J.; Rayner, P.J.W. Parameter Estimation of Time-Varying Autoregressive Models Using the Gibbs Sampler. Electron. Lett. 1995, 31, 1035–1036. [Google Scholar] [CrossRef]
- Tanizaki, H. The Time-Varying Parameter Model Revisited. Kobe Univ. Econ. Rev. 1999, 45, 41–57. [Google Scholar]
- Gelman, A.; Carlin, J.B.; Stern, H.S.; Rubin, D.B. Bayesian Data Analysis, 2nd ed.; Chapman & Hall/CRC: London, UK, 2004. [Google Scholar]
- Box, G.E.P.; Tiao, G.C. Bayesian Inference in Statistical Analysis; Addison-Wesley Publishing Company, Inc.: Boston, MA, USA, 1973. [Google Scholar]
- Carlin, B.P.; Chib, S. Bayesian Model Choice via Markov Chain Monte Carlo Methods. J. R. Stat. Soc. Ser. B 1995, 57, 473–484. [Google Scholar] [CrossRef]
- Ntzoufras, I. Bayesian Modeling Using WinBUGS; John Wiley & Sons: Hoboken, NJ, USA, 2009; ISBN 9780470141144. [Google Scholar]
- Vasishth, S. Additional Notes on MCMC Sampling. 2020. Available online: https://vasishth.github.io/IntroductionBDA/slides/02MCMCAdditionalNotes.pdf (accessed on 3 July 2023).
- Casella, G.; George, E.I. Explaining the Gibbs Sampler. Am. Stat. 1992, 46, 167–174. [Google Scholar] [CrossRef]
- Vega, R.; Flores, L.; Greiner, R. SIMLR: Machine Learning inside the SIR Model for COVID-19 Forecasting. Forecasting 2022, 4, 72–94. [Google Scholar] [CrossRef]
- Montaño Moreno, J.J.; Palmer Pol, A.; Sesé Abad, A.; Cajal Blasco, B. Using the R-MAPE Index as a Resistant Measure of Forecast Accuracy. Psicothema 2013, 25, 500–506. [Google Scholar] [CrossRef] [PubMed]
- Lewis, C.D. Industrial and Business Forecasting Methods: A Practical Guide to Exponential Smoothing and Curve Fitting; Heinemann: Penang, Malaysia, 1982. [Google Scholar]
- Teräsvirta, T.; Lin, C.F.; Granger, C.W.J. Power of the Neural Network Linearity Test. J. Time Ser. Anal. 1993, 14, 209–220. [Google Scholar] [CrossRef]
- Chow, G.C. Tests of Equality Between Sets of Coefficients in Two Linear Regressions. Econometrica 1960, 28, 591–605. [Google Scholar] [CrossRef]
- Zeileis, A.; Leisch, F.; Homik, K.; Kleiber, C. Strucchange: An R Package for Testing for Structural Change. J. Stat. Softw. 2002, 7, 1–38. [Google Scholar] [CrossRef]
- Box, G.E.P.; Cox, D.R. An Analysis of Transformations. J. R. Stat. Soc. Ser. B 1964, 26, 211–252. [Google Scholar] [CrossRef]
- Gujarati, D.N.; Porter, D.C. Basic Econometrics, 5th ed.; McGraw-Hill: New York, NY, USA, 2012. [Google Scholar]
- Ramsey, J.B. Tests for Specification Errors in Classical Linear Least-Squares Regression Analysis. J. R. Stat. Soc. Ser. B Stat. Methodol. 1969, 31, 350–371. [Google Scholar] [CrossRef]
- Bai, J.; Perron, P. Computation and Analysis of Multiple Structural Change Models. J. Appl. Econom. 2003, 18, 1–22. [Google Scholar] [CrossRef]
- Daniel, W.W. Applied Nonparametric Statistics, 2nd ed.; PWS-Kent: Boston, MA, USA, 2000. [Google Scholar]
- Lu, Z.L.; Yuan, K.-H. Welch’s t Test. In Encyclopedia of Research Design; Salkind, N.J., Ed.; Sage Publications: Thousand Oaks, CA, USA, 2010; pp. 1620–1623. [Google Scholar]
- Corder, G.W.; Foreman, D.I. Nonparametric Statistics: A Step-by-Step Approach, 2nd ed.; John Wiley & Sons: Hoboken, NJ, USA, 2014; ISBN 9788578110796. [Google Scholar]
- Levene, H. Robust Tests for Equality of Variances. In Contributions to Probability and Statistics; Olkin, I., Ed.; Stanford University Press: Palo Alto, CA, USA, 1960; pp. 278–292. [Google Scholar]
- National Bureau of Economic Research (NBER). U.S. Business Cycle Expansions and Contractions. Available online: https://www.nber.org/research/data/us-business-cycle-expansions-and-contractions (accessed on 3 July 2023).
- McNees, S.K. The 1990-91 Recession in Historical Perspective. N. Engl. Econ. Rev. 1992, 3–22. Available online: https://ideas.repec.org/a/fip/fedbne/y1992ijanp3-22.html (accessed on 1 March 2024).
- Federal Reserve Bank of St. Louis. The Financial Crisis: Timeline of Events and Policy Actions. Available online: https://fraser.stlouisfed.org/timeline/financial-crisis (accessed on 27 October 2024).
- Bureau of Economic Analysis (BEA). Gross Domestic Product, 2nd Quarter 2020: Advance Estimate and Annual Update. Available online: https://www.bea.gov/news/2020/gross-domestic-product-2nd-quarter-2020-advance-estimate-and-annual-update (accessed on 3 July 2023).
- Choir, A.S.; Iriawan, N.; Mutmainah, S.S.K. R Package, version 0.1.4; Neojags: Neo-Normal Distributions Family for Markov Chain Monte Carlo (MCMC) Models in JAGS; CRAN: Windhoek, Namibia, 2025; Available online: https://cran.r-project.org/web/packages/neojags/index.html (accessed on 3 July 2025).
- Choir, A.S.; Iriawan, N.; Suprih Ulama, B.S.; Dokhi, M. MSEPBurr Distribution: Properties and Parameter Estimation. Pak. J. Stat. Oper. Res. 2019, 15, 179–193. [Google Scholar] [CrossRef]
- Iriawan, N. Computationally Intensive Approaches to Inference in Neo-Normal Linear Models; Curtin University of Technology: Bentley, UK, 2000. [Google Scholar]
- Petetin, Y.; Desbouvries, F. Bayesian Multi-Object Filtering for Pairwise Markov Chains. IEEE Trans. Signal Process. 2013, 61, 4481–4490. [Google Scholar] [CrossRef]
- Kulikova, M.V.; Tsyganova, J.V.; Kulikov, G.Y. UD-Based Pairwise and MIMO Kalman-Like Filtering for Estimation of Econometric Model Structures. IEEE Trans. Autom. Control 2020, 65, 4472–4479. [Google Scholar] [CrossRef]
- Mahler, R. The Pairwise-Markov Bernoulli Filter. IEEE Access 2020, 8, 168229–168245. [Google Scholar] [CrossRef]
- Nemesin, V.; Derrode, S. Robust Partial-Learning in Linear Gaussian Systems. IEEE Trans. Autom. Control 2015, 60, 2518–2523. [Google Scholar] [CrossRef]













| Dataset | p-Value (Teräsvirta Test) | p-Value (Chow Test) |
|---|---|---|
| U.S. Real GNP (Q3 1952–Q4 1984) | 0.0306 | |
| U.S. Real GNP (Q1 1947–Q1 2022) | 0.0435 |
| Parameter | U.S. Real GNP Stationary (1952–1984) | U.S. Real GNP Stationary (1947–2022) | ||
|---|---|---|---|---|
| Mean Posterior | SD Posterior | Mean Posterior | SD Posterior | |
| 0.984483 | 0.999992 | |||
| 0.982895 | 0.979957 | |||
| 0.991465 | 0.973342 | |||
| 0.960302 | 0.996083 | |||
| 0.254784 | ||||
| 0.245401 | ||||
| Dataset | Model | MAPE (%) | MAE | ||
|---|---|---|---|---|---|
| In-Sample | Out-of-Sample | In-Sample | Out-of-Sample | ||
| U.S. Real GNP (1952–1986) | Classical MSAR | 3.3042 | 4.3318 | 62.4868 | 159.2326 |
| Classical MSAR-TVP | 1.7592 | 1.8825 | 42.7753 | 69.3366 | |
| Bayesian MSAR-TVP | 2.7762 | 3.6221 | 55.6518 | 131.8436 | |
| Bayesian AR-TVP | 3.5498 | 6.7342 | 84.2860 | 244.9528 | |
| U.S. Real GNP (1947–2024) | Classical MSAR | 6.9597 | 24.2442 | 843.3941 | 5347.443 |
| Classical MSAR-TVP | 4.9582 | 23.8856 | 685.1016 | 5347.443 | |
| Bayesian MSAR-TVP | 5.4784 | 6.5595 | 740.1583 | 3499.565 | |
| Bayesian AR-TVP | 6.3291 | 23.5093 | 868.7970 | 5263.634 | |
| Time | Classical MSAR-TVP | Classical MSAR | Bayesian MSAR-TVP | Bayesian AR-TVP | ||||
|---|---|---|---|---|---|---|---|---|
| MAPE (%) | MAE | MAPE (%) | MAE | MAPE (%) | MAE | MAPE (%) | MAE | |
| Q1 1985 | 1.3760 | 48.8170 | 2.0260 | 71.8787 | 3.1713 | 112.5113 | 6.9276 | 245.7772 |
| Q2 1985 | 1.2760 | 45.3265 | 2.1234 | 75.4419 | 3.4787 | 123.5974 | 7.1414 | 253.7174 |
| Q3 1985 | 1.0136 | 36.0561 | 2.3755 | 84.6972 | 3.6309 | 129.4141 | 7.1982 | 256.4974 |
| Q4 1985 | 0.8515 | 30.3201 | 2.5293 | 90.3695 | 3.8877 | 138.8763 | 7.3696 | 263.1475 |
| Q1 1986 | 1.2988 | 47.2398 | 3.2872 | 11.3241 | 3.4904 | 125.2501 | 6.8679 | 246.6935 |
| Q2 1986 | 1.5150 | 55.3927 | 3.7115 | 135.4495 | 3.4521 | 124.5067 | 6.7387 | 243.1951 |
| Q3 1986 | 1.6899 | 62.0078 | 4.0328 | 147.7120 | 3.5261 | 127.7740 | 6.7243 | 243.6598 |
| Q4 1986 | 1.8825 | 69.3366 | 4.3318 | 159.2326 | 3.6221 | 131.8436 | 6.7342 | 244.9528 |
| Time | Classical MSAR-TVP | Classical MSAR | Bayesian MSAR-TVP | Bayesian AR-TVP | ||||
|---|---|---|---|---|---|---|---|---|
| MAPE (%) | MAE | MAPE (%) | MAE | MAPE (%) | MAE | MAPE (%) | MAE | |
| Q2 2022 | 23.9196 | 5237.5663 | 23.2286 | 5086.2550 | 8.8030 | 1927.5434 | 23.1654 | 5072.4251 |
| Q3 2022 | 23.8045 | 5228.0075 | 23.3967 | 5138.6360 | 8.4942 | 1865.3330 | 23.1692 | 5088.5483 |
| Q4 2022 | 23.7631 | 5234.6219 | 23.5634 | 5191.0252 | 8.1863 | 1802.8022 | 23.2157 | 5114.2143 |
| Q1 2023 | 23.8164 | 5260.2716 | 23.7764 | 5252.0063 | 7.9210 | 1748.6220 | 23.3317 | 5153.4479 |
| Q2 2023 | 23.8920 | 5291.3727 | 23.9794 | 5311.5009 | 7.6495 | 1692.7292 | 23.4510 | 5194.0198 |
| Q3 2023 | 23.8626 | 5304.4369 | 24.0547 | 5348.2078 | 7.2721 | 1613.8294 | 23.4522 | 5213.5621 |
| Q4 2023 | 23.8336 | 5318.1884 | 24.1145 | 5382.2402 | 6.8849 | 1532.0398 | 23.4438 | 5231.6310 |
| Q1 2024 | 23.8856 | 5347.4426 | 24.2442 | 5429.3124 | 6.5595 | 1463.0779 | 23.5093 | 5263.6337 |
| Dataset | Group | KS Test p-Value | Difference Test | p-Value | |
|---|---|---|---|---|---|
| Classical MSAR-TVP | Bayesian MSAR-TVP | ||||
| U.S. Real GNP (1952–1986) | In-Sample | 0.6079 (normal) | 0.0675 (normal) | t-test (unequal variance, Levene’s p ) | |
| Out-of-Sample | 0.7129 (normal) | 0.8426 (normal) | t-test (equal variance, Levene’s p = 0.1148) | 0.004238 | |
| U.S. Real GNP (1947–2024) | In-Sample | (not normal) | 0.2058 (normal) | Mann–Whitney test | |
| Out-of-Sample | 0.5598 (normal) | 0.9942 (normal) | t-test (unequal variance, Levene’s p = 0.0023) | ||
| Dataset | Model | Standard Deviation | |
|---|---|---|---|
| In-Sample | Out-of-Sample | ||
| U.S. Real GNP (1952–1986) | Classical MSAR-TVP | 0.947471 | 1.165966 |
| Bayesian MSAR-TVP | 1.956111 | 0.850760 | |
| U.S. Real GNP (1947–2024) | Classical MSAR-TVP | 4.904877 | 0.238539 |
| Bayesian MSAR-TVP | 3.012078 | 1.672326 | |
| Run Length | State 1 | State 2 |
|---|---|---|
| Maximum Run Length | 131 | 2 |
| Minimum Run Length | 1 | 1 |
| Number of Runs | 8 | 8 |
| ARL | 36.13 | 1.25 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Inayati, S.; Iriawan, N.; Irhamah; Isnaini, U. A Bayesian Markov Switching Autoregressive Model with Time-Varying Parameters for Dynamic Economic Forecasting. Forecasting 2025, 7, 79. https://doi.org/10.3390/forecast7040079
Inayati S, Iriawan N, Irhamah, Isnaini U. A Bayesian Markov Switching Autoregressive Model with Time-Varying Parameters for Dynamic Economic Forecasting. Forecasting. 2025; 7(4):79. https://doi.org/10.3390/forecast7040079
Chicago/Turabian StyleInayati, Syarifah, Nur Iriawan, Irhamah, and Uha Isnaini. 2025. "A Bayesian Markov Switching Autoregressive Model with Time-Varying Parameters for Dynamic Economic Forecasting" Forecasting 7, no. 4: 79. https://doi.org/10.3390/forecast7040079
APA StyleInayati, S., Iriawan, N., Irhamah, & Isnaini, U. (2025). A Bayesian Markov Switching Autoregressive Model with Time-Varying Parameters for Dynamic Economic Forecasting. Forecasting, 7(4), 79. https://doi.org/10.3390/forecast7040079

