TimeSeries

Time Series Analysis

Base R ships with a lot of functionality useful for time series, in particular in the stats package. This is complemented by many packages on CRAN, which are briefly summarized below. There is also a considerable overlap between the tools for time series and those in the Econometrics and Finance task views. The packages in this view can be roughly structured into the following topics. If you think that some package is missing from the list, please let us know.

Basics

  • Infrastructure: Base R contains substantial infrastructure for representing and analyzing time series data. The fundamental class is "ts" that can represent regularly spaced time series (using numeric time stamps). Hence, it is particularly well-suited for annual, monthly, quarterly data, etc.
  • Rolling statistics: Moving averages are computed by ma from forecast, and rollmean from zoo. The latter also provides a general function rollapply, along with other specific rolling statistics functions. roll provides parallel functions for computing rolling statistics.
  • Graphics: Time series plots are obtained with plot() applied to ts objects. (Partial) autocorrelation functions plots are implemented in acf() and pacf(). Alternative versions are provided by Acf() and Pacf() in forecast, along with a combination display using tsdisplay(). SDD provides more general serial dependence diagrams, while dCovTS computes and plots the distance covariance and correlation functions of time series. Seasonal displays are obtained using monthplot() in stats and seasonplot in forecast. Wats implements wrap-around time series graphics. ggseas provides ggplot2 graphics for seasonally adjusted series and rolling statistics. dygraphs provides an interface to the Dygraphs interactive time series charting library. TSstudio provides some interactive visualization tools for time series. ZRA plots forecast objects from the forecast package using dygraphs. Basic fan plots of forecast distributions are provided by forecast and vars. More flexible fan plots of any sequential distributions are implemented in fanplot.

Times and Dates

  • Class "ts" can only deal with numeric time stamps, but many more classes are available for storing time/date information and computing with it. For an overview see R Help Desk: Date and Time Classes in R by Gabor Grothendieck and Thomas Petzoldt in R News 4(1), 29-32.
  • Classes "yearmon" and "yearqtr" from zoo allow for more convenient computation with monthly and quarterly observations, respectively.
  • Class "Date" from the base package is the basic class for dealing with dates in daily data. The dates are internally stored as the number of days since 1970-01-01.
  • The chron package provides classes for dates(), hours() and date/time (intra-day) in chron(). There is no support for time zones and daylight savings time. Internally, "chron" objects are (fractional) days since 1970-01-01.
  • Classes "POSIXct" and "POSIXlt" implement the POSIX standard for date/time (intra-day) information and also support time zones and daylight savings time. However, the time zone computations require some care and might be system-dependent. Internally, "POSIXct" objects are the number of seconds since 1970-01-01 00:00:00 GMT. Package lubridate provides functions that facilitate certain POSIX-based computations. timechange allows for efficient manipulation of date-times accounting for time zones and daylight saving times. wktmo converts weekly data to monthly data in several different ways.
  • Several packages aim to handle time-based tibbles: tsibble provides tidy temporal data frames and associated tools; tibbletime handles time aware tibbles; timetk contains tools for working with and coercing between time-based tibbles, xts, zoo and ts objects. tsbox is another toolkit for converting between various time series data classes.
  • Class "timeDate" is provided in the timeDate package (previously: fCalendar). It is aimed at financial time/date information and deals with time zones and daylight savings times via a new concept of "financial centers". Internally, it stores all information in "POSIXct" and does all computations in GMT only. Calendar functionality, e.g., including information about weekends and holidays for various stock exchanges, is also included.
  • The tis package provides the "ti" class for time/date information.
  • The "mondate" class from the mondate package facilitates computing with dates in terms of months.
  • The tempdisagg package includes methods for temporal disaggregation and interpolation of a low frequency time series to a higher frequency series.
  • Time series disaggregation is also provided by tsdisagg2.
  • TimeProjection extracts useful time components of a date object, such as day of week, weekend, holiday, day of month, etc, and put it in a data frame.

