Time series analysis is a statistical technique used to analyze data points collected or recorded at successive points in time. It helps identify patterns, trends, and seasonal variations to make predictions or better understand the underlying dynamics of the data.
-
Time Series Data:
A sequence of observations recorded over time (e.g., daily stock prices, monthly sales, annual rainfall). -
Components of a Time Series:
- Trend: The long-term movement in the data (e.g., increasing sales over years).
- Seasonality: Regular patterns or cycles in the data within a fixed period (e.g., holiday sales spikes).
- Cyclic Patterns: Fluctuations with no fixed period, often driven by economic or business cycles.
- Noise: Random variations or residuals that cannot be explained by the above components.
-
Stationarity:
A time series is stationary if its statistical properties (mean, variance, autocorrelation) do not change over time.
-
Exploratory Analysis:
Identifies trends, seasonality, and outliers using descriptive statistics and visualizations. -
Forecasting:
Predicts future values based on historical data. -
Modeling Relationships:
Analyzes how external variables affect the time series (e.g., sales influenced by advertising).
Separates a time series into its components: trend, seasonality, and residuals.
Example: Understanding the seasonal pattern of monthly sales data.
Smooths time series data by calculating the average of subsets over time, reducing noise.
Example: Identifying trends in stock prices by using a 7-day moving average.
A powerful method for modeling and forecasting time series.
- AR (Autoregressive): Uses past values to predict future values.
- I (Integrated): Differencing the data to make it stationary.
- MA (Moving Average): Models the relationship between an observation and a residual error.
Example: Forecasting electricity demand.
Separates a time series into seasonal, trend, and residual components, especially useful for data with strong seasonality.
Assigns exponentially decreasing weights to older observations.
- Simple Exponential Smoothing: For data with no trend or seasonality.
- Holt’s Method: Adds a trend component.
- Holt-Winters Method: Adds both trend and seasonality components.
Example: Forecasting monthly airline passengers.
Combines time series data with external variables to model and predict outcomes.
Example: Predicting sales based on advertising spend and seasonal factors.
Monthly sales data for 2 years:
Month | Sales |
---|---|
Jan 2021 | 200 |
Feb 2021 | 220 |
... | ... |
Dec 2022 | 300 |
Forecast sales for Jan 2023.
-
Decompose the Time Series:
Identify trend and seasonality. -
Fit an ARIMA Model:
- Use
$p = 1$ ,$d = 1$ ,$q = 1$ based on autocorrelation (ACF) and partial autocorrelation (PACF) plots.
- Use
-
Generate Forecast:
Predict sales for Jan 2023.
-
Mean Absolute Error (MAE):
$$MAE = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|$$ -
Mean Squared Error (MSE):
$$MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2$$ -
Root Mean Squared Error (RMSE):
$$RMSE = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2}$$ -
Mean Absolute Percentage Error (MAPE):
$$MAPE = \frac{1}{n} \sum_{i=1}^{n} \left|\frac{y_i - \hat{y}_i}{y_i}\right| \times 100$$
-
Business:
- Forecasting sales, revenue, and inventory needs.
-
Finance:
- Predicting stock prices and economic indicators.
-
Healthcare:
- Analyzing patient admissions and disease spread trends.
-
Weather:
- Predicting temperatures and precipitation patterns.
-
Python Libraries:
- Pandas: Data manipulation.
- Statsmodels: Statistical models (e.g., ARIMA).
- Prophet: Easy forecasting for business applications.
-
R: Popular for time series analysis and visualization.
-
Excel: Useful for basic analysis and visualizations.
Time series analysis is a critical tool for understanding temporal data and making informed predictions. By mastering its techniques, you can uncover trends, identify patterns, and anticipate future changes effectively.
Next Steps: Bayesian Statistics