\HeaderA{FDist}{The F Distribution}{FDist}
\aliasA{df}{FDist}{df}
\aliasA{pf}{FDist}{pf}
\aliasA{qf}{FDist}{qf}
\aliasA{rf}{FDist}{rf}
\keyword{distribution}{FDist}
\begin{Description}\relax
Density, distribution function, quantile function and random
generation for the F distribution with \code{df1} and \code{df2}
degrees of freedom (and optional non-centrality parameter \code{ncp}).
\end{Description}
\begin{Usage}
\begin{verbatim}
df(x, df1, df2, ncp, log = FALSE)
pf(q, df1, df2, ncp, lower.tail = TRUE, log.p = FALSE)
qf(p, df1, df2, ncp, lower.tail = TRUE, log.p = FALSE)
rf(n, df1, df2, ncp)
\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. If \code{length(n) > 1}, the length
is taken to be the number required.
\item[\code{df1, df2}] degrees of freedom.  \code{Inf} is allowed.
\item[\code{ncp}] non-centrality parameter. If omitted the central F is assumed.
\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]}{}, otherwise, \eqn{P[X > x]}{}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The F distribution with \code{df1 =} \eqn{n_1}{} and \code{df2 =}
\eqn{n_2}{} degrees of freedom has density
\deqn{
f(x) = \frac{\Gamma(n_1/2 + n_2/2)}{\Gamma(n_1/2)\Gamma(n_2/2)}
\left(\frac{n_1}{n_2}\right)^{n_1/2} x^{n_1/2 -1}
\left(1 + \frac{n_1 x}{n_2}\right)^{-(n_1 + n_2) / 2}
}{}
for \eqn{x > 0}{}.

It is the distribution of the ratio of the mean squares of
\eqn{n_1}{} and \eqn{n_2}{} independent standard normals, and hence
of the ratio of two independent chi-squared variates each divided by its
degrees of freedom.  Since the ratio of a normal and the root
mean-square of \eqn{m}{} independent normals has a Student's \eqn{t_m}{}
distribution, the square of a \eqn{t_m}{} variate has a F distribution on
1 and \eqn{m}{} degrees of freedom.

The non-central F distribution is again the ratio of mean squares of
independent normals of unit variance, but those in the numerator are
allowed to have non-zero means and \code{ncp} is the sum of squares of
the means.  See \LinkA{Chisquare}{Chisquare} for further details on
non-central distributions.
\end{Details}
\begin{Value}
\code{df} gives the density,
\code{pf} gives the distribution function
\code{qf} gives the quantile function, and
\code{rf} generates random deviates.

Invalid arguments will result in return value \code{NaN}, with a warning.
\end{Value}
\begin{Source}\relax
For \code{df}, and \code{ncp == 0}, computed via a binomial
probability, code contributed by Catherine Loader (see \code{\LinkA{dbinom}{dbinom}});
for \code{ncp != 0}, computed via a \code{\LinkA{dbeta}{dbeta}},
code contributed by Peter Ruckdeschel.

For \code{pf}, via \code{\LinkA{pbeta}{pbeta}} (or for large \code{df2}, via
\code{\LinkA{pchisq}{pchisq}}).

For \code{qf}, via \code{\LinkA{qchisq}{qchisq}} for large \code{df2}, else via
\code{\LinkA{qbeta}{qbeta}}.
\end{Source}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.

Johnson, N. L., Kotz, S. and Balakrishnan, N. (1995)
\emph{Continuous Univariate Distributions}, volume 2, chapters 27 and 30.
Wiley, New York.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{dchisq}{dchisq}} for chi-squared and \code{\LinkA{dt}{dt}} for Student's
t distributions.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## the density of the square of a t_m is 2*dt(x, m)/(2*x)
# check this is the same as the density of F_{1,m}
x <- seq(0.001, 5, len=100)
all.equal(df(x^2, 1, 5), dt(x, 5)/x)

## Identity:  qf(2*p - 1, 1, df)) == qt(p, df)^2)  for  p >= 1/2
p <- seq(1/2, .99, length=50); df <- 10
rel.err <- function(x,y) ifelse(x==y,0, abs(x-y)/mean(abs(c(x,y))))
quantile(rel.err(qf(2*p - 1, df1=1, df2=df), qt(p, df)^2), .90)# ~= 7e-9
\end{ExampleCode}
\end{Examples}

