2025-03-16

Introduction to Time Series Analysis

  • A specialized statistical technique for analyzing time-ordered data
  • Used to understand patterns, trends, and make forecasts
  • Applications in economics, finance, meteorology, and many other fields
  • Focus on temporal dependencies that regular statistical methods ignore

Components of Time Series

Time series data can be decomposed into four primary components:

  • Trend: Long-term progression of the series
  • Seasonality: Repeating patterns at fixed intervals
  • Cyclical: Fluctuations without fixed periods
  • Irregular: Random, unpredictable variations

\[ Y_t = T_t + S_t + C_t + I_t \]

Where \(Y_t\) is the time series value at time \(t\).

Stationarity

  • A fundamental concept in time series analysis
  • A stationary time series has constant:
    • Mean
    • Variance
    • Autocorrelation structure

Autocorrelation

  • Measures the correlation between a time series and its lagged values
  • Autocorrelation Function (ACF): Correlation with direct previous values
  • Partial Autocorrelation Function (PACF): Correlation after removing effects of intermediate lags

\[ \rho_k = \frac{\sum_{t=k+1}^{T} (y_t - \bar{y})(y_{t-k} - \bar{y})}{\sum_{t=1}^{T} (y_t - \bar{y})^2} \]

Where \(\rho_k\) is the autocorrelation at lag \(k\).

Example Dataset: Air Passengers

##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   104.0   180.0   265.5   280.3   360.5   622.0
##         Date Passengers
## 1 1949-01-01        112
## 2 1949-02-01        118
## 3 1949-03-01        132
## 4 1949-04-01        129
## 5 1949-05-01        121
## 6 1949-06-01        135
  • Monthly totals of international airline passengers, 1949-1960
  • Shows clear trend and seasonality
  • Classic example for time series analysis

Time Series Visualization

Time Series Decomposition

3D Time Series Visualization

years <- 1949:1960
months <- 1:12
month_names <- month.abb

grid <- expand.grid(Year = years, Month = 1:12)
grid$Passengers <- as.numeric(AirPassengers)

plot_ly(x = ~months, y = ~years, z = ~matrix(grid$Passengers, ncol = 12, byrow = TRUE),
        type = "surface") %>%
  layout(
    title = "3D Visualization of Airline Passengers (1949-1960)",
    scene = list(
      xaxis = list(title = "Month", tickvals = 1:12, ticktext = month_names),
      yaxis = list(title = "Year"),
      zaxis = list(title = "Passengers (thousands)")
    )
  )

R Code for Time Series Analysis

ap_ts <- ts(AirPassengers, frequency = 12, start = c(1949, 1))

ap_decomp <- decompose(ap_ts, "multiplicative")

adf_test <- adf.test(ap_ts)
print(adf_test)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  ap_ts
## Dickey-Fuller = -7.3186, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary
ap_arima <- auto.arima(ap_ts)
summary(ap_arima)
## Series: ap_ts 
## ARIMA(2,1,1)(0,1,0)[12] 
## 
## Coefficients:
##          ar1     ar2      ma1
##       0.5960  0.2143  -0.9819
## s.e.  0.0888  0.0880   0.0292
## 
## sigma^2 = 132.3:  log likelihood = -504.92
## AIC=1017.85   AICc=1018.17   BIC=1029.35
## 
## Training set error measures:
##                    ME     RMSE      MAE       MPE     MAPE     MASE
## Training set 1.342306 10.84619 7.867539 0.4206996 2.800458 0.245628
##                      ACF1
## Training set -0.001248451
ap_forecast <- forecast(ap_arima, h = 12)

plot(ap_forecast, main = "Forecast of Airline Passengers")

Forecasting Results

ARIMA Models

  • ARIMA: AutoRegressive Integrated Moving Average
  • Key parameters:
    • p: Order of the autoregressive part
    • d: Degree of differencing
    • q: Order of the moving average part

\[ \begin{align} \text{AR(p):} \quad y_t &= c + \phi_1 y_{t-1} + \phi_2 y_{t-2} + \ldots + \phi_p y_{t-p} + \varepsilon_t \\ \text{MA(q):} \quad y_t &= c + \varepsilon_t + \theta_1 \varepsilon_{t-1} + \theta_2 \varepsilon_{t-2} + \ldots + \theta_q \varepsilon_{t-q} \end{align} \]

Applications and Conclusion

  • Time series analysis is crucial in many areas:
    • Finance: Stock price prediction, risk management
    • Economics: GDP forecasting, unemployment rates
    • Weather: Temperature and precipitation forecasting
    • Retail: Sales forecasting and inventory planning
    • Healthcare: Disease surveillance, patient monitoring
  • Key challenges:
    • Handling non-stationarity
    • Dealing with missing data
    • Choosing appropriate models
    • Balancing complexity and interpretability