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:adf.test()
.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.
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.
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.
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.