Time series
A time series is a list of measurements recorded in time order, such as daily temperatures, monthly sales, or a country's yearly economic output. Time series analysis is the part of statistics that describes such data, works out how each value depends on earlier values, and uses that to forecast what comes next.
Order is what sets time series apart from other data. In most statistics the observations are treated as unrelated, but in a time series today's value usually depends on yesterday's. Most of the methods below exist to measure and model that dependence.
What a time series is
A time series is an ordered sequence of values of a variable, usually taken at equally spaced times.[1] Typical spacings are seconds, days, months, quarters, or years. Common examples are gross domestic product (GDP), prices, interest rates, and stock prices.[2]
In the theory, each value is treated as a random variable. A time series is then a collection of random variables indexed by the order in which they are observed, also called a stochastic process.[3] The data you actually record are one realization of that process.[3]
Why it matters
Time series models have two broad uses.[1]
- Understanding: explain the forces and structure that produced the data.
- Prediction and control: fit a model, then use it for forecasting, monitoring, or feedback control of a process.
Applications include economic and sales forecasting, budget analysis, stock market analysis, process and quality control, inventory studies, and census analysis.[1]
Even and uneven spacing
Most classical methods assume equal spacing. Much of the basic theory was built when limited computing power favored equally spaced data.[4] Many real records are irregular, such as earthquake dates, astronomical observations limited by weather, or patient check-ups in clinical studies.[4]
These are called unevenly spaced time series. A common workaround is to interpolate them onto a regular grid, but this can bias estimates of autocorrelation and volatility.[4]
Patterns in a series
The first step in any analysis is to plot the data against time.[3] Analysts then look for a few standard patterns.[5]
| Pattern | What it is | Example |
|---|---|---|
| Trend | A long-term increase or decrease, not necessarily a straight line | Steady growth in drug sales |
| Seasonal | A repeating pattern tied to the calendar, with a fixed and known period | Higher retail sales every December |
| Cycle | Rises and falls that do not have a fixed period, often lasting at least 2 years | The business cycle |
Seasons and cycles are easy to confuse. If the period is fixed and set by the calendar, the pattern is seasonal; if it is not fixed, it is cyclic.[5] Cycles are usually longer and vary more in size than seasonal patterns.[5]
Decomposition
Decomposition splits a series into parts. In an additive decomposition,[6]
where is the data at time , is the seasonal component, is the trend-cycle component (trend and cycle together), and is the remainder.
A multiplicative decomposition, , fits better when the seasonal swings grow in proportion to the level of the series.[6] This is common in economic data. Taking logarithms turns a multiplicative decomposition into an additive one.[6]
Removing the seasonal part gives seasonally adjusted data: for additive and for multiplicative decompositions.[6]
Autocorrelation
Autocorrelation measures how strongly a series is linearly related to its own past.[7] The gap between the two values being compared is called the lag. For example, the lag-1 autocorrelation compares with , and compares with .[7]
The sample autocorrelation at lag is[7]
where is the length of the series and is its mean. The values together form the autocorrelation function (ACF), and a bar plot of them is a correlogram.[7]
Reading an ACF plot
The shape of the ACF reveals the patterns described above.[7]
- Trend: autocorrelations at small lags are large and positive, and they fall off slowly as the lag grows.
- Seasonality: autocorrelations are larger at multiples of the seasonal period, such as lags 4 and 8 for quarterly data.
White noise
A series with no autocorrelation is called white noise.[9] Its sample autocorrelations are not exactly zero, because of random variation. For white noise, about 95% of the ACF spikes should lie within .[9]
White noise is the building block of most models. It stands for the part of each new value that could not have been predicted.
Stationarity
A stationary time series is one whose statistical properties do not depend on when you look at it.[10] A series with a trend or seasonality is not stationary, while white noise is.[10] Many methods assume stationarity, because a model fitted to one stretch of data should then hold for the rest.[11]
Formal definition
A series is weakly stationary if three things hold for every time :[8]
- The mean is the same.
- The variance of is the same.
- The covariance between and is the same at each lag .
The third condition means the autocorrelation at a given lag is the same throughout the series.[8] That is why the ACF is only meaningful for a stationary series.
Random walks
The random walk is the standard example of a non-stationary series:[10]
where is white noise. Random walks show long stretches that look like trends and sudden, unpredictable changes of direction.[10] Adding a constant gives a random walk with drift, , which tends to drift up if is positive and down if is negative.[10]
Making a series stationary
Differencing replaces each value with its change from the previous one:[10]
Differencing steadies the mean and can remove or reduce trend and seasonality.[10] A random walk becomes white noise after one difference. One difference is usually enough, and each difference shortens the series by one point.[11]
Other fixes target other problems.[11]
- A trend can be removed by fitting a simple curve, such as a straight line, and modeling the leftover residuals.
- A variance that grows over time can often be steadied with a logarithm or square root.
Unit root tests
Unit root tests are hypothesis tests that help decide whether a series needs differencing.[10] They rest on different assumptions and can disagree.[10] The augmented Dickey-Fuller test takes "the series has a unit root" as its null hypothesis, while the KPSS test takes the opposite, that the series is stationary.[12]
The number of differences needed to make a series stationary is its order of integration. A series that becomes approximately stationary after differences is written , so a stationary series is .[13]
Linear models for one series
The classic models describe a stationary series as a weighted sum of its past values and past random shocks. The shorthand , called the backshift or lag operator, shifts a series back one step, so .[14]
Autoregressive models
An autoregressive model of order , written AR(), predicts the current value from the last values:[15]
Here is a constant, are coefficients, and is white noise. It is like a regression with the series' own past values as predictors.[15]
The AR(1) model shows how the coefficient shapes behavior.[15]
- and : white noise.
- and : a random walk.
- : the series tends to swing back and forth around its mean.
- : the condition for the AR(1) model to be stationary.
For a stationary AR(1), the autocorrelation at lag is , so it shrinks by the same factor at every lag.[8]
Moving-average models
A moving-average model of order , written MA(), uses past random shocks instead of past values:[16]
The shocks are never observed directly, so this is not an ordinary regression.[16] The ACF of an MA() process is zero from lag onward.[17]
ARMA and ARIMA
Combining both parts gives an autoregressive moving-average (ARMA) model. Applying it to a differenced series gives an autoregressive integrated moving average (ARIMA) model, where "integrated" means the reverse of differencing.[14] In backshift notation, an ARIMA(, , ) model is[14]
where is the order of the autoregressive part, is the number of differences, and is the order of the moving-average part.[14] Some texts write the moving-average terms with minus signs instead.[18]
ARMA models are very flexible. By Wold's theorem, a stationary process can be approximated by an ARMA model, though finding that approximation in practice may not be easy.[18]
The Box-Jenkins method
The Box-Jenkins method is a step-by-step way to build an ARIMA model, named for George Box and Gwilym Jenkins. It has three main stages: identification, estimation, and validation.[18]
- Check whether the series is stationary and seasonal, and difference it if needed.[17]
- Identify and from the sample ACF and the partial autocorrelation function (PACF).[17]
- Estimate the coefficients.[18]
- Check that the residuals look like white noise; if not, return to step 2.[19]
Effective fitting needs at least a moderately long series, with recommendations ranging from at least 50 to at least 100 observations.[18]
The ACF shape points to a model type.[17]
| ACF shape | Suggested model |
|---|---|
| Decays exponentially to zero | Autoregressive; use the PACF to find the order |
| Alternates in sign while decaying to zero | Autoregressive |
| One or more spikes, then about zero | Moving average; order is where the ACF reaches zero |
| Decay that starts after a few lags | Mixed ARMA |
| All near zero | Essentially random |
| High values at fixed intervals | Add a seasonal autoregressive term |
| No decay to zero | Not stationary |
The PACF of an AR() process is zero from lag onward.[17] Because sample plots are noisy, mixed models are hard to identify by eye, and information criteria such as the Akaike information criterion (AIC) are now often used to automate the choice.[17]
Checking residuals
A good model leaves residuals that are uncorrelated and have zero mean.[19] Correlated residuals mean there is information left that the forecasts should use, and a non-zero mean means the forecasts are biased.[19]
A portmanteau test checks many autocorrelations at once. The Ljung-Box test uses[19]
where is the largest lag checked and is the number of observations. Large values of suggest the residuals are not white noise.[19]
Exponential smoothing
Exponential smoothing forecasts with a weighted average of past values, where the weights shrink exponentially with age.[20] The simplest form is[20]
where is the forecast for time made at time , and is the smoothing parameter. Expanding it shows the weights directly: , , , and so on.[20]
A large puts more weight on recent values, and a small spreads weight further into the past.[20] With the forecast is simply the last observation.[20] Holt's linear method adds a trend term, and the Holt-Winters method adds a seasonal term as well.[21][22]
Forecasting and accuracy
Time series forecasting predicts future values from past ones. To judge a method fairly, the data are split by time into a training set, used to fit the model, and a test set, used only to measure accuracy.[23] The test set is typically about 20% of the sample and should ideally be at least as long as the longest forecast horizon needed.[23]
A forecast error is the gap between an observed value and its forecast:[23]
where is the last training point and is the number of steps ahead. Two common summaries are the mean absolute error, , and the root mean squared error, .[23] Minimizing MAE leads to forecasts of the median, while minimizing RMSE leads to forecasts of the mean.[23]
Time domain and frequency domain
There are two broad, overlapping approaches to time series analysis.[3]
| Approach | Main idea | Typical tools |
|---|---|---|
| Time domain | Each value depends on past values | Autocorrelation, ARIMA models, regression on lagged values |
| Frequency domain | The data are made of periodic, wave-like variations | Spectral density, Periodogram |
The two often give similar answers for long series, but the time domain tends to do better on short samples.[3] Many analysts use both together.[3]
Spectral analysis
Any time series can be written as a sum of sine and cosine waves of different frequencies, its Fourier representation.[24] Spectral analysis measures how much of the variance belongs to each frequency, and this variance profile is called the power spectrum.[3] For a stationary series, the power spectrum is given by the spectral density, which is the Fourier transform of the autocovariance function and gives the expected power at each frequency.[24]
The periodogram estimates the spectral density from data. On its own it is an inconsistent estimator, meaning its error does not shrink as the series gets longer, so it is usually smoothed across nearby frequencies.[24] See spectral density estimation.
The sampling rate matters. Sampling too slowly can make a fast cycle look like a slow one, a distortion called aliasing, as when wagon wheels in films seem to turn backwards.[3]
Several series together
Many questions involve two or more series that affect each other, such as income and spending.
Vector autoregression
A vector autoregression (VAR) extends the AR model to several series, with one equation per variable.[25] Each equation includes a constant and lags of every variable in the system. A two-variable VAR with one lag is[25]
where measures the effect of the previous value of series on series , and the white noise terms may be correlated with each other.[25] Christopher Sims, who shared the 2011 economics Nobel Prize, used VAR models to identify economic shocks and trace their effects over time with impulse responses.[26]
Granger causality
Granger causality defines causation in terms of prediction. Clive Granger's general 1969 definition compares predictions made with all available information to predictions made with everything except one series.[27] In its two-series form, where only and matter, causes if past values of reduce the error of predicting beyond what past values of alone achieve:[27]
Here is the variance of the best prediction error given the listed past values. Granger noted that leaving out a relevant third series can produce spurious causality.[27]
Spurious regression and cointegration
Regressing one non-stationary series on another can show a strong link where none exists. In 1974, Granger and Paul Newbold regressed independent random walks on each other and found "significant" relationships far more often than standard theory predicts.[13] This is a time series form of a spurious relationship.
Cointegration is the exception. Two series and are cointegrated if some combination is stationary, so the two series wander but stay tied together.[13] Granger introduced the idea in 1981, and Engle and Granger (1987) developed tests and estimation methods for it.[13]
Changing volatility
Financial series often swing between turbulent periods with large changes and calm periods with small ones.[2] Models that assume a constant variance miss this.
Robert Engle's autoregressive conditional heteroskedasticity (ARCH) model, introduced in 1982, lets the variance depend on recent shocks.[13] The error is written , where are independent with mean zero and variance one, and[13]
where is the conditional variance, meaning the variance of the shock at time given the shocks before it.[13] A large shock of either sign raises the variance for the next periods.[13] Related approaches include stochastic volatility models.
History
In 1927, two separate papers opened the way to using probability models for economic time series.[28]
- Udny Yule built and estimated a second-order autoregressive model of sunspot numbers.[28] The historian of statistics Stephen Stigler said Yule "managed effectively to invent modern time series analysis."[28]
- Eugen Slutsky, studying business cycles in Russia, showed that sums of random shocks can produce cycle-like patterns. His paper first appeared in Russian and was published in English in Econometrica in 1937.[28][29]
| Year | Work |
|---|---|
| 1938 | Herman Wold, A Study in the Analysis of Stationary Time Series[29] |
| 1969 | Granger's prediction-based definition of causality[27] |
| 1970 | Box and Jenkins, Time Series Analysis: Forecasting and Control[30] |
| 1974 | Granger and Newbold on spurious regression[13] |
| 1981 | Granger introduces cointegration[13] |
| 1982 | Engle introduces ARCH[13] |
| 1987 | Engle and Granger on testing and estimating cointegration[13] |
| 2003 | Engle and Granger share the economics Nobel Prize for ARCH and cointegration[2] |
Software
- Prophet fits an additive model with non-linear trends, yearly, weekly, and daily seasonality, and holiday effects, in R and Python.[31]
- Darts is a Python library for forecasting and anomaly detection, with models from ARIMA to deep neural networks.[32]
References
- Definitions, Applications and Techniques, NIST/SEMATECH e-Handbook of Statistical Methods, 2012.
- The Prize in Economic Sciences 2003, press release, NobelPrize.org, 2003.
- Time Series Analysis and Its Applications, 3rd ed., R. H. Shumway and D. S. Stoffer, Springer, 2011.
- A Framework for the Analysis of Unevenly Spaced Time Series Data, Andreas Eckner, 2014.
- Time series patterns, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Time series components, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Autocorrelation, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Sample ACF and Properties of AR(1) Model, STAT 510 Applied Time Series Analysis, Penn State University.
- White noise, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Stationarity and differencing, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Stationarity, NIST/SEMATECH e-Handbook of Statistical Methods, 2012.
- Stationarity and detrending (ADF/KPSS), statsmodels documentation.
- Time-series Econometrics: Cointegration and Autoregressive Conditional Heteroskedasticity, Royal Swedish Academy of Sciences, 2003.
- Non-seasonal ARIMA models, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Autoregressive models, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Moving average models, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Box-Jenkins Model Identification, NIST/SEMATECH e-Handbook of Statistical Methods, 2012.
- Box-Jenkins Models, NIST/SEMATECH e-Handbook of Statistical Methods, 2012.
- Residual diagnostics, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Simple exponential smoothing, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Methods with trend, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Methods with seasonality, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Evaluating point forecast accuracy, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- Introduction to time series analysis in the frequency domain, E. Ionides, STATS 531 course notes, University of Michigan, 2021.
- Vector autoregressions, R. J. Hyndman and G. Athanasopoulos, Forecasting: Principles and Practice (3rd ed.), OTexts, 2021.
- The Prize in Economic Sciences 2011, popular information, NobelPrize.org, 2011.
- Investigating Causal Relations by Econometric Models and Cross-spectral Methods, C. W. J. Granger, Econometrica, 1969.
- Time Series Econometrics in Macroeconomics and Finance, Lars Peter Hansen, 2017.
- Time Series, International Encyclopedia of the Social Sciences, Encyclopedia.com.
- Time series analysis; forecasting and control, G. E. P. Box and G. M. Jenkins, Holden-Day, 1970.
- Prophet: Forecasting at scale, Meta, Prophet documentation.
- Time Series Made Easy in Python, Unit8, Darts documentation.
