INTEGRATED OF WEB APPLICATION RSHINY FOR MARKOV CHAIN AND ITS APPLICATION TO THE DAILY CASES OF COVID-19 IN WEST SUMATERA

ABSTRACT


INTRODUCTION
Corona disease-2019, also known as COVID-19, is an infectious disease caused by the SARS-Cov-2 virus.This disease was discovered at the end of 2019 in Wuhan, China.The virus quickly spread throughout numerous countries, and the World Health Organization proclaimed Covid-19 a pandemic in March 2020.According to [1] COVID-19 transmission can occur through direct contact with respiratory droplets of an infected individual (produced by coughing and sneezing) and touching surfaces contaminated with the virus.Fever, coughing, and shortness of breath are some of the symptoms.The infection can lead to pneumonia or difficulty breathing in more severe situations [2].
The disease quickly spread around the world, including in Indonesia.On March 2, 2020, the first positive case of COVID-19 was discovered in Indonesia.In a reasonably short time, COVID-19 spread to 34 provinces in Indonesia.One of them is West Sumatra Province, COVID-19 has spread since March 26, 2020, with the discovery of five positive cases [3].A lot of research has been done in modelling the COVID-19 phenomenon.This paper uses the Markov chain method to predict the long-term chances of COVID-19 cases.
Markov chain is a stochastic model that describes a succession of possible occurrences in which the probability of each event is determined solely by the state obtained in the preceding event [4]- [8].The Markov chain method has been widely used in research.K. J. Doubleday and J. N. Esunge apply the Markov chain discrete-time stochastic model to determine the relationship between various stock portfolios and the market as a whole However, in these studies, manual calculations were carried out using software such as Maple, Ms Excel, and Matlab, which require a relatively long time to process the data.Along with the development of science, processing data can use the help of software.One is software R. Software R is software for data analysis purposes.Software R has advantages, including being open-source and easy to understand compared to other programming languages, can speed up data processing, and provide more accurate results [16].The features offered by R software are complete for data processing needs.The R script built can be used as a Web Application with RShiny [17].RShiny is a package from RStudio used to create interactive web applications.Other users in processing data can use web applications that have been created with RShiny [18].The user uploads the data to be processed, and the output of the processing results can be immediately displayed on the web application RShiny display.The benefits of using RShiny for researchers are speeding up data processing and an interactive display.This paper builds commands into an R script for discrete-time Markov chains to simplify and speed up data processing.Besides that, the R script does not require other software.The algorithm for composing the R script begins with inputting data which the Markov chain will then process.Data is defined in several states and expressed by a transition probability matrix.The th-day probability will calculate by using the n-step distribution.The R script was created to classify the Markov chain's state, including irreducible, positive recurrent, and aperiodic conditions for an ergodic Markov chain-calculating long-term probabilities using the Markov chain stationary distribution.The R script was developed into an integrated web application RShiny for the Markov chain.In this research, the developed RShiny web application is limited to two and three states.Furthermore, the web application RShiny is published for data processing.The data used in this study is daily case data of COVID-19 in West Sumatra from March 26, 2020, to October 20, 2020.

Software R and Web Application RShiny
R is statistical software for data analysis purposes [16].Software R has advantages, including many data processing options with complete features; it is easier to learn and run to process data than other programming languages.R is free and open-source, so there is no need for licensing fees which are usually very expensive for data processing software.Suitable for both beginners and experts.Packages "markovchain" is a library that makes it easy to process data using the discrete Markov time chain method.The "markovchain" packages are equipped with functions to perform data analysis.For example, these packages can calculate the stationary distribution and classify state space [19].
Shiny is a set of RStudio tools for creating interactive web apps [11].Shiny makes creating interactive web apps in R relatively straightforward.Applications that are sophisticated, accessible, and efficient can be constructed [20].Shiny's official website can be found at https://shiny.rstudio.com.
Web applications RShiny make it very easy for users to process data.RShiny can be accessed via the web without running a script on RStudio.The web application is flexible because it can be accessed via PC, smartphone, and tablet.The web application RShiny consists of a user interface script and a server script as shown in Figure 1 [17].User interface scripts should be named ui.r,which controls input data, variables, and models.Display controls in the user interface script include sliders, radio buttons, and checkboxes.The user interface is used to enter input values and presentations, which can be graphics, numbers, and text.Server scripts are stored in a file named server.r.The server is the program's brain that contains all the data processing procedures and then sends the results to the output section.ShinyApp can be run with a combination of ui.r and server.rsimultaneously.
Note that () =  denotes that the process is in state  ( = 0,1,2, … ) at time ( = 0,1,2, … ).The conditional probability in Equation (1), which describes the whole history is independent of the past history at time 0,1,2, … ,  − 1 and depends to the "future" state depends only on the "present" state and is independent of "past" history.Such a property is called the Markov Property.The probability of transition from state  to state  (  ) in Equation (1) can be expressed in the transition probability matrix ().The state  is said to be recurrent if and only if,