Time Series Classes

  • As mentioned above, "ts" is the basic class for regularly spaced time series using numeric time stamps.
  • The zoo package provides infrastructure for regularly and irregularly spaced time series using arbitrary classes for the time stamps (i.e., allowing all classes from the previous section). It is designed to be as consistent as possible with "ts". Coercion from and to "zoo" is available for all other classes mentioned in this section.
  • The package xts is based on zoo and provides uniform handling of R's different time-based data classes.
  • Various packages implement irregular time series based on "POSIXct" time stamps, intended especially for financial applications. These include "irts" from tseries, and "fts" from fts.
  • The class "timeSeries" in timeSeries (previously: fSeries) implements time series with "timeDate" time stamps.
  • The class "tis" in tis implements time series with "ti" time stamps.
  • The package tframe contains infrastructure for setting time frames in different formats.

Forecasting and Univariate Modeling

  • The forecast package provides a class and methods for univariate time series forecasts, and provides many functions implementing different forecasting models including all those in the stats package.
  • Exponential smoothing: HoltWinters() in stats provides some basic models with partial optimization, ets() from the forecast package provides a larger set of models and facilities with full optimization. robets provides a robust alternative to the ets() function. smooth implements some generalizations of exponential smoothing. The MAPA package combines exponential smoothing models at different levels of temporal aggregation to improve forecast accuracy.
  • prophet forecasts time series based on an additive model where nonlinear trends are fit with yearly and weekly seasonality, plus holidays. It works best with daily data.
  • The theta method is implemented in the thetaf function from the forecast package. An alternative and extended implementation is provided in forecTheta.
  • Autoregressive models: ar() in stats (with model selection) and FitAR for subset AR models.
  • ARIMA models: arima() in stats is the basic function for ARIMA, SARIMA, ARIMAX, and subset ARIMA models. It is enhanced in the forecast package via the function Arima() along with auto.arima() for automatic order selection. arma() in the tseries package provides different algorithms for ARMA and subset ARMA models. Other estimation methods including the innovations algorithm are provided by itsmr. FitARMA implements a fast MLE algorithm for ARMA models. Package gsarima contains functionality for Generalized SARIMA time series simulation. Robust ARIMA modeling is provided in the robustarima package. The mar1s package handles multiplicative AR(1) with seasonal processes. TSTutorial provides an interactive tutorial for Box-Jenkins modelling. Improved prediction intervals for ARIMA and structural time series models are provided by tsPI.
  • Periodic ARMA models: pear and partsm for periodic autoregressive time series models, and perARMA for periodic ARMA modelling and other procedures for periodic time series analysis.
  • ARFIMA models: Some facilities for fractional differenced ARFIMA models are provided in the fracdiff package. The arfima package has more advanced and general facilities for ARFIMA and ARIMA models, including dynamic regression (transfer function) models.
  • Transfer function models are provided by the arimax function in the TSA package, and the arfima function in the arfima package.
  • Outlier detection following the Chen-Liu approach is provided by tsoutliers. The tsoutliers and tsclean functions in the forecast package provide some simple heuristic methods for identifying and correcting outliers. anomalize provides some additional outlier detection methods in a tidy data framework.
  • Structural models are implemented in StructTS() in stats, and in stsm and stsm.class. KFKSDS provides a naive implementation of the Kalman filter and smoothers for univariate state space models. Bayesian structural time series models are implemented in bsts
  • Non-Gaussian time series can be handled with GLARMA state space models via glarma, and using Generalized Autoregressive Score models in the GAS package. Conditional Auto-Regression models using Monte Carlo Likelihood methods are implemented in mclcar. Efficient Bayesian inference for nonlinear and non-Gaussian state space models is provided in bssm.
  • GARCH models: garch() from tseries fits basic GARCH models. Many variations on GARCH models are provided by rugarch. Other univariate GARCH packages include fGarch which implements ARIMA models with a wide class of GARCH innovations. There are many more GARCH packages described in the Finance task view.
  • Stochastic volatility models are handled by stochvol in a Bayesian framework.
  • Count time series models are handled in the tscount and acp packages. ZIM provides for Zero-Inflated Models for count time series. tsintermittent implements various models for analysing and forecasting intermittent demand time series.
  • Censored time series can be modelled using cents and carx.
  • Portmanteau tests are provided via Box.test() in the stats package. Additional tests are given by portes and WeightedPortTest.
  • Change point detection is provided in strucchange (using linear regression models), and in trend (using nonparametric tests). The changepoint package provides many popular changepoint methods, and ecp does nonparametric changepoint detection for univariate and multivariate series. InspectChangepoint uses sparse projection to estimate changepoints in high-dimensional time series.
  • Tests for possibly non-monotonic trends are provided by funtimes.
  • Time series imputation is provided by the imputeTS package. Some more limited facilities are available using na.interp() from the forecast package. mtsdi implements an EM algorithm for imputing missing values in multivariate normal time series, accounting for spatial and temporal correlations.
  • Forecasts can be combined using ForecastComb which supports many forecast combination methods including simple, geometric and regression-based combinations. forecastHybrid provides functions for ensemble forecasts, combining approaches from the forecast package. opera has facilities for online predictions based on combinations of forecasts provided by the user. mafs fits several forecast models and selects the best one according to an error metric.
  • Forecast evaluation is provided in the accuracy() function from forecast. Distributional forecast evaluation using scoring rules is available in scoringRules
  • Tidy tools for forecasting are provided by sweep, converting objects produced in forecast to "tidy" data frames.
  • Miscellaneous: ltsa contains methods for linear time series analysis, timsac for time series analysis and control, and tsbugs for time series BUGS models.

