The χ2 distribution

### 8.4.9 The χ2 distribution

#### The probability density function for the χ2 distribution: chisquare

The χ2 distribution with n degrees of freedom has density function given by

χ2(n,x) = |
xn/2−1e−x/2
2n/2Γ(n/2)
| (6)

The chisquare command computes this density function.

- chisquare takes two arguments:
  - n, an integer (the degrees of freedom).
  - x, a real number.
- chisquare(n,x) returns the value of the χ2 density function with n degrees of freedom, given in (6).

#### Example

Input:

chisquare(5,2)

Output:

2 | √ |
2
e | ⎛ ⎜ ⎜ ⎝ |
3
4
|  | √ |
π
|  | √ |
2
| · 22 | ⎞ ⎟ ⎟ ⎠

which can be numerically approximated by:
Input:

evalf(chisquare(5,2))

Output:

0.138369165807

#### The cumulative distribution function for the χ2 distribution: chisquare_cdf

The chisquare_cdf command computes the cumulative distribution function for the χ2 distribution.

- chisquare_cdf takes two mandatory arguments and one optional argument:
  - n, an integer (the degrees of freedom).
  - x, a real number.
  - Optionally, y, a real number.
- chisquare_cdf(n,x) returns Prob(X ≤ x) for the χ2 distribution with n degrees of freedom.
- chisquare_cdf(n,x,y) returns Prob(x ≤ X < y).

#### Examples

- Input:
  chisquare_cdf(5,11)
  Output:

  0.948620016517

- Input:
  chisquare_cdf(3,1,2)
  Output:

  0.22884525243

#### The inverse distribution function for the χ2 distribution: chisquare_icdf

The chisquare_icdf command computes the inverse distribution for the χ2 distribution.

- chisquare_icdf takes two arguments:
  - n, an integer (the degrees of freedom).
  - h, a real number between 0 and 1.
- chisquare_icdf(n, h) returns the inverse distribution for the χ2 distribution with n degrees of freedom; namely, the value of x for which Prob(X ≤ x) = h.

#### Example

Input:

chisquare_icdf(5,0.95)

Output:

11.0704976935

#### The upper tail cumulative function for the χ2 distribution: UTPC

The UTPC (the Upper Tail Probability - Chi-square distribution) computes Prob(X > x) for the χ2 distribution.

- UTPC takes two arguments:
  - n, an integer (the degrees of freedom).
  - x, a real number.
- UTPC(n,x) returns Prob(X > x) for the χ2 distribution with n degrees of freedom.

#### Example

Input:

UTPC(5,11)

Output:

0.0513799834831