Pa ge 1 Pa ge 70 American Journal of Smart Technology and Solutions (AJSTS) R-Shiny Web Application Development for Multilayer Perceptron State Switching Model for Predicting Regimes of Time Series Returns Oluwasegun Agbailu Adejumo1*, Omorogbe Joseph Asemota1, Samuel Olayemi Olanrewaju1 Volume 4 Issue 2, Year 2025 ISSN: 2837-0295 (Online) DOI: https://doi.org/10.54536/ajsts.v4i2.5956 https://journals.e-palli.com/home/index.php/ajsts Article Information ABSTRACT Received: August 14, 2025 Accepted: September 22, 2025 Published: October 21, 2025 Forecasting regimes in financial time series is complicated by nonlinearity and small- sample limitations, where conventional Markov Switching Models (MSMs) and regime- switching autoregressive models often underperform. To address this, we developed an interactive R-Shiny Web Application implementing the recently introduced Multilayer Perceptron State Switching Model (MLPSSM). The app integrates neural networks to capture nonlinear intra-regime patterns with Markov switching structures to identify latent regime transitions. Using Nigerian exchange rate returns as a case study, the app demonstrated robust performance across diagnostics, estimation, and forecasting. Residual checks confirmed that the hybrid approach effectively modeled underlying dynamics, while forecasts achieved lower RMSE and MAE than baseline MSMs. The web-based interface further enhances accessibility, enabling both technical and non-specialist users to apply advanced regime-switching methods without coding expertise. The MLPSSM Web App thus bridges machine learning and econometric modeling, offering a practical, reproducible tool for regime prediction in financial markets. Keywords Financial Time Series Returns, Markov Process, MLPSSM, R Shiny, Regime Switching 1 Department of Statistics, Faculty of Science, University of Abuja, Abuja, Nigeria * Corresponding author’s e-mail: agbailuoa@gmail.com INTRODUCTION Financial time series data, such as stock returns, exchange rates, and commodity prices, are often characterized by nonlinearity, volatility clustering, and structural regime shifts. Traditional linear time series models, while useful for short-term forecasting, are limited in their ability to capture abrupt changes between economic states such as bull and bear markets or high- and low-volatility regimes (Hamilton, 1989; Krolzig, 1997). To address these limitations, researchers have developed state- switching models, including the Markov Switching Model (MSM) and Regime-Switching Autoregressive Models, which explicitly account for stochastic regime shifts and structural breaks. These models have been widely applied in empirical finance to enhance the understanding of market dynamics and improve predictive performance in risk-sensitive environments (Ang & Timmermann, 2012). Despite their popularity, conventional MSMs and regime-switching autoregressive models demonstrate poor predictive performance in small-sample settings, which is a common challenge in emerging markets and in high-frequency but short-span datasets. Under such conditions, parameter estimates become unstable, leading to unreliable regime classification, weak predictive power, and difficulty in distinguishing genuine structural shifts from random noise (Psaradakis & Spagnolo, 2003; Chauvet & Potter, 2000). These shortcomings limit the applicability of MSMs and related models, especially in contexts where robust regime detection is most critical for investors, policymakers, and risk managers. To overcome these challenges, recent research has explored the integration of neural networks into regime- switching frameworks. Neural networks excel at capturing nonlinear patterns, hidden structures, and complex dependencies within financial data that conventional linear models often fail to detect (Zhang et al., 1998). By combining the flexibility of machine learning with the interpretability of regime-based approaches, Neural Network State Switching Models (NN-SSMs) have emerged as promising alternatives for predicting time series regimes (Yao et al., 1999). A notable advancement in this field is the study by Adejumo et al. (2025), who introduced the Multilayer Perceptron State Switching Model (MLPSSM), a novel hybrid approach that embeds a neural network within a regime-switching framework. Their findings demonstrated that the MLPSSM consistently outperforms traditional MSMs and regime-switching autoregressive models, particularly in small-sample environments and in accurately predicting regime transitions. By addressing the weaknesses of conventional models, the MLPSSM provides a more robust and reliable tool for forecasting financial returns under volatile and structurally shifting conditions. However, while Adejumo et al. (2025) established the methodological superiority of the MLPSSM, its practical application remains constrained by accessibility barriers. Financial analysts and policymakers often lack the programming expertise to implement advanced hybrid models, and existing statistical software environments do not provide user-friendly, interactive platforms for real- time regime prediction. In response, the present study focuses on the development of an R-Shiny Web Application for the MLPSSM Pa ge 71 https://journals.e-palli.com/home/index.php/ajsts Am. J. Smart. Technol. Solutions 4(2) 70-79, 2025 introduced by Adejumo et al. (2025). R-Shiny provides an ideal platform for operationalizing this optimal model into an interactive, scalable, and accessible tool. Through this web application, users will be able to upload datasets, configure model parameters, visualize regime-switching dynamics, and generate real-time forecasts without the need for advanced coding. Thus, this research makes a dual contribution: methodologically, by extending the work of Adejumo et al. (2025) through application- oriented development of the MLPSSM; and practically, by democratizing access to advanced predictive models for financial analysts, researchers, and policymakers in Nigeria and other emerging economies where regime shifts and structural breaks are frequent. MATERIALS AND METHODS Following Hamilton (2005), the MSSM addresses the hidden states weakness of the Hidden Markov Model (HMM). To describe the MSSM, we assume that the number of states (or States) is N=2, i.e. St Ω={1,2}. This implies that; for instance, the log returns of financial time series are drawn from distinct normal distributions, depending on what state the HMM is currently in. This would give us the following model to work with: This means that when the state of the HMM for time t is 1, then the expectation of the dependent variable is μ1 and the variance of the innovations is σ1 2, similarly when the state of the HMM for time t is 2, then the expectation of the dependent variable is μ2 and the variance of the innovations is σ2 2 and so on. Since the underlying Markov chain is hidden one cannot observe what state the HMM is in directly, but only deduce its operation through the observed behaviour of Yt. In order to attain the probability law governing the observed data Yt a probabilistic model of what causes the change from state St=i to state St=j is required. This can be specified using the transition probabilities of an N=2 state HMM; ρi,j=Pr (St=j│St-1=i) i,j∈Ω={1,2} ....(2) The transition probability (2) is by the Markov property; dependent of the past only through the value of the most recent state. This is one of the central points of the structure of a Markov state switching model, i.e. the switching of the states of the underlying HMM is a stochastic process itself. There are several ways to estimate the required parameters of the 2-state MSSM given by (1), for instance by using the maximum likelihood estimation method. The Multilayer Perceptrons State Switching Model (MLPSSM) by Adejumo et al. (2025) To improve the regime prediction performance of the famous state switching model described in equation (1) for nonlinear time series data, especially returns, in small sample size contexts, Adejumo-Agbailu et al. (2025) integrate deep neural networks such as Multilayer Perceptrons (MLP) with Markov two-State Switching modelling technique. The Adejumo-Agbailu et al. (2025) neural network state switching modeling approach combines the strengths of MLP-deep neural networks (i.e., efficient in high complexity datasets) and Markov two-state switching capabilities of ensuring both interpretability and predictability of the two Nigerian exchange returns’ regimes (i.e., bull and bear states). The models were introduced in two phases. 1st Phase: Generative Network using MLP Given time series dataset of Yt, the generative network procedure for the dataset include the following: Define of training and testing dataset of Yk i.e. by setting training dataset at time step tk, and testing dataset at time step tt-k At time step tk, MLP is used to process the input data (i.e. training dataset) such as hk~mlph (yt ). 2nd Phase: Integration of Generative Network ht into the Markov Two-State Switching Model Subsequently, the generative network ht is integrated in the Markov two-state switching model alongside the defined training dataset to develop the Multilayer Perceptrons State Switching Model (MLPSSM). This would give us the following model to work with: Ytk~ht)=gt=cst+Β1(gt-1-cst-1)+Β2 (gt-2-cst-2))+ϵt ....(7) where cst=c0 S0t+c1 S1t+c2 S2t σst 2=σ1 2 S1t+σ2 2 S2t ϵt~i.i.d(0,σst 2) cst is the state dependent mean, σst 2 is state dependent variance and the coefficients are Β1or Β2; which could be different for different subsamples. The proposal will be to model the state St as the outcome of an unobserved two-state Markov chain with St independent of ϵt for all t. The transitions of the St, are presumed to be ergodic and intricate first order Markov-process. This means impacts of earlier observation(s) for the gt and state(s) is/are completely captured in the recent gt state(s) observations as represented in (3); ρij=Prob(St=j ⁄ St-1) =i) ∀i,j=1,2∑i=1 2ρij =1 ....(8) Matrix P captures the probability of switching which is known as a transition matrix; ....(9) Where, P11+P21=1, and P12+P22=1 The nearer the probability ρij is to one the longer it takes to shift to the next regime. Consider the model given by equation (7), i.e., a Markov regime-switching model with 2-regimes. The estimation will be performed using Hamilton’s filter, where the main idea is to calculate each state’s filter probabilities by making inferences on each state’s unknown probabilities based on the available information. The MLPSSM Web Application Development MLPSSM is a web application developed in the Shiny environment, leveraging a variety of R libraries and Pa ge 72 https://journals.e-palli.com/home/index.php/ajsts Am. J. Smart. Technol. Solutions 4(2) 70-79, 2025 packages to provide a comprehensive regimes of time series returns modelling and predicting experience. Currently, there are more than 12,000 R packages or libraries available, which are the result of a collaborative project sustained by individuals from different parts of the world and disciplines. The project continues to grow both in the number of packages and in knowledge areas, such as statistics, finance, genetics, network analysis, and data mining, among many others (Cruz et al. 2023). This application has been designed to facilitate efficient and effective time series returns data exploration, preliminary analysis, regime modelling and predicting. To ensure optimal functionality and a wide range of features, MLPSSM makes use of libraries and packages in R. You can view the application at the following URL: https://agbailuoa.shinyapps.io/MLPSSM_App/ The user interface of MLPSSM has been carefully designed using the Shiny package in R, providing a smooth and intuitive experience for users. Shiny is an R package that allows the construction of interactive web applications from R scripts. The application is organized into different tabs, each with specific functionalities. The application architecture includes: i. Frontend; shiny, shinydashboard for UI (upload, plots, model outputs). ii. Backend; Neural networks via RSNNS::mlp, regime- switching via MSwM::msmFit. iii. Support packages; forecast, tseries, lmtest, Metrics, ggplot2 for tests, diagnostics, and forecasting. Figure 1 presents a flowchart of the MLPSSM App. Figure 1: Flowchart of the Application: MLPSSM App MLPSSM App User Interface The user interface of MLPSSM App welcomes you to an interactive and enriching experience. Here you will find a concise description of the application’s functionalities, Figure 2 presents the user interface of the developed MLPSSM App. According to Figure 2, the application includes tabs for Upload Data, a Time Series, a Model Output, Residuals, and a Forecast. The Upload Data tab allows users to load returns time series, i.e. rt=ln(Rt⁄Rt-1 ), in CSV format. The Time Series tab presents users with the time series plot and preliminary tests of the series such as the ADF test (stationarity test) and BDS test (non-linearity test). The Model Estimation tab allows users to estimate the novel MLPSSM and provides the estimated model’s transition probability plots. The Residuals tab allows users to assess the diagnosed residuals of the estimated MLPSSM, including the residuals plot, Ljung-Box test, and Shapiro- Wilk test. Lastly, the Forecast tab enables users to forecast or predict the returns-regime means and the model performance metrics Mlpssm App Evaluation This section presents and discusses the deployment and evaluation of the MLPSSM Web App using the sample size 30 of daily Nigeria Exchange Rate returns. Figure 3 presents the “Data Upload” interface of the app using the aforementioned dataset. The app successfully ingested the Nigeria Exchange Rate (USD/₦) daily data from CBN (11th June–23rd July 2025). The data upload interface was limited to CSV files, ensuring standardized inputs. The app extracted the second column of the dataset as the time series and visualized it under the Time Series tab. This confirms the reactivity of the app, as the uploaded data was immediately transformed into plots and summary previews for the user. By visualizing the exchange rate returns, the app provides users with an intuitive entry point before model estimation. Subsequently, the time series is visualized in the “Time Series” tab, just below the “Upload & Settings” tab. The plotOutput function is used to display the graph of the time series in levels. The reactivity of the application is reflected in the outputs, which are the results (numeric values, plots) received by the interface from the server.R. In our case, the result is a graph and it is inserted using the plotOutput() function (Figure 4). The inclusion of Augmented Dickey-Fuller (ADF) and BDS (Brock-Dechert-Scheinkman) tests within the Time Pa ge 73 https://journals.e-palli.com/home/index.php/ajsts Am. J. Smart. Technol. Solutions 4(2) 70-79, 2025 Figure 2: The User Interface of MLPSSM Web App Figure 3: Data Upload Interface of the MLPSSM Web App Figure 4: Time Series Plot of the Nigeria Exchange Rate Returns using the Time Series tab of the App Series tab allowed for formal pre-model diagnostics. - ADF Test: Evaluates whether the returns are stationary. If the null hypothesis of a unit root is rejected, the series can be considered stationary. In most exchange rate returns, stationarity is expected after transformation into returns. - BDS Test: Evaluates non-linearity and independence of residuals. Significant results indicate the presence of hidden structure, justifying the need for nonlinear hybrid models like MLPSSM. In this evaluation, the results confirmed stationarity and non-linearity, validating the use of a nonlinear, regime- switching hybrid model. Pa ge 74 https://journals.e-palli.com/home/index.php/ajsts Am. J. Smart. Technol. Solutions 4(2) 70-79, 2025 Figure 5: ADF Test Results of the Nigeria Exchange Rate Returns using the Time Series tab Figure 6: BDS Test Results of the Nigeria Exchange Rate Returns using the Time Series tab Pa ge 75 https://journals.e-palli.com/home/index.php/ajsts Am. J. Smart. Technol. Solutions 4(2) 70-79, 2025 Figure 7: MLPSSM Estimation for the Nigeria Exchange Rate Returns using the Model Estimation tab Figure 8: Regimes Transition Probabilities of MLPSSM Estimated of the Nigeria Exchange Rate Returns using the Model Estimation tab The Model Estimation tab provided the estimated parameters of the MLPSSM (a combination of neural networks for nonlinear fitting and Markov switching models for regime identification). - Estimation Results (Figure 7): These show the fitted coefficients and transition probabilities of the model. The estimates suggest the model successfully learned from the exchange rate returns. - Transition Probabilities (Figure 8): The graph displayed probabilities of switching between regimes (bear vs. bull). High self-transition probabilities suggest persistence within regimes, while non-trivial switching probabilities capture regime dynamics. This indicates that the app correctly implements the regime identification logic, a major improvement over conventional MSMs and ARSSMs, which often perform poorly in small samples. Pa ge 76 https://journals.e-palli.com/home/index.php/ajsts Am. J. Smart. Technol. Solutions 4(2) 70-79, 2025 Figure 9: Residuals Plot of the Estimated MLPSSM using the Residuals tab Figure 10: Residuals Diagnostics of the Estimated MLPSSM using the Residuals tab Pa ge 77 https://journals.e-palli.com/home/index.php/ajsts Am. J. Smart. Technol. Solutions 4(2) 70-79, 2025 Figure 11: Forecast Plot of the Estimated MLPSSM using the Forecast tab Figure 12: Forecast Estimate of the Estimated MLPSSM using the Forecast tab Pa ge 78 https://journals.e-palli.com/home/index.php/ajsts Am. J. Smart. Technol. Solutions 4(2) 70-79, 2025 Figure 13: Estimated MLPSSM Performance Metrics using the Forecast tab Afterward, The Residuals tab provided three diagnostic checks: residual plots, Ljung-Box test, and Shapiro-Wilk test. - Residual Plot (Figure 9): Shows whether errors fluctuate randomly around zero. A fairly random pattern indicates good fit. - Ljung-Box Test (Figure 10): Checks if residuals are autocorrelated. A non-significant result suggests residual independence. - Shapiro-Wilk Test (Figure 10): Tests normality of residuals. This ensures validity of statistical inferences. Together, these diagnostics confirm whether the hybrid model adequately captures the dynamics in the data. In this evaluation, the residual diagnostics suggested that the MLPSSM provides a statistically adequate fit, with minimal autocorrelation and approximate normality. The Forecast tab generated three outputs: - Forecast Plot (Figure 11): Displayed short-horizon projections of exchange rate returns. - Forecast Estimates with Regimes (Figure 12): Highlighted regime-dependent forecasts (bear vs. bull), making it useful for risk management and trading strategy design. - Performance Metrics (Figure 13): Reported forecast accuracy measures (RMSE, MAE). These quantitative metrics confirmed the predictive strength of the MLPSSM in small-sample forecasting. The hybrid model outperformed conventional regime- switching models in terms of both forecast precision and regime classification accuracy, aligning with Adejumo et al. (2025)’s theoretical contributions. The deployment and evaluation of the MLPSSM Web App demonstrated, technical correctness (i.e. proper integration of reactivity, diagnostics, regime estimation, and forecasting), practical relevance (i.e. useful outputs for researchers, policymakers, and investors in financial markets), methodological novelty (i.e. the app operationalizes Adejumo et al. (2025)’s neural- network-based hybrid model, overcoming weaknesses of traditional MSMs in small samples), and user accessibility (i.e. with simple tabs and automated tests, non-technical users can upload data, check assumptions, run hybrid models, and obtain forecasts). Discussion The evaluation of the Multilayer Perceptron State Switching Model (MLPSSM) Web Application demonstrates its capacity to address long-standing methodological and practical challenges in regime prediction within financial time series. Conventional Markov Switching Models (MSMs) and regime-switching autoregressive models (ARSSMs) have often been limited in their predictive capacity, especially under small-sample conditions, where parameter instability and regime misclassification become prominent issues (Hamilton, 1989; Krolzig, 1997). Recent studies, including Adejumo et al. (2025), have argued that hybrid frameworks combining neural networks with regime-switching methods offer a robust alternative by integrating nonlinear approximation with probabilistic regime identification. The performance of the app across data input, model estimation, residual diagnostics, and forecasting validates these theoretical expectations. Pre-model diagnostics confirmed both stationarity and non-linearity in the Nigerian exchange rate returns, justifying the application of a nonlinear, regime-dependent framework. The MLPSSM successfully captured hidden regime dynamics through a two-stage estimation; first modeling nonlinear intra- regime patterns using multilayer perceptrons (MLPs), and subsequently applying a Markov-switching structure to the residuals. The transition probability estimates highlighted persistent regime behaviors, while allowing for realistic switching, aligning with empirical evidence in financial markets where volatility clustering and regime persistence are common (Hamilton & Susmel, 1994). Residual diagnostics further reinforced the adequacy of the hybrid approach. The Ljung-Box and Shapiro-Wilk results indicated that the residuals were largely uncorrelated and approximately normal, suggesting that the hybrid model extracted most of the signal embedded in the series. These results compare favorably to conventional MSMs, which often leave strong autocorrelation structures unmodeled, thereby undermining their predictive reliability (Maheu & McCurdy, 2000). The forecasting module provided perhaps the most critical evidence of the app’s utility. Both the point forecasts and the regime-dependent projections showed strong predictive accuracy, as reflected in the RMSE and MAE metrics. These results substantiate the claim by Adejumo et al. (2025) that the MLPSSM can outperform baseline regime-switching methods, particularly in small samples where neural networks are able to flexibly capture nonlinear structures that traditional parametric forms miss. The integration of forecasts with regime classifications also provides added interpretive value for practitioners in risk management and policy analysis, who Pa ge 79 https://journals.e-palli.com/home/index.php/ajsts Am. J. Smart. Technol. Solutions 4(2) 70-79, 2025 require not just point estimates but also insights into underlying market conditions. Beyond methodological contributions, the deployment of this model in a Shiny Web Application represents an important step toward accessibility and reproducibility. By embedding advanced methods in an interactive interface, the app democratizes the use of sophisticated econometric techniques, enabling both technical and non-technical users to conduct diagnostics, fit models, and generate forecasts. This aligns with recent calls in computational economics and data science for tools that bridge methodological rigor and usability (Chambers & Hastie, 1992; Varian, 2014). CONCLUSIONS In summary, the MLPSSM Web App provides empirical evidence for the superiority of neural-network-enhanced regime-switching approaches over conventional methods. It not only validates the theoretical advances proposed by Adejumo et al. (2025) but also operationalizes them in a user-friendly platform that can be applied to diverse time series forecasting tasks. These findings highlight both the academic novelty and the practical relevance of integrating machine learning with classical state-space and regime-switching frameworks. From a policy and practical perspective, the implications are significant. For policymakers in Nigeria and other emerging economies, the ability to identify and forecast financial regimes in exchange rate markets provides a valuable tool for anticipating volatility and implementing timely interventions. Regulators can apply the app’s diagnostic and forecasting features to monitor systemic risks, while financial institutions can leverage the regime predictions to inform hedging strategies and risk-adjusted investment decisions. Moreover, by operationalizing advanced econometric and machine learning techniques within a Shiny Web App, this study bridges the gap between methodological innovation and practical accessibility. The interactive dashboard ensures that both technical experts and non-specialist users can upload data, conduct diagnostics, fit models, and interpret results without extensive coding skills. This democratization of advanced forecasting methods supports capacity building within financial institutions, academic research, and policy circles. Nevertheless, limitations remain. The two-stage estimation approach assumes that regime structure lies entirely in residual dynamics, which may overlook deeper joint interactions. Additionally, small-sample robustness, while improved over MSMs, still warrants further exploration through regularization techniques and Bayesian extensions. Future research should also extend the Web App to multivariate series and high-frequency data, as well as integrate real-time data streaming for dynamic monitoring. In conclusion, the MLPSSM Web App provides a practical and innovative tool for regime prediction and forecasting in financial time series. It validates the theoretical contributions of Adejumo et al. (2025) and extends them into a usable platform with direct policy and market relevance. The study contributes both to the advancement of econometric methodology and to the provision of applied solutions for managing uncertainty in financial markets. REFERENCES Adejumo, O. A., Asemota, O. J. & Olanrewaju, S. O. (2025). Novel Neural Network State Switching Models for Returns Predicting with Regime Switching: A Monte Carlo’s Simulation Approach. American Journal of Applied Statistics and Economics, 4(1). Ang, A., & Timmermann, A. (2012). Regime changes and financial markets. Annual Review of Financial Economics, 4, 313–337. Chambers, J. M., & Hastie, T. J. (1992). Statistical models in S. Wadsworth & Brooks/Cole. Chauvet, M., & Potter, S. (2000). Coincident and leading indicators of the stock market. Journal of Empirical Finance, 7(1), 87–111. Cruz, T., Jimenez, F. G., Bravo, A. R. Q., & Ander, E. (2023). DataXploreFines: Generalized Data for Informed Decision, Making, An Interactive Shiny Application for Data Analysis and Visualization. arXiv preprint arXiv:2307.11056. Hamilton, J. D. (1989). A new approach to the economic analysis of nonstationary time series and the business cycle. Econometrica, 57(2), 357–384. https://doi. org/10.2307/1912559 Hamilton, J. D., & Susmel, R. (1994). Autoregressive conditional heteroskedasticity and changes in regime. Journal of Econometrics, 64(1–2), 307–333. https://doi. org/10.1016/0304-4076(94)90067-1 Krolzig, H.-M. (1997). Markov-switching vector autoregressions: Modelling, statistical inference, and application to business cycle analysis. Springer. Maheu, J. M., & McCurdy, T. H. (2000). Identifying bull and bear markets in stock returns. Journal of Business & Economic Statistics, 18(1), 100–112. https://doi.org/ 10.1080/07350015.2000.10524846 Psaradakis, Z., & Spagnolo, N. (2003). On the determination of the number of regimes in Markov- switching autoregressive models. Journal of Time Series Analysis, 24(2), 237–252. Varian, H. R. (2014). Big data: New tricks for econometrics. Journal of Economic Perspectives, 28(2), 3–28. https:// doi.org/10.1257/jep.28.2.3 Yao, J., Tan, C. L., & Poh, H. L. (1999). Neural networks for technical analysis: A study on KLCI. International Journal of Theoretical and Applied Finance, 2(2), 221–241. Zhang, G., Patuwo, B. E., & Hu, M. Y. (1998). Forecasting with artificial neural networks: The state of the art. International Journal of Forecasting, 14(1), 35–62.