Chisquare {base} | R Documentation |
Density, distribution function, quantile function and random
generation for the chi-squared (\chi^2
) distribution with
df
degrees of freedom and optional non-centrality parameter
ncp
.
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, ncp=0)
x , q |
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. If |
df |
degrees of freedom. |
ncp |
non-centrality parameter. For |
log , log.p |
logical; if TRUE, probabilities p are given as log(p). |
lower.tail |
logical; if TRUE (default), probabilities are
|
The chi-squared distribution with df
= n
degrees of
freedom has density
f_n(x) = \frac{1}{{2}^{n/2} \Gamma (n/2)} {x}^{n/2-1} {e}^{-x/2}
for x > 0
. The mean and variance are n
and 2n
.
The non-central chi-squared distribution with df
= n
degrees of freedom and non-centrality parameter ncp
= \lambda
has density
f(x) = e^{-\lambda / 2}
\sum_{r=0}^\infty \frac{(\lambda/2)^r}{r!}\, f_{n + 2r}(x)
for x \ge 0
. It is the distribution of the sum of squares of
n
normals each with variance one, \lambda
being the sum of
squares of the normal means.
dchisq
gives the density, pchisq
gives the distribution
function, qchisq
gives the quantile function, and rchisq
generates random deviates.
dgamma
for the Gamma distribution which generalizes the
chi-squared one.
dchisq(1, df=1:3)
pchisq(1, df= 3)
pchisq(1, df= 3, ncp = 0:4)# includes the above
x <- 1:10
## Chi-squared(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))