R Programming/Time Series

Introduction
In the following examples we will use the data set Mpyr which is included in the R-package Ecdat, which can be loaded into R and viewed in R by the following code.

Creating time-series objects

 * The function ts is used to create time-series objects.
 * The function as.ts coerces an object to a time-series.
 * The function is.ts tests whether an object is a time-series.

Example:

Creating lagged and differenced variables

 * The function lag creates a lagged variable.
 * The function diff creates a differenced variable.

Example:

Plotting time-series objects

 * The function plot.ts is used for plotting time-series objects.

Fit Autoregressive Models to Time-series by OLS
In order to fit an autoregressive time series model to the data by ordinary least squares it is possible to use the function ar.ols which is part of the "stats" package.

Autocorrelation function
The function acf computes (and by default plots) estimates of the autocovariance or autocorrelation function. Function pacf is the function used for the partial autocorrelations. Function ccf computes the cross-correlation or cross-covariance of two univariate series.

Useful R-packages

 * fBasics, tis, zoo, tseries, xts, urca, forecast