A sequence of of data points being recorded at specific times.
plot(AirPassengers)
AirPassengers
time series:library(astsa)
start(AirPassengers)
## [1] 1949 1
end(AirPassengers)
## [1] 1960 12
frequency(AirPassengers)
## [1] 12
length(AirPassengers)
## [1] 144
Overall upward or downward pattern of the data. This trend in the series might be a result of political, economic or technological factors among other factors.
Regular patter of upward/downward fluctuations that occur within certain period of time due to external factors such as waether, customs, holidays ..etc.
Unsystemtaic fluctuations that happen due to random variation or unforseen events.
The components mentioned above can be detected by decomposing the time series.
plot(decompose(AirPassengers))
The simplest exapmple of stationary process. It is a purely random process that has constant mean and variace and has zero autocovariance. Each observation in the white noise series is uncorrelated with all other values in the sequence.
WN <- arima.sim(model = list(order = c(0,0,0)), n = 200)
ts.plot(WN)
A time series said to follow a random walk if the first differences are random. The random walk process can be deemed as the simplest example of non-stationary process.
\(Y_t = Y_t-1 + et\)
\(Y_t - Y_t-1 = et\)
where \(et\) is white noise
RW <- arima.sim(model = list(order = c(0,1,0)), n = 200)
ts.plot(RW)
RW_Drift <- arima.sim(model = list(order = c(0,1,0)), n = 200) + 50
ts.plot(RW_Drift)
A time series in which \(Yt\) depends only on its past values.
\(Y_t - µ = slope(Y_t-1 - µ) + et\)
where µ is the mean
if the slope = 0, then \(Y_t = µ + et\), such that \(Y_t\) is White Noise.
if the slope != 0, \(Y_t\) depends on both \(et\) and \(Y-t-1\)
if the slope = 0 and \(µ\) = 0, then \(Y_t = Y_t-1 + et\) (Random Walk)
AR <- arima.sim(model = list(ar = 0.5), n = 200)
ts.plot(AR)
A time series in which \(Y_t\) depends only on the error terms including the current and the previous ones.
\(Y_t = µ + (slope) et-1\)
If the slope = 0, then \(Y_t = µ + et\), such that \(Y_t\) is White Noise.
If slope != 0, then \(Y_t = µ + (slope) et-1\), \(Y_t\) depends on both \(et\) and \(et-1\) (Autocorrelated).
MA <- arima.sim(model = list(ma = 0.5), n = 200)
ts.plot(MA)
A time series that combines AR model and MA model. In other words, the ARMA model is just an autoregressive model with autocorrelated errors.
\(Y_t = µ + (slope) Y_t-1 + et + (slope) et-1\)
ARMA <- arima.sim(model = list(ar = 0.75, ma = 0.3), n = 200)
ts.plot(ARMA)
The modelling of ARMA model requires the time series to be stationary. Sationary process has a constant mean and variance and has no trend. One technique can be used to transform non-stationary time series into a stationary one is “Differencing”.
Assume that we have a non-stationary process.
A <- arima.sim(model = list(order = c(0,1,0)), n = 200)
ts.plot(A)
If we want to transform the non-stationary process into stationary one, we can apply diffrencing on the time series.
Stationary <- diff(A)
ts.plot(Stationary)
Autocorrelation of a random process is a measure of correlation between observations at different distances apart. The autocorrelation function can be used for two purpuses:
1- Detecting non-randomness in data.
2- Identifying the appropriate time series model if the data is not random.By using the Autocorrelation (ACF) and Partial Autocorrelation (PACF) functions.
The plot summarizes the correlation of an observation with lag value.
The plot summarizes the correlation of an observation that is not accounted for by prior lagged observation.
If ACF tails off and PACF cuts off at lag p, this should be a strong indictaor of possible AR(p) model.
AR <- arima.sim(model = list(ar = 0.9), n = 200)
acf2(AR)
If ACF cuts off at laq q and PACF tails off, this should be a strong indictaor of possible MA(q) model.
MA <- arima.sim(model = list(ma = -0.5), n = 200)
acf2(MA)
If both ACF and PACF are tailing off, this should be a strong indicator of ARMA(p,q) model.
ARMA <- arima.sim(model = list(ar = 0.65, ma = -0.4), n = 200)
acf2(ARMA)