Skip to main content
Statistics LibreTexts

16.3: Goodness of Fit χ² Formula

  • Page ID
    17428
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The calculations for our test statistic in \(\chi^{2}\) tests combine our information from our observed frequencies (\(O\)) and our expected frequencies (\(E\)) for each level of our qualitative variable. For each cell (category) we find the difference between the observed and expected values, square them, and divide by the expected values. We then sum this value across cells for our test statistic. This is shown in the formula:

    \[\chi^{2}=\sum_{Each}\left(\dfrac{\left(E-O\right)^{2}}{E} \right) \nonumber \]

    This formula is telling us to find the difference, square it, then divide by the Expected value for that category, and then add together that number for each categor.

    Huh?  Let's continue to use our pet preference data, shown in Table \(\PageIndex{1}\) to see what that means.  We'll first use the table to do all of the calculations described in the formula, then use the formula alone.  

    Table \(\PageIndex{1}\)- Pet Preference Observations & Expectations
      Cat Dog Other Total
    Observed Frequencies 14 17 5 36
    Expected Frequencies 12 12 12 36
    Difference Score (E Minus O)        
    Difference Score Squared        
    Diff2 divided by Expected         

    Let's look at Table \(\PageIndex{1}\) a little closer first.  The Total column is the sum of the frequencies in that row.  In this case, the Total is also our N because each person could only choose one type of pet.  To determine the Expected frequencies, we used to Total, and divided it by how many groups we have (k = 3, which are Cats, Dogs, Other):

    \[ \dfrac{Total}{k} = \dfrac{36}{3} = 12 \nonumber \]

    Okay, now that know where the numbers come from so far, fill in the rest of the table.

    Example \(\PageIndex{1}\)

    Calculate the formula to complete Table \(\PageIndex{1}\).

    Solution

    Table \(\PageIndex{2}\)- Pet Preference Observations & Expectations
      Cat Dog Other Total
    Observed Frequencies 14 17 5 36
    Expected Frequencies 12 12 12 36
    Difference Score (E Minus O) -2 -5 7 0
    Difference Score Squared (Diff2) 4 25 49 78
    Diff2 divided by Expected  0.33 2.08 4.08 6.49

     

    What would this look like with our Chi-Square formula?

    \[\chi^{2}=\dfrac{(14-12)^{2}}{12}+\dfrac{(17-12)^{2}}{12}+\dfrac{(5-12)^{2}}{12}=0.33+2.08+4.08=6.49 \nonumber \]

    For each category's calculation, the expected value in the numerator and the expected value in the denominator are the same value whether we used the table or the formula.  As you have noticed, the result is also the same whether you use the table to do the calculations, or did it all with the formula.  The table is explaining each step of the formula, but they are exactly the same process.  It's Statisticians Choice how you would like to calculate Chi-Square (table of formula).  

    Let’s now take a look at an example from start to finish.

    Contributors and Attributions


    This page titled 16.3: Goodness of Fit χ² Formula is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Michelle Oja.