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. slider calculates a diverse and comprehensive set of type-stable running functions for any R data types. tsibble provides slide() for rolling statistics, tile() for non-overlapping sliding windows, and stretch() for expanding windows. tbrf provides rolling functions based on date and time windows instead of n-lagged observations. roll provides parallel functions for computing rolling statistics. runner provides tools for running any R function in rolling windows or date windows. runstats provides fast computational methods for some running sample statistics. For data.table, froll() can be used for high-performance 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(). Seasonal displays are obtained using monthplot() in stats, seasonplot in forecast, and seasplot in tsutils. feasts and brolgar provide various time series graphics for tsibble objects including time plots, season plots, subseries plots, ACF and PACF plots, and some combination displays. Interactive graphics for tsibbles using htmlwidgets are provided by tsibbletalk. SDD provides more general serial dependence diagrams, while dCovTS computes and plots the distance covariance and correlation functions of time series. ggseas provides additional ggplot2 graphics for seasonally adjusted series and rolling statistics. Calendar plots are implemented in sugrrants. gravitas allows for visualizing probability distributions conditional on bivariate temporal granularities. 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, while clock provides a comprehensive library for date-time manipulations using a new family of orthogonal date-time classes (durations, time points, zoned-times, and calendars). 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.
- 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 and disaggR.
- 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.