\HeaderA{Box.test}{Box-Pierce and Ljung-Box Tests}{Box.test}
\keyword{ts}{Box.test}
\begin{Description}\relax
Compute the Box--Pierce or Ljung--Box test statistic for examining the
null hypothesis of independence in a given time series.  These are
sometimes known as \sQuote{portmanteau} tests.
\end{Description}
\begin{Usage}
\begin{verbatim}
Box.test(x, lag = 1, type = c("Box-Pierce", "Ljung-Box"), fitdf = 0)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a numeric vector or univariate time series.
\item[\code{lag}] the statistic will be based on \code{lag} autocorrelation
coefficients.
\item[\code{type}] test to be performed: partial matching is used.
\item[\code{fitdf}] number of degrees of freedom to be subtracted if \code{x}
is a series of residuals.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
These tests are sometimes applied to the residuals from an
\code{ARMA(p, q)} fit, in which case the references suggest a better
approximation to the null-hypothesis distribution is obtained by
setting \code{fitdf = p+q}, provided of course that \code{lag > fitdf}.
\end{Details}
\begin{Value}
A list with class \code{"htest"} containing the following components:
\begin{ldescription}
\item[\code{statistic}] the value of the test statistic.
\item[\code{parameter}] the degrees of freedom of the approximate chi-squared
distribution of the test statistic (taking \code{fitdf} into account.
\item[\code{p.value}] the p-value of the test.
\item[\code{method}] a character string indicating which type of test was
performed.
\item[\code{data.name}] a character string giving the name of the data.
\end{ldescription}
\end{Value}
\begin{Note}\relax
Missing values are not handled.
\end{Note}
\begin{Author}\relax
A. Trapletti
\end{Author}
\begin{References}\relax
Box, G. E. P. and Pierce, D. A. (1970),
Distribution of residual correlations in autoregressive-integrated
moving average time series models.
\emph{Journal of the American Statistical Association}, \bold{65},
1509--1526.

Ljung, G. M. and Box, G. E. P. (1978),
On a measure of lack of fit in time series models.
\emph{Biometrika} \bold{65}, 297--303.

Harvey, A. C. (1993)
\emph{Time Series Models}.
2nd Edition, Harvester Wheatsheaf, NY, pp. 44, 45.
\end{References}
\begin{Examples}
\begin{ExampleCode}
x <- rnorm (100)
Box.test (x, lag = 1)
Box.test (x, lag = 1, type="Ljung")
\end{ExampleCode}
\end{Examples}