Frequency analysis

  • Spectral density estimation is provided by spectrum() in the stats package, including the periodogram, smoothed periodogram and AR estimates. Bayesian spectral inference is provided by bspec. quantspec includes methods to compute and plot Laplace periodograms for univariate time series. The Lomb-Scargle periodogram for unevenly sampled time series is computed by lomb. spectral uses Fourier and Hilbert transforms for spectral filtering. psd produces adaptive, sine-multitaper spectral density estimates. kza provides Kolmogorov-Zurbenko Adaptive Filters including break detection, spectral analysis, wavelets and KZ Fourier Transforms. multitaper also provides some multitaper spectral analysis tools.
  • Wavelet methods: The wavelets package includes computing wavelet filters, wavelet transforms and multiresolution analyses. Wavelet methods for time series analysis based on Percival and Walden (2000) are given in wmtsa. WaveletComp provides some tools for wavelet-based analysis of univariate and bivariate time series including cross-wavelets, phase-difference and significance tests. Tests of white noise using wavelets are provided by hwwntest. Further wavelet methods can be found in the packages brainwaver, rwt, waveslim, wavethresh and mvcwt.
  • Harmonic regression using Fourier terms is implemented in HarmonicRegression. The forecast package also provides some simple harmonic regression facilities via the fourier function.

Decomposition and Filtering

  • Filters and smoothing: filter() in stats provides autoregressive and moving average linear filtering of multiple univariate time series. The robfilter package provides several robust time series filters, while mFilter includes miscellaneous time series filters useful for smoothing and extracting trend and cyclical components. smooth() from the stats package computes Tukey's running median smoothers, 3RS3R, 3RSS, 3R, etc. sleekts computes the 4253H twice smoothing method.
  • Decomposition: Seasonal decomposition is discussed below. Autoregressive-based decomposition is provided by ArDec. tsdecomp implements ARIMA-based decomposition of quarterly and monthly data. rmaf uses a refined moving average filter for decomposition.
  • Singular Spectrum Analysis is implemented in Rssa, ASSA and spectral.methods.
  • Empirical Mode Decomposition (EMD) and Hilbert spectral analysis is provided by EMD. Additional tools, including ensemble EMD, are available in hht. An alternative implementation of ensemble EMD and its complete variant are available in Rlibeemd.

Seasonality

  • Seasonal decomposition: the stats package provides classical decomposition in decompose(), and STL decomposition in stl(). Enhanced STL decomposition is available in stlplus. stR provides Seasonal-Trend decomposition based on Regression.
  • X-13-ARIMA-SEATS binaries are provided in the x13binary package, with seasonal providing an R interface and seasonalview providing a GUI. An alternative interface is provided by x12, with an associated alternative GUI provided by x12GUI.
  • Analysis of seasonality: the bfast package provides methods for detecting and characterizing abrupt changes within the trend and seasonal components obtained from a decomposition. npst provides a generalization of Hewitt's seasonality test.
  • season: Seasonal analysis of health data including regression models, time-stratified case-crossover, plotting functions and residual checks.
  • seas: Seasonal analysis and graphics, especially for climatology.
  • deseasonalize: Optimal deseasonalization for geophysical time series using AR fitting.

