Time-series Analysis

R Programming for COVID-19 Time-series Analysis

Vikrant thakur
4 min readOct 8, 2021

Introduction:

Time-Series Analysis Graph

Time series the title of this Machine learning technique itself defines that it is dependent on time. In analysis or prediction of data of sales, weather, economic growth, Score prediction and much such time is really important. Time is not dependent on any variable so it is always an independent variable. A time series is a series of data points that are dependent on the time variable. Most of the time such series analysis is used to predict the future value of the variable which is dependent on the time variable. There are some basic terms that we need to understand before moving ahead let us define them one by one: -

1) Markov property and stationarity in time series:

In the most accurate sense, stationarity means that the mathematical properties of the timing process do not change over time. It does not mean that the series does not change over time, just that the way it changes does not change by itself over time. Algebraic equality is, therefore, a direct function, perhaps, not always performed; the amount of direct activity changes as 𝒙 grows, but the way it changes remains constant — it has a constant slope; one value that holds that number of changes.

Stationary Time series

Stationarity is one of the most important properties of time series. A time series is stationary if its statistical properties do not change over time.

2) Seasonality of time series:

Seasonal itself means for a specific time. Seasonality refers to the temporary fluctuation in the values of any variable over the given or considered course of time.

3) Autocorrelation:

Informally, autocorrelation is the similarity between observations as a function of the time lag between them. It is the similarity between the time series and a lagged version of itself.

4) White Noises:

These are the unwanted, unique, and random data in the dataset. For a time series to be white noise, the mean should be zero and the variable should be independent and ideally distributed.

ARIMA Model:

The ARIMA is an acronym for the Autoregressive Integrated Moving Average Model. It is a statistical class for the classification of time series data.

There are non-seasonal ARIMA (p,d,q) consist of:

P: No. of Auto-regressive terms

D: No. of Non-seasonal difference needed for stationarity

Q: No. of lagged forecast errors in the model equation

For White Noises, all the three above parameters of the ARIMA Model are zero.

i.e., ARIMA(0,0,0)

Ø R code for ARIMA: white_noice = arima.sim(list(order = c(0,0,0) , n = 300)))

Fitting Data in Time series:

ð Steps before starting to fit data:

1) Check stationarity

2) If not stationary: Transform it to stationarity

3) Fit ARIMA and determine parameters

4) Check if it is a good fit

5) Forecast the future

Converting Stationary data into non-stationary:

Isolate the deterministic parameters

For Ex: — check trends (Growing company), Seasonality (Tourism revenue)

GARCH MODEL:

Generalized Autoregressive Conditional Heteroskedasticity (GARCH) is a statistical version utilized in reading time-series statistics wherein the variance errors are believed to be serially autocorrelated. GARCH models assume that the variance of the error term follows an autoregressive transferring average procedure.

GARCH models are used while the variance of the mistake term is not regular. that is, the mistake term is heteroskedastic. Heteroskedasticity describes the irregular sample of variation of an error time period, or variable, in a statistical version.

Example of Time series Analysis in R:

Below is the image which contains the source code for the R Time series of Covid-19 In India.

For this program we will use the R package named Lubridate which makes it easy for us to work with data and time.

x <- c(580, 7813, 28266, 59287, 75700,
87820, 95314, 126214, 218843, 471497,
936851, 1508725, 2072113)

library(lubridate)

# output of png file
png(file =”timeSeries.png”)

mts <- ts(x, start = decimal_date(ymd(“2020–01–22”)),
frequency = 365.25 / 7)

# plot the graph
plot(mts, xlab =”Weekly Data”,
ylab =”Total Positive Cases”,
main =”COVID-19 Pandemic”,
col.main =”darkgreen”)

# save the file
dev.off()

The Ouput: -

Ouput

Conclusion:

Arima is a fantastic tool for time-collection analysis, and automobile

Arima programs make the technique of satisfactory-tuning a lot simpler always plot your data and carry out EDA on the way to get higher expertise of the records.

Mastering the technicalities in the back of distinctive prediction fashions permit you to choose the appropriate one.

GARCH models describe the financial market in which volatility can change, it can become highly volatile during periods of financial crises and become less volatile if there are no economic crises and is steady economic growth

--

--