1. Time series forecasting using ARIMA models

    This example is important because it introduces the forecasting methodology using ARIMA models in R. The steps are as following:
    • Examining the data by firstly plotting the data. Then, outliers and missing values should be removed.
    • Second step is to decompose the data to observe if there is any seasonality or trend underlying in the data.
    • In the third step, stationarity analysis should be made. One of the stationarity tests that can used is adf.test().
    • Then, ACF and PACF plots should be plotted to examine the autocorrelations. With the help of these plots the order of the ARIMA model can be determined.
    • The fifth step can be regarded as the most important step. In this step a proper ARIMA model is fitted to the data.
    • Finally, the model should be evaluated by checking whether residuals have any pattern and are normally distributed or not. If there are visible patterns or bias, refitting of the model should get under way. After the model is satisfying, the forecast of the intended period can be done.

  1. Forecasting with Simple Linear Regression

    If you have a data consisting of one independent variable and one dependent variable, one of the most widely used methods of forecasting is Simple Linear Regression. The most simple formula for Simple Linear Regression is as follows:

    \[ y = a~0~ + a~1~*x \]

    Again, the first step of fitting a model is to plot and observe if this method can be applied to that data. After the approval of the data \(a0\) and \(a1\) are estimated by using lm() function. Then, applying the original formula using the intended time period as x value, the forecast can be performed.


  1. Simple Exponential Smoothing Technique in R

    To apply this method, the data should be at a constant level and have no seasonality. With these assumptions, simple exponential smoothing can be performed by estimating a parameter called alfa. (Parameters beta and gamma has to equal to 0 in this version.) This parameter, alfa, can be estimated by using the function HoltWinters(). After the determination of that parameter, forecasts for further time points can be done by using the forecast.HoltWinters() function in the R forecast package.

    To plot the predictions made by forecast.HoltWinters(), plot.forecast() function can be used. Again, errors can be calculated using the same procedure as indicated above.


  1. What is a Random Walk and How to Simulate in R?

    Random walks are time series data have the following specific properties:

    • No specified mean or variance

    • Strong dependence over time

    • It’s changes or increments are white noise

    • Most simple non-stationary time series model

    A discrete white noise series is basically a series where all values are independent and identically distributed (IID) with a mean of zero. The basic formula of the random walk is,

    \[ x~(t)~ = x~(t-1)~ + w~(t)~ \]

    Where \(w~(t)~\) is the white noise. Random walks can be simulated by using the cumsum(x) function, which does cumulative summation of the vector x over its entire length.


  1. Fitting a Centered Moving Averages Model in R

    In this method, a number of nearby points are chosen and averaged to estimate the trend. This method provides a more stationary model since finding the average of multiple values lowers the errors associated with residuals.

    To add a new column of moving averages to the data, mutate() function of dplyr package and rollmean() function of zoo package can be leveraged. After the computations, comparisons can be made by plotting the data and calculating the errors associated with this newly formed column and the original one.