Stationarity, Unit Roots, and Cointegration

  • Stationarity and unit roots: tseries provides various stationarity and unit root tests including Augmented Dickey-Fuller, Phillips-Perron, and KPSS. Alternative implementations of the ADF and KPSS tests are in the urca package, which also includes further methods such as Elliott-Rothenberg-Stock, Schmidt-Phillips and Zivot-Andrews tests. uroot provides seasonal unit root tests. CADFtest provides implementations of both the standard ADF and a covariate-augmented ADF (CADF) test. MultipleBubbles tests for the existence of bubbles based on Phillips-Shi-Yu (2015).
  • Local stationarity: locits provides a test of local stationarity and computes the localized autocovariance. Time series costationarity determination is provided by costat. LSTS has functions for locally stationary time series analysis. Locally stationary wavelet models for nonstationary time series are implemented in wavethresh (including estimation, plotting, and simulation functionality for time-varying spectra).
  • Cointegration: The Engle-Granger two-step method with the Phillips-Ouliaris cointegration test is implemented in tseries and urca. The latter additionally contains functionality for the Johansen trace and lambda-max tests. tsDyn provides Johansen's test and AIC/BIC simultaneous rank-lag selection. CommonTrend provides tools to extract and plot common trends from a cointegration system. Parameter estimation and inference in a cointegrating regression are implemented in cointReg. nardl estimates nonlinear cointegrating autoregressive distributed lag models.

Nonlinear Time Series Analysis

  • Nonlinear autoregression: Various forms of nonlinear autoregression are available in tsDyn including additive AR, neural nets, SETAR and LSTAR models, threshold VAR and VECM. Neural network autoregression is also provided in GMDH. nnfor provides time series forecasting with neural networks. NlinTS includes neural network VAR, and a nonlinear version of the Granger causality test based on feedforward neural networks. bentcableAR implements Bent-Cable autoregression. BAYSTAR provides Bayesian analysis of threshold autoregressive models.
  • tseriesChaos provides an R implementation of the algorithms from the TISEAN project.
  • Autoregression Markov switching models are provided in MSwM, while dependent mixtures of latent Markov models are given in depmix and depmixS4 for categorical and continuous time series.
  • Tests: Various tests for nonlinearity are provided in fNonlinear. tseriesEntropy tests for nonlinear serial dependence based on entropy metrics.
  • Additional functions for nonlinear time series are available in nlts and nonlinearTseries.
  • Fractal time series modeling and analysis is provided by fractal. fractalrock generates fractal time series with non-normal returns distributions.

Dynamic Regression Models

  • Dynamic linear models: A convenient interface for fitting dynamic regression models via OLS is available in dynlm; an enhanced approach that also works with other regression functions and more time series classes is implemented in dyn. More advanced dynamic system equations can be fitted using dse. Gaussian linear state space models can be fitted using dlm (via maximum likelihood, Kalman filtering/smoothing and Bayesian methods), or using bsts which uses MCMC. dLagM provides time series regression with distributed lags. Functions for distributed lag nonlinear modelling are provided in dlnm.
  • Time-varying parameter models can be fitted using the tpr package.
  • orderedLasso fits a sparse linear model with an order constraint on the coefficients in order to handle lagged regressors where the coefficients decay as the lag increases.
  • Dynamic modeling of various kinds is available in dynr including discrete and continuous time, linear and nonlinear models, and different types of latent variables.

