# Chisq-class

##### Class "Chisq"

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$. For integer $n$, this 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.
C.f. `rchisq`

- Keywords
- distribution

##### Note

Warning: The code for pchisq and qchisq is unreliable for values of ncp above approximately 290.

##### Objects from the Class

Objects can be created by calls of the form `Chisq(df, ncp)`

.
This object is a chi-squared distribution.

##### Extends

Class `"ExpOrGammaOrChisq"`

, directly.
Class `"AbscontDistribution"`

, by class `"ExpOrGammaOrChisq"`

.
Class `"UnivariateDistribution"`

, by class `"AbscontDistribution"`

.
Class `"Distribution"`

, by class `"UnivariateDistribution"`

.

##### Is-Relations

By means of `setIs`

, R ``knows'' that a distribution object `obj`

of class `"Chisq"`

with non-centrality 0 also is
a Gamma distribution with parameters `shape = df(obj)/2, scale = 2`

.

##### concept

- absolutely continuous distribution
- Chi square distribution
- S4 distribution class
- generating function

##### See Also

`ChisqParameter-class`

`AbscontDistribution-class`

`Reals-class`

`rchisq`

##### Examples

```
C <- Chisq(df = 1, ncp = 1) # C is a chi-squared distribution with df=1 and ncp=1.
r(C)(1) # one random number generated from this distribution, e.g. 0.2557184
d(C)(1) # Density of this distribution is 0.2264666 for x = 1.
p(C)(1) # Probability that x < 1 is 0.4772499.
q(C)(.1) # Probability that x < 0.04270125 is 0.1.
df(C) # df of this distribution is 1.
df(C) <- 2 # df of this distribution is now 2.
is(C, "Gammad") # no
C0 <- Chisq() # default: Chisq(df=1,ncp=0)
is(C0, "Gammad") # yes
as(C0,"Gammad")
```

*Documentation reproduced from package distr, version 2.0.2, License: LGPL-3*