\HeaderA{bartlett.test}{Bartlett Test of Homogeneity of Variances}{bartlett.test}
\methaliasA{bartlett.test.default}{bartlett.test}{bartlett.test.default}
\methaliasA{bartlett.test.formula}{bartlett.test}{bartlett.test.formula}
\keyword{htest}{bartlett.test}
\begin{Description}\relax
Performs Bartlett's test of the null that the variances in each of the
groups (samples) are the same.
\end{Description}
\begin{Usage}
\begin{verbatim}
bartlett.test(x, ...)

## Default S3 method:
bartlett.test(x, g, ...)

## S3 method for class 'formula':
bartlett.test(formula, data, subset, na.action, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a numeric vector of data values, or a list of numeric data
vectors representing the respective samples, or fitted linear model
objects (inheriting from class \code{"lm"}).
\item[\code{g}] a vector or factor object giving the group for the
corresponding elements of \code{x}.
Ignored if \code{x} is a list.
\item[\code{formula}] a formula of the form \code{lhs \textasciitilde{} rhs} where \code{lhs}
gives the data values and \code{rhs} the corresponding groups.
\item[\code{data}] an optional matrix or data frame (or similar: see
\code{\LinkA{model.frame}{model.frame}}) containing the variables in the
formula \code{formula}.  By default the variables are taken from
\code{environment(formula)}.
\item[\code{subset}] an optional vector specifying a subset of observations
to be used.
\item[\code{na.action}] a function which indicates what should happen when
the data contain \code{NA}s.  Defaults to
\code{getOption("na.action")}.
\item[\code{...}] further arguments to be passed to or from methods.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
If \code{x} is a list, its elements are taken as the samples or fitted
linear models to be compared for homogeneity of variances.  In this
case, the elements must either all be numeric data vectors or fitted
linear model objects, \code{g} is ignored, and one can simply use
\code{bartlett.test(x)} to perform the test.  If the samples are not
yet contained in a list, use \code{bartlett.test(list(x, ...))}.

Otherwise, \code{x} must be a numeric data vector, and \code{g} must
be a vector or factor object of the same length as \code{x} giving the
group for the corresponding elements of \code{x}.
\end{Details}
\begin{Value}
A list of class \code{"htest"} containing the following components:
\begin{ldescription}
\item[\code{statistic}] Bartlett's K-squared test statistic.
\item[\code{parameter}] the degrees of freedom of the approximate chi-squared
distribution of the test statistic.
\item[\code{p.value}] the p-value of the test.
\item[\code{method}] the character string
\code{"Bartlett test of homogeneity of variances"}.
\item[\code{data.name}] a character string giving the names of the data.
\end{ldescription}
\end{Value}
\begin{References}\relax
Bartlett, M. S. (1937).
Properties of sufficiency and statistical tests.
\emph{Proceedings of the Royal Statistical Society Series A}
\bold{160}, 268--282.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{var.test}{var.test}} for the special case of comparing variances in
two samples from normal distributions;
\code{\LinkA{fligner.test}{fligner.test}} for a rank-based (nonparametric)
\eqn{k}{}-sample test for homogeneity of variances;
\code{\LinkA{ansari.test}{ansari.test}} and \code{\LinkA{mood.test}{mood.test}} for two rank
based two-sample tests for difference in scale.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
plot(count ~ spray, data = InsectSprays)
bartlett.test(InsectSprays$count, InsectSprays$spray)
bartlett.test(count ~ spray, data = InsectSprays)
\end{ExampleCode}
\end{Examples}

