Chi Square Distribution

The chi square distribution, written as \chi^2 is a continuous probability distribution. A \chi^2 with k degrees of freedom has the Probability Density Function

    \begin{equation*} f(x) = \frac{1}{2^{\frac{k}{2}} \Gamma (\frac{k}{2})} x^{\frac{k}{2} - 1} e^{-\frac{x}{2}}, \quad x > 0 \end{equation*}

Here, \Gamma denotes the Gamma Distribution, of which the \chi^2 is a special case. In the opposite case, f(x)=0 for x \leq 0. Let X_1, X_2, \dots, X_k be k independent, standard normal variables. Then their sum of squares Q = \sum_{i=1}^k X_i^2 follows a \chi^2 distribution with k degrees of freedom, written as Q \sim \chi_k^2. For a thorough introduction to the chi squared distribution, watch the Chi Square Distribution Introduction at Khan Academy.

To the right, I have plotted probability density functions and their corresponding cumulative densities for three different chi squared distributions. I have plotted them for degrees of freedom equal to 1, 2 and 3. Take a look at the Chi Squared Probability Density Function with 1 degree of freedom (the blue line). It obviously has a very high probability close to zero. This makes sense because if you draw a single sample from a standard normal distribution and square it, it will likely be close to zero. You can download the code creating these plots here.

Chi Squared Probability Distribution Function PDF with different degrees of freedom
Chi Squared Cummulative Distribution Function CDF with different degrees of freedom
Chi Square Distribution SAS Code Example

Below, I have written a SAS code example, that lets you play around with the degrees of freedom in the \chi^2 distribution and plots the Chi Squared probability density function corresponding to the degrees of freedom you set. I encourage you to set k to different values and look what happens with the PDF. You know from above what happens when k is small. What happens to the density if k is very large? Try it out yourself.

%let k = 3;
 
/* Chi Squared PDF Curves */
data ChiSquared_PDF;
   do x=0 to 8 by 0.01;
      ChiSquared_PDF = pdf('chisquare', x, &k);
      output;
   end;
run;
 
/* Draw PDF Curve */
title "Chi Squared Density For k = &k";
proc sgplot data=ChiSquared_PDF noautolegend;
   series x=x y=ChiSquared_PDF / lineattrs = (thickness=2) legendlabel="Chi Squared PDF";
   keylegend "Chi Squared PDF" / position=NE location=inside across=1 noborder valueattrs=(Size=12 Weight=Bold) 
                                 titleattrs = (Size=12 Weight=Bold);
   xaxis label='x' labelattrs = (size=12 weight=Bold);
   yaxis display=(nolabel) label='PDF' labelattrs = (size=12 weight=Bold);
run;
title;