𝐏 = [𝑝
State  is transient if and only if, c) Periodicity The period of the state  is denoted by being the greatest common divisor (gcd) of the integers where () ≥ 1   > 0.
If () = 1, the state  is said to be aperiodic.
If () > 1, the state  is said to be periodic.

d) Positive Recurrent
If the state  is recurrent and aperiodic, then If the state  is recurrent and periodic, then which is free from the initial state , with {  ,  = 0,1,2, … } it is singular and it is the positive solution of and {  } is called the Markov chain stationary distribution [15].

Build Script R for the Markov Chain
Building script R for the Markov chain is required packages for processing data, such as "markovchain" packages, "diagrams", and "dplyr".The Markov chain integrated R script was built for three states in this research.Data were defined and classified using criteria based on the difference between day and day data.Let is the nth day of data if it is defined as state 0 (downstate), if it is defined as state 1 (stagnation state), and if it is defined as state 2 (upward state).First, we define the data into several states and calculate the transition probability.Script R is built to define and classify each state.The transition probability of each state is expressed in the transition probability matrix following Equation (2).The transition probability of each step is calculated quickly and automatically with the built R Script.The transition probability is calculated using an if-else statement and process looping by following the steps on the pseudocode that is presented in Algorithm 1.

Creating a Web Application for Markov Chain
The first step to creating a web application using RShiny is to install and import the relevant packages.Two primary packages are typically utilized when constructing web apps using RShiny: the "shiny" package and the "shinythemes" package.The "shiny" package offers a framework for creating interactive user interfaces, while the "shinythemes" package allows you to make more visually appealing display themes.This web application is divided into the user interface (UI) script and the server script.The user interface (UI) configures the web app's visual appearance, including the layout, UI elements, and themes.Server scripts are responsible for processing data, executing computations, and integrating user activities with the user interface displays.Figure 2 depicts an overview of the user interface (UI) script, which may comprise numerous elements such as input panels, graphics, text, and other components required to generate the desired interactive display.Add buttons, sliders, text input boxes, and so on.Meanwhile, Figure 3 displays the server script, which performs numerous operations and calculations.
Server scripts may include data processing, analysis, or mathematical calculations to offer suitable answers to user interface activities.The completed RShiny web application is published when the user interface and server scripts have been constructed and configured as needed.In this regard, Figure 4 depicts a published RShiny web application that may be viewed online via links like https://putrimonika.shinyapps.io/rantaimarkov/.By publishing this web application, you enable others to access and interact with the application you have created via the internet.This process transforms an application that could only be run locally into something that users from various locations can access.As such, the steps involved in developing a web application with RShiny include installing and importing packages, scripting the user interface and server scripts, and the final stage of publishing the application so that it can be accessed online.In addition, you can organize INTEGRATED OF WEB APPLICATION RSHINY FOR MARKOV CHAIN… various elements in the user interface and implement functionality that suits the needs of the application you are developing.

