Time Series analysis tsa
statsmodels.tsa contains model classes and functions that are useful
for time series analysis. This currently includes univariate autoregressive models (AR),
vector autoregressive models (VAR) and univariate autoregressive moving average models
(ARMA). It also includes descriptive statistics for time series, for example autocorrelation, partial
autocorrelation function and periodogram, as well as the corresponding theoretical properties
of ARMA or related processes. It also includes methods to work with autoregressive and
moving average lag-polynomials.
Additionally, related statistical tests and some useful helper functions are available.
Estimation is either done by exact or conditional Maximum Likelihood or conditional
least-squares, either using Kalman Filter or direct filters.
Currently, functions and classes have to be imported from the corresponding module, but
the main classes will be made available in the statsmodels.tsa namespace. The module
structure is within statsmodels.tsa is
- stattools : empirical properties and tests, acf, pacf, granger-causality,
adf unit root test, ljung-box test and others.
- ar_model : univariate autoregressive process, estimation with conditional
and exact maximum likelihood and conditional least-squares
- arima_model : univariate ARMA process, estimation with conditional
and exact maximum likelihood and conditional least-squares
- vector_ar, var : vector autoregressive process (VAR) estimation models,
impulse response analysis, forecast error variance decompositions, and data
visualization tools
- kalmanf : estimation classes for ARMA and other models with exact MLE using
Kalman Filter
- arma_process : properties of arma processes with given parameters, this
includes tools to convert between ARMA, MA and AR representation as well as
acf, pacf, spectral density, impulse response function and similar
- sandbox.tsa.fftarma : similar to arma_process but working in frequency domain
- tsatools : additional helper functions, to create arrays of lagged variables,
construct regressors for trend, detrend and similar.
- filters : helper function for filtering time series
Some additional functions that are also useful for time series analysis are in
other parts of statsmodels, for example additional statistical tests.
Some related functions are also available in matplotlib, nitime, and
scikits.talkbox. Those functions are designed more for the use in signal
processing where longer time series are available and work more often in the
frequency domain.
Descriptive Statistics and Tests
stattools.acovf(x[, unbiased, demean, fft]) |
Autocovariance for 1D |
stattools.acf(x[, unbiased, nlags, confint, ...]) |
Autocorrelation function for 1d arrays. |
stattools.pacf(x[, nlags, method, alpha]) |
Partial autocorrelation estimated |
stattools.pacf_yw(x[, nlags, method]) |
Partial autocorrelation estimated with non-recursive yule_walker |
stattools.pacf_ols(x[, nlags]) |
Calculate partial autocorrelations |
stattools.ccovf(x, y[, unbiased, demean]) |
crosscovariance for 1D |
stattools.ccf(x, y[, unbiased]) |
cross-correlation function for 1d |
stattools.periodogram(X) |
Returns the periodogram for the natural frequency of X |
stattools.adfuller(x[, maxlag, regression, ...]) |
Augmented Dickey-Fuller unit root test |
stattools.q_stat(x, nobs[, type]) |
Return’s Ljung-Box Q Statistic |
stattools.grangercausalitytests(x, maxlag[, ...]) |
four tests for granger non causality of 2 timeseries |
stattools.levinson_durbin(s[, nlags, isacov]) |
Levinson-Durbin recursion for autoregressive processes |
Estimation
The following are the main estimation classes, which can be accessed through
statsmodels.tsa.api and their result classes
Univariate Autogressive Processes (AR)
ar_model.AR |
|
ar_model.ARResults |
|
Autogressive Moving-Average Processes (ARMA) and Kalman Filter
arima_model.ARMA |
|
arima_model.ARMAResults |
|
arima_model.ARIMA |
|
arima_model.ARIMAResults |
|
kalmanf.kalmanfilter.KalmanFilter |
|
Vector Autogressive Processes (VAR)
Vector Autogressive Processes (VAR)
Besides estimation, several process properties and additional results after
estimation are available for vector autoregressive processes.
vector_ar.var_model.VAR(endog[, dates, ...]) |
Fit VAR(p) process and do lag order selection |
vector_ar.var_model.VARProcess(coefs, ...[, ...]) |
Class represents a known VAR(p) process |
vector_ar.var_model.VARResults(endog, ...[, ...]) |
Estimate VAR(p) process with fixed number of lags |
vector_ar.irf.IRAnalysis(model[, P, ...]) |
Impulse response analysis class. |
vector_ar.var_model.FEVD(model[, P, periods]) |
Compute and plot Forecast error variance decomposition and asymptotic |
vector_ar.dynamic.DynamicVAR(data[, ...]) |
Estimates time-varying vector autoregression (VAR(p)) using |
ARMA Process
The following are tools to work with the theoretical properties of an ARMA
process for given lag-polynomials.
arima_process.ArmaProcess(ar, ma[, nobs]) |
represents an ARMA process for given lag-polynomials |
arima_process.ar2arma(ar_des, p, q[, n, ...]) |
find arma approximation to ar process |
arima_process.arma2ar(ar, ma[, nobs]) |
get the AR representation of an ARMA process |
arima_process.arma2ma(ar, ma[, nobs]) |
get the impulse response function (MA representation) for ARMA process |
arima_process.arma_acf(ar, ma[, nobs]) |
theoretical autocorrelation function of ARMA process |
arima_process.arma_acovf(ar, ma[, nobs]) |
theoretical autocovariance function of ARMA process |
arima_process.arma_generate_sample(ar, ma, ...) |
generate an random sample of an ARMA process |
arima_process.arma_impulse_response(ar, ma) |
get the impulse response function (MA representation) for ARMA process |
arima_process.arma_pacf(ar, ma[, nobs]) |
partial autocorrelation function of an ARMA process |
arima_process.arma_periodogram(ar, ma[, ...]) |
periodogram for ARMA process given by lag-polynomials ar and ma |
arima_process.deconvolve(num, den[, n]) |
Deconvolves divisor out of signal, division of polynomials for n terms |
arima_process.index2lpol(coeffs, index) |
expand coefficients to lag poly |
arima_process.lpol2index(ar) |
remove zeros from lagpolynomial, squeezed representation with index |
arima_process.lpol_fiar(d[, n]) |
AR representation of fractional integration |
arima_process.lpol_fima(d[, n]) |
MA representation of fractional integration |
arima_process.lpol_sdiff(s) |
return coefficients for seasonal difference (1-L^s) |
sandbox.tsa.fftarma.ArmaFft |
|
Other Time Series Filters
filters.bkfilter(X[, low, high, K]) |
Baxter-King bandpass filter |
filters.hpfilter(X[, lamb]) |
Hodrick-Prescott filter |
filters.arfilter(x, a) |
apply an autoregressive filter to a series x |
filters.cffilter(X[, low, high, drift]) |
Christiano Fitzgerald asymmetric, random walk filter |
filters.miso_lfilter(ar, ma, x[, useic]) |
use nd convolution to merge inputs, |
filters.filtertools.fftconvolve3(in1[, in2, ...]) |
Convolve two N-dimensional arrays using FFT. |
filters.filtertools.fftconvolveinv(in1, in2) |
Convolve two N-dimensional arrays using FFT. |
Interpolation
interp.denton.dentonm(indicator, benchmark) |
Modified Denton’s method to convert low-frequency to high-frequency data. |