\HeaderA{acf}{Auto- and Cross- Covariance and -Correlation Function Estimation}{acf}
\aliasA{ccf}{acf}{ccf}
\aliasA{pacf}{acf}{pacf}
\methaliasA{pacf.default}{acf}{pacf.default}
\aliasA{[.acf}{acf}{[.acf}
\keyword{ts}{acf}
\begin{Description}\relax
The function \code{acf} computes (and by default plots) estimates of
the autocovariance or autocorrelation function.  Function \code{pacf}
is the function used for the partial autocorrelations.  Function
\code{ccf} computes the cross-correlation or cross-covariance of two
univariate series.
\end{Description}
\begin{Usage}
\begin{verbatim}
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, ...)

## Default S3 method:
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 class 'acf':
x[i, j]
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, y}] a univariate or multivariate (not \code{ccf}) numeric time
series object or a numeric vector or matrix, or an \code{"acf"} object.
\item[\code{lag.max}] maximum lag at which to calculate the acf.
Default is \eqn{10\log_{10}(N/m)}{10*log10(N/m)} where \eqn{N}{} is the
number of observations and \eqn{m}{} the number of series.  Will
be automatically limited to one less than the number of observations
in the series.
\item[\code{type}] character string giving the type of acf to be computed.
Allowed values are
\code{"correlation"} (the default), \code{"covariance"} or
\code{"partial"}.
\item[\code{plot}] logical. If \code{TRUE} (the default) the acf is plotted.
\item[\code{na.action}] function to be called to handle missing
values. \code{na.pass} can be used.
\item[\code{demean}] logical.  Should the covariances be about the sample
means?
\item[\code{...}] further arguments to be passed to \code{plot.acf}.
\item[\code{i}] a set of lags (time differences) to retain.
\item[\code{j}] a set of series (names or numbers) to retain.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
For \code{type} = \code{"correlation"} and \code{"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 \code{na.action}
function passes through missing values (as \code{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
\code{lag.max}.

The generic function \code{plot} has a method for objects of class
\code{"acf"}.

The lag is returned and plotted in units of time, and not numbers of
observations.

There are \code{print} and subsetting methods for objects of class
\code{"acf"}.
\end{Details}
\begin{Value}
An object of class \code{"acf"}, which is a list with the following
elements:

\begin{ldescription}
\item[\code{lag}] A three dimensional array containing the lags at which
the acf is estimated.
\item[\code{acf}] An array with the same dimensions as \code{lag} containing
the estimated acf.
\item[\code{type}] The type of correlation (same as the \code{type}
argument).
\item[\code{n.used}] The number of observations in the time series.
\item[\code{series}] The name of the series \code{x}.
\item[\code{snames}] The series names for a multivariate time series.
\end{ldescription}


The lag \code{k} value returned by \code{ccf(x,y)} estimates the
correlation between \code{x[t+k]} and \code{y[t]}.

The result is returned invisibly if \code{plot} is \code{TRUE}.
\end{Value}
\begin{Author}\relax
Original: Paul Gilbert, Martyn Plummer.
Extensive modifications and univariate case of \code{pacf} by
B.D. Ripley.
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{plot.acf}{plot.acf}}, \code{\LinkA{ARMAacf}{ARMAacf}} for the exact
autocorrelations of a given ARMA process.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
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)
\end{ExampleCode}
\end{Examples}