Numerical Experiments
This information is collected via the official website (https://corona.sumbarprov.go.id/).The data records the number of COVID-19 instances in the West Sumatra region daily.Table 1 displays descriptive statistics to provide a more in-depth look at the data.Furthermore, data on the number of people who tested positive for COVID-19 in West Sumatra has been processed into a graph, as shown in Figure 5.The descriptive statistics of daily COVID-19 case data in West Sumatra are shown in Table 1.In this situation, the minimum value is 0, suggesting no COVID-19 cases were reported on that day or period.The maximum value is 544, indicating the number of COVID-19 cases per day or time.The observed variable is associated with an average of 54 persons.The average number of persons is eleven.This means that half of the days or periods have fewer than or equal to 11 notable cases, while the other half have more significant issues than 11.Meanwhile, Figure 5 depicts a graph of the number of people who tested positive for COVID-19 in West Sumatra.This graph shows the trend and variation of daily cases across the period analyzed.By looking at this graph, it is possible to see specific patterns, such as spikes in cases in certain periods, decreasing or increasing trends, as well as potential fluctuations that can provide additional insights for the interpretation of the research results.Data were defined and classified using criteria based on the difference between day− and day−( − 1) data.Let   is the th day of data.If   < 0 is defined as state 0 (downstate), if   = 0 is defined as state 1 (stagnation state), and if   > 0 is defined as state 2 (upward state).Figure 6 shows the transition of each state processed by script R. The probability of a one-step transition from state  to state  (,  = 0,1,2.)is shown in Table 2 below,  7 displays a visual representation of the web application designed to show the order transition probability matrix in a Markov chain that includes three states: 0, 1, and 2. This web application offers users an interactive platform to study and comprehend the probabilities associated with transitions between different states in a Markov chain.States 0, 1, and 2 represent other conditions or situations, and the transition probabilities show the possibility of moving from one state to another during a specific period.Calculations using a web application can be seen in Figure 9.    Figure 12 shows the calculation results from the web application for the stationary distribution.In the long-term, the probability of people testing positive for COVID-19 in West Sumatra in State 0 is 43%, state 1 is 5.8%, and state 2 is 51.2%.State 2 has the most considerable probability, which is an increasing state.This means that the number of people testing positive for COVID-19 in West Sumatra today is higher than the previous day.
An ergodic Markov chain refers to a system that will reach a stationary distribution in the long-term, where the probability for each state will remain constant.This stationary distribution reflects the long-term equilibrium in the transition between states.In this case, the stationary distribution probabilities indicate the relative comparison of COVID-19 cases in three states in West Sumatra.
The calculation results and depiction in Figure 12 provided a more precise knowledge of the long-term probability of switching between states in this system via the web application.It explains the switching tendency between states and the long-term state of the system represented by this ergodic Markov chain.

CONCLUSIONS
Based on the results of the previous chapter, a web application that integrates with a Markov chain can be built.This web application has been published and can be found at https://putrimonika.shinyapps.io/rantaimarkov/.Other researchers can use this application to process data using Markov chains quickly, automatically, and accurately.This online Markov chain integration application is helpful for data analysis, especially during state transitions.The program uses the Markov chain method to predict future events based on historical data, such as daily COVID-19 cases in West Sumatra.Forecast results can provide insight into potential future trends.The results of this integrated web application illustrate probability in the example of COVID-19 data in West Sumatra.The probability of an increase in COVID-19 cases is 51.2%, indicating a potential increase in the future.There is a 43% chance that fewer cases will occur, suggesting that the number of COVID-19 cases may decline.There is a 5.8% chance that the number of cases has not changed, meaning the number of cases may remain stable.These findings are useful for scholars and practitioners interested in understanding the changing dynamics of COVID-19 cases in West Sumatra.This web application allows users to understand state transitions and potential changes quickly.In short, this application facilitates the application of Markov chain methods in data analysis and prediction based on transition patterns discovered in historical data.
[9].F. Kachapova represents the Markov chain with transition diagrams for each state [10].In education, Mardiyah.Maiyastri and D. Devianto use the Markov chain for Forecasting the Student Achievement Index [11].F. N. Masukum, Y.A.R. Langi, and C. Mongi introduced Markov chain analysis to predict consumer movement of airline route Manado-Jakarta [12].Markov chains are also used to forecast rainfall following the data mining approach [13].In the case of COVID-19, Markov chains are used to forecast future conditions using stationary distributions [14], [15].

Figure 5 .
Figure 5. Plot of daily COVID-19 case data in West Sumatra

Figure 6 .
Figure 6.The Display of Web Applications for The Transition of Each State

Figure 7 .
Figure 7. Web Application View for Transition Probability MatrixThe transition diagram in Figure8depicts the state transitions in a Markov chain, which has three different states (0, 1, and 2).The figure represents how each state transitions dynamically between these stages.We may see the probability and patterns that control the passage from one state to another by observing the arrows and links in the diagram.This depiction aids in comprehending the underlying behavior and transitions associated with moving a Markov chain through several states.

Figure 8 .
Figure 8. Web Application View for Diagram Transition

Figure 9 .
Figure 9.The Display of Web Application for Day- Prediction This section examines the Markov chain's state classification.Figure 10 depicts the outcome of the computation using the web application.The result is 1, implying that (0) = (1) = (2) = 1.As a result, states 0, 1, and 2 are aperiodic.

Figure 10 .
Figure 10.The Display of Web Application for Periodicity

Figure 11 .
Figure 11.The Display of Web Application for State Classification This Markov chain is considered an ergodic Markov chain because it is irreducible, positive recurrent, and aperiodic, as determined by studying its state classification.Equation (11) can be used to calculate the long-term probability using the stationary distribution.The following is the long-term probability:  = [ 0 ,  1 ,  2 ] = [0.4299517,0.05797101, 0.5120773](15)

Figure 12 .
Figure 12.Web Application View for Stationery Distribution

Algorithm 3
Algorithm for Calculate the -step distribution If the Markov chain is ergodic, long-term probability can be estimated.Long-term probability was determined using a stationary Markov chain distribution and Equation (11).Algorithm 4 presents the pseudocode for examining the ergodic Markov chain and calculating the stationary distribution of the Markov chain.

Table 2 . Transition Probability form State 𝒊 to State 𝒋
Probability from state  to state  can be expressed in transition probability matrix follows Equation (2).INTEGRATED OF WEB APPLICATION RSHINY FOR MARKOV CHAIN…