### 7.4.7 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

chisquare(n,x) =

xn/2−1e−x/2
2n/2Γ(n/2)

If you enter

chisquare(5,2)

you will get

2*sqrt(2)/(exp(1)*sqrt(2)*3*sqrt(pi))

which can be numerically approximated by

evalf(chisquare(5,2))

which is

0.138369165807

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

The cumulative distribution function for the χ2 distribution with n degrees of freedom at a value x is chisquare_cdf(n,x) = Prob(X ≤ x); if you enter

chisquare_cdf(5,11)

you will get

0.948620016517

If you give chisquare_cdf an extra argument, you will get the probability that the random variable lies between two values; chisquare_cdf(n,x,y) = Prob(x ≤ X ≤ y). If you enter

chisquare_cdf(3,1,2)

you will get

0.22884525243

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

The inverse distribution function for the χ2 distribution with n degrees of freedom is computed with chisquare_icdf(n,h); recall that this will return the value x with chisquare_cdf(n,x) = h. If you enter

chisquare_icdf(5,0.95)

you will get

11.0704976935

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

The UTPC (the Upper Tail Probability - Chi-square distribution) will compute Prob(X > x). If you enter

UTPC(5,11)

you will get

0.0513799834831