Multivariate Time Series Models

  • Vector autoregressive (VAR) models are provided via ar() in the basic stats package including order selection via the AIC. These models are restricted to be stationary. MTS is an all-purpose toolkit for analyzing multivariate time series including VAR, VARMA, seasonal VARMA, VAR models with exogenous variables, multivariate regression with time series errors, and much more. Possibly non-stationary VAR models are fitted in the mAr package, which also allows VAR models in principal component space. sparsevar allows estimation of sparse VAR and VECM models, bigtime estimates large sparse VAR, VARX and VARMA models, while BigVAR estimates VAR and VARX models with structured lasso penalties and svars implements data-driven structural VARs. Automated VAR models and networks are available in autovarCore. More elaborate models are provided in package vars, tsDyn, estVARXls() in dse. Another implementation with bootstrapped prediction intervals is given in VAR.etp. mlVAR provides multi-level vector autoregression. VARsignR provides routines for identifying structural shocks in VAR models using sign restrictions. gdpc implements generalized dynamic principal components. pcdpca extends dynamic principal components to periodically correlated multivariate time series. onlineVAR implements online fitting of time-adaptive lasso VARs.
  • VARIMA models and state space models are provided in the dse package. EvalEst facilitates Monte Carlo experiments to evaluate the associated estimation methods.
  • Vector error correction models are available via the urca, ecm, vars, tsDyn packages, including versions with structural constraints and thresholding.
  • Time series component analysis: Time series factor analysis is provided in tsfa. ForeCA implements forecastable component analysis by searching for the best linear transformations that make a multivariate time series as forecastable as possible. PCA4TS finds a linear transformation of a multivariate time series giving lower-dimensional subseries that are uncorrelated with each other. One-sided dynamic principal components are computed in odpc. Frequency-domain-based dynamic PCA is implemented in freqdom.
  • Multivariate state space models An implementation is provided by the KFAS package which provides a fast multivariate Kalman filter, smoother, simulation smoother and forecasting. Yet another implementation is given in the dlm package which also contains tools for converting other multivariate models into state space form. MARSS fits constrained and unconstrained multivariate autoregressive state-space models using an EM algorithm. All of these packages assume the observational and state error terms are uncorrelated.
  • Partially-observed Markov processes are a generalization of the usual linear multivariate state space models, allowing non-Gaussian and nonlinear models. These are implemented in the pomp package.
  • Multivariate stochastic volatility models (using latent factors) are provided by factorstochvol.

Analysis of large groups of time series

  • Time series clustering is implemented in TSclust, dtwclust, BNPTSclust and pdc.
  • TSdist provides distance measures for time series data.
  • TSrepr includes methods for representing time series using dimension reduction and feature extraction.
  • jmotif implements tools based on time series symbolic discretization for finding motifs in time series and facilitates interpretable time series classification.
  • rucrdtw provides R bindings for functions from the UCR Suite to enable ultrafast subsequence search for a best match under Dynamic Time Warping and Euclidean Distance.
  • Methods for plotting and forecasting collections of hierarchical and grouped time series are provided by hts. thief uses hierarchical methods to reconcile forecasts of temporally aggregated time series. An alternative approach to reconciling forecasts of hierarchical time series is provided by gtop. thief

Functional time series

  • Tools for visualizing, modeling, forecasting and analysis of functional time series are implemented in ftsa.
  • freqdom.fda provides implements of dynamical functional principal components for functional time series.

Continuous time models

  • Continuous time autoregressive modelling is provided in cts, while carfima allows for continuous-time ARFIMA models.
  • Sim.DiffProc simulates and models stochastic differential equations.
  • Simulation and inference for stochastic differential equations is provided by sde and yuima.

Resampling

  • Bootstrapping: The boot package provides function tsboot() for time series bootstrapping, including block bootstrap with several variants. tsbootstrap() from tseries provides fast stationary and block bootstrapping. Maximum entropy bootstrap for time series is available in meboot. timesboot computes the bootstrap CI for the sample ACF and periodogram. BootPR computes bias-corrected forecasting and bootstrap prediction intervals for autoregressive time series.

Time Series Data

  • Data from Makridakis, Wheelwright and Hyndman (1998) Forecasting: methods and applications are provided in the fma package.
  • Data from Hyndman, Koehler, Ord and Snyder (2008) Forecasting with exponential smoothing are in the expsmooth package.
  • Data from Hyndman and Athanasopoulos (2013) Forecasting: principles and practice are in the fpp package.
  • Data from Hyndman and Athanasopoulos (2017) Forecasting: principles and practice (2nd ed) are in the fpp2 package.
  • Data from the M-competition and M3-competition are provided in the Mcomp package. Tcomp provides data from the 2010 IJF Tourism Forecasting Competition.
  • pdfetch provides facilities for downloading economic and financial time series from public sources.
  • Data from the Quandl online portal to financial, economical and social datasets can be queried interactively using the Quandl package.
  • Data from the Datamarket online portal can be fetched using the rdatamarket package.
  • Data from Switzerland via dataseries.org can be downloaded and imported using dataseries.
  • BETS provides access to the most important economic time series in Brazil. rbcb is an R interface to access Brazilian Central Bank time series and other data.
  • Data from Cryer and Chan (2010) are in the TSA package.
  • Data from Shumway and Stoffer (2011) are in the astsa package.
  • tswge accompanies the text Applied Time Series Analysis with R, 2nd edition by Woodward, Gray, and Elliott.
  • TSdbi provides a common interface to time series databases.
  • fame provides an interface for FAME time series databases
  • influxdbr provides an interface to the InfluxDB time series database.
  • AER and Ecdat both contain many data sets (including time series data) from many econometrics text books

