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.
acf(x, lag.max = NULL,
type = c("correlation", "covariance", "partial"),
plot = TRUE, na.action = na.fail, demean = TRUE, …)pacf(x, lag.max, plot, na.action, …)
# S3 method for default
pacf(x, lag.max = NULL, plot = TRUE, na.action = na.fail,
...)
ccf(x, y, lag.max = NULL, type = c("correlation", "covariance"),
plot = TRUE, na.action = na.fail, …)
# S3 method for acf
[(x, i, j)
a univariate or multivariate (not ccf
) numeric time
series object or a numeric vector or matrix, or an "acf"
object.
maximum lag at which to calculate the acf. Default is \(10\log_{10}(N/m)\) where \(N\) is the number of observations and \(m\) the number of series. Will be automatically limited to one less than the number of observations in the series.
character string giving the type of acf to be computed.
Allowed values are
"correlation"
(the default), "covariance"
or
"partial"
. Will be partially matched.
logical. If TRUE
(the default) the acf is plotted.
function to be called to handle missing
values. na.pass
can be used.
logical. Should the covariances be about the sample means?
further arguments to be passed to plot.acf
.
a set of lags (time differences) to retain.
a set of series (names or numbers) to retain.
An object of class "acf"
, which is a list with the following
elements:
A three dimensional array containing the lags at which the acf is estimated.
An array with the same dimensions as lag
containing
the estimated acf.
The type of correlation (same as the type
argument).
The number of observations in the time series.
The name of the series x
.
The series names for a multivariate time series.
The lag k value returned by ccf(x, y) estimates the correlation between x[t+k] and y[t].
The result is returned invisibly if plot is TRUE.
For type
= "correlation"
and "covariance"
, the
estimates are based on the sample covariance. (The lag 0 autocorrelation
is fixed at 1 by convention.)
By default, no missing values are allowed. If the na.action
function passes through missing values (as na.pass
does), the
covariances are computed from the complete cases. This means that the
estimate computed may well not be a valid autocorrelation sequence,
and may contain missing values. Missing values are not allowed when
computing the PACF of a multivariate time series.
The partial correlation coefficient is estimated by fitting
autoregressive models of successively higher orders up to
lag.max
.
The generic function plot
has a method for objects of class
"acf"
.
The lag is returned and plotted in units of time, and not numbers of observations.
There are print
and subsetting methods for objects of class
"acf"
.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth Edition. Springer-Verlag.
(This contains the exact definitions used.)
plot.acf
, ARMAacf
for the exact
autocorrelations of a given ARMA process.
require(graphics)
## Examples from Venables & Ripley
acf(lh)
acf(lh, type = "covariance")
pacf(lh)
acf(ldeaths)
acf(ldeaths, ci.type = "ma")
acf(ts.union(mdeaths, fdeaths))
ccf(mdeaths, fdeaths, ylab = "cross-correlation")
# (just the cross-correlations)
presidents # contains missing values
acf(presidents, na.action = na.pass)
pacf(presidents, na.action = na.pass)
Run the code above in your browser using DataLab