\Header{Chisquare}{The (non-central) Chi-Square Distribution}
\alias{dchisq}{Chisquare}
\alias{pchisq}{Chisquare}
\alias{qchisq}{Chisquare}
\alias{rchisq}{Chisquare}
\keyword{distribution}{Chisquare}
\begin{Description}\relax
Density, distribution function, quantile function and random
generation for the chi-square (\eqn{\chi^2}{chi^2}) distribution with
\code{df} degrees of freedom and optional non-centrality parameter
\code{ncp}.\end{Description}
\begin{Usage}
\begin{verbatim}
dchisq(x, df, ncp=0, log = FALSE)
pchisq(q, df, ncp=0, lower.tail = TRUE, log.p = FALSE)
qchisq(p, df, ncp=0, lower.tail = TRUE, log.p = FALSE)
rchisq(n, df)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, q}] vector of quantiles.
\item[\code{p}] vector of probabilities.
\item[\code{n}] number of observations to generate.
\item[\code{df}] degrees of freedom.
\item[\code{ncp}] non-centrality parameter.
\item[\code{log, log.p}] logical; if TRUE, probabilities p are given as log(p).
\item[\code{lower.tail}] logical; if TRUE (default), probabilities are
\eqn{P[X \le x]}{P[X <= x]}, otherwise, \eqn{P[X > x]}{P[X > x]}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The chi-square distribution with \code{df}\eqn{= n}{} degrees of freedom
has density
\deqn{f_n(x) = \frac{1}{{2}^{n/2} \Gamma (n/2)} {x}^{n/2-1} {e}^{-x/2}}{f_n(x) = 1 / (2^(n/2) Gamma(n/2))  x^(n/2-1) e^(-x/2)}
for \eqn{x > 0}{}. Mean and variance are \eqn{n}{} and \eqn{2n}{}, respectively.

The non-central chi-square distribution with \code{df}\eqn{= n}{}
degrees of freedom and non-centrality parameter \code{ncp} \eqn{=
\lambda}{} has density
\deqn{
f(x) = e^{-\lambda / 2}
\sum_{r=0}^\infty \frac{(\lambda/2)^r}{r!}\, f_{n + 2r}(x)}{f(x) = exp(-lambda/2) SUM_{r=0}^infty ((lambda/2)^r / r!) dchisq(x, df + 2r)
}
for \eqn{x \ge 0}{}.\end{Details}
\begin{Value}
\code{dchisq} gives the density, \code{pchisq} gives the distribution
function, \code{qchisq} gives the quantile function, and \code{rchisq}
generates random deviates.\end{Value}
\begin{SeeAlso}\relax
\code{\Link{dgamma}} for the Gamma distribution which generalizes the
chi-square one.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
dchisq(1, df=1:3)
pchisq(1, df= 3)
pchisq(1, df= 3, ncp = 0:4)# includes the above

x <- 1:10
## Chisquare( df = 2) is a special exponential distribution
all.equal(dchisq(x, df=2), dexp(x, 1/2))
all.equal(pchisq(x, df=2), pexp(x, 1/2))
\end{ExampleCode}
\end{Examples}