Miscellaneous

  • dtw: Dynamic time warping algorithms for computing and plotting pairwise alignments between time series.
  • ensembleBMA: Bayesian Model Averaging to create probabilistic forecasts from ensemble forecasts and weather observations.
  • earlywarnings: Early warnings signals toolbox for detecting critical transitions in time series
  • events: turns machine-extracted event data into regular aggregated multivariate time series.
  • FeedbackTS: Analysis of fragmented time directionality to investigate feedback in time series.
  • LPStimeSeries aims to find "learned pattern similarity" for time series.
  • MAR1 provides tools for preparing ecological community time series data for multivariate AR modeling.
  • nets: routines for the estimation of sparse long run partial correlation networks for time series data.
  • paleoTS: Modeling evolution in paleontological time series.
  • pastecs: Regulation, decomposition and analysis of space-time series.
  • PSF: Forecasting univariate time series using pattern-sequences.
  • ptw: Parametric time warping.
  • RGENERATE provides tools to generate vector time series.
  • RMAWGEN is set of S3 and S4 functions for spatial multi-site stochastic generation of daily time-series of temperature and precipitation making use of VAR models. The package can be used in climatology and statistical hydrology.
  • RSEIS: Seismic time series analysis tools.
  • rts: Raster time series analysis (e.g., time series of satellite images).
  • sae2: Time series models for small area estimation.
  • spTimer: Spatio-temporal Bayesian modelling.
  • surveillance: Temporal and spatio-temporal modeling and monitoring of epidemic phenomena.
  • TED: Turbulence time series Event Detection and classification.
  • Tides: Functions to calculate characteristics of quasi periodic time series, e.g. observed estuarine water levels.
  • tiger: Temporally resolved groups of typical differences (errors) between two time series are determined and visualized.
  • tsfknn: Time series forecasting with k-nearest-neighbours.
  • TSMining: Mining Univariate and Multivariate Motifs in Time-Series Data.
  • tsModel: Time series modeling for air pollution and health.

View on CRAN

4 days ago

Rob J Hyndman

Packages

56
118
122
139
144
209
227
233
240
247
302
316
319
343
379
387
513
517
527
533
542
558
560
567
614
647
660
664
674
684
688
826
858
938
961
1009
1041
1150
1164
1199
1264
1307
1359
1382
1394
1404
1407
1436
1446
1459
1516
1584
1686
1687
1704
1718
1735
1741
1782
1786
1788
1797
1798
1801
1886
1894
1948
1985
1994
2019
2020
2043
2127
2137
2138
2143
2204
2206
2212
2215
2248
2267
2281
2295
2306
2307
2310
2335
2359
2390
2396
2417
2448
2456
2471
2482
2489
2510
2515
2529
2539
2550
2569
2576
2582
2614
2621
2686
2743
2770
2772
2781
2782
2789
2805
2811
2825
2859
2876
2877
2878
2885
2921
2931
2951
2956
3000
3003
3010
3011
3084
3108
3112
3127
3154
3194
3205
3217
3226
3242
3267
3274
3276
3295
3315
3318
3385
3386
3399
3405
3446
3490
3540
3543
3544
3557
3569
3579
3617
3635
3685
3697
3705
3779
3827
3829
3841
3844
3883
3891
3909
3942
3958
3978
4002
4008
4017
4084
4100
4129
4150
4175
4191
4211
4234
4255
4258
4266
4271
4303
4357
4369
4389
4414
4422
4434
4440
4483
4488
4549
4566
4577
4609
4625
4631
4641
4642
4693
4718
4733
4752
4876
4911
4929
4985
5030
5031
5213
5602
6090

Discussions