\setcounter{ExampleCounter}{1}
Remember, our goal now is to test how well data matches our expectation, specifically regarding how the data breaks down for a number of categories.

Let's go back to the M\&M example.  Suppose you opened a bag of 600 M\&Ms, separated them by color, and got the following counts for each category.
\begin{center}
\begin{tabular}{l l}
Color & Number\\
\hline
Blue & 212\\
Orange & 147\\
Green & 103\\
Red & 50\\
Yellow & 46\\
Brown & 42
\end{tabular}
\end{center}

You may already see evidence that the candies are not uniformly distributed, but how can we measure this?

\subsection{The Chi-Square Test Statistic}
The test statistic we use to measure how closely data matches our expected distribution is found by calculating how far off each category is, then combining all those errors:
\vfill

Or more concisely,
\vfill

Now, the larger this value, the more difference there is between what we expected and what we observe.  Therefore, the larger $\chi^2$ is, the less likely it is that our expected distribution was correct.
\vfill
\pagebreak

\subsection{The p Value}
The p value for this test will be the probability that $\chi^2$ could be at least as large as what we observe.  So if we get a large value for $\chi^2$, that probability will be relatively low (recall the shape of the $\chi^2$ distribution):
\begin{center}
\begin{tikzpicture}
  \begin{axis}[no markers, axis lines*=none,
  hide y axis,xtick={8},
  xticklabels={{$\chi^2$}},width=12cm, height=6cm]
    \addplot[domain=8:15,fill=cyan!40, draw=none]
      {chisquare(x,\grauliber)} \closedcycle;
    %\addplot[domain=0.01:\chiright]
      %{chisquare(x,\grauliber)} \closedcycle;
    \addplot[samples at={0.2,0.19,...,0}, thick]
      {chisquare(x,\grauliber)} -- (0,0);
    \addplot[samples=50, thick, smooth, domain=0.2:15]
      {chisquare(x,\grauliber)};
    \draw (0,0) -- (150,0);
    \draw [yshift=0.5cm, -latex](axis cs:8,0) -- node [fill=white] {$p$} (axis cs:15,0);
  \end{axis}
\end{tikzpicture}
\end{center}

\subsection{Testing Goodness of Fit}
Now that we have our test statistic ($\chi^2$) and we can calculate a p-value, the rest of the test is just like the others that we've done.
\begin{itemize}
\item \text{}
\vspace{1.5in}
\end{itemize}

\paragraph{Step 1:} State the hypotheses.

\vfill
\pagebreak

\paragraph{Step 2:} Calculate the test statistic.
\vspace{0.75in}

\paragraph{Step 3:} Calculate the p value (the area above the $\chi^2$ statistic:
\vspace{0.5in}

\paragraph{Step 4:} Draw a conclusion.
\begin{itemize}
\item \text{}
\vspace{0.5in}

\item \text{}
\vspace{0.5in}
\end{itemize}

\begin{example}{Work Absences}
A managers wants to know which days of the week her employees are absent in a five-day work week.  Most employers would like to believe that employees are absent equally during the week.  She tracked the next 60 absences and recorded on which day they occurred, and the results are shown in the table below.  Do the absences occur with equal frequencies during the work week?  Use a significance level of 0.05.

\begin{center}
\begin{tabular}{l c}
Day & Number of Absences\\
\hline
Monday & 15\\
Tuesday & 12\\
Wednesday & 9\\
Thursday & 9\\
Friday & 15
\end{tabular}
\end{center}

\paragraph{Step 1:} State the hypotheses.
\vspace{2in}
\pagebreak

\paragraph{Step 2:} Calculate the test statistic.
\vspace{0.5in}

\begin{center}
\begin{tabular}{l c c c}
Day & Observed Absences & Expected Absences & $O - E$\\
\hline
& & & \\
Monday & 15 & &\\
& & & \\
Tuesday & 12 & &\\
& & & \\
Wednesday & 9 & &\\
& & & \\
Thursday & 9 & &\\
& & & \\
Friday & 15 & &
\end{tabular}
\end{center}

\vspace{1in}

\begin{center}
\begin{tikzpicture}
  \begin{axis}[no markers, axis lines*=none,
  hide y axis,xtick={3},
  xticklabels={{$\chi^2$}},width=12cm, height=6cm]
    \addplot[domain=3:15,fill=cyan!40, draw=none]
      {chisquare(x,\grauliber)} \closedcycle;
    %\addplot[domain=0.01:\chiright]
      %{chisquare(x,\grauliber)} \closedcycle;
    \addplot[samples at={0.2,0.19,...,0}, thick]
      {chisquare(x,\grauliber)} -- (0,0);
    \addplot[samples=50, thick, smooth, domain=0.2:15]
      {chisquare(x,\grauliber)};
    \draw (0,0) -- (150,0);
    \draw [yshift=3cm, -latex](axis cs:3,0) -- node [fill=white] {$p$} (axis cs:15,0);
  \end{axis}
\end{tikzpicture}
\end{center}

\paragraph{Step 3:} Calculate the p value that corresponds to this area.  
\vspace{1in}

\paragraph{Step 4:} Draw a conclusion.
\vspace{1in}
\end{example}
\pagebreak

\begin{example}{TV Ownership}
A study concluded that the number of TVs in American households is distributed as in the table below.
\begin{center}
\begin{tabular}{c c}
Number of TVs & Percent\\
\hline
0 & 10\\
1 & 16\\
2 & 55\\
3 & 11\\
4+ & 8
\end{tabular}
\end{center}

A new study investigates households on the west coast of the US, to see if the distribution there is similar to the entire country, or if it is unique.  A random sample of 600 west coast households yielded the following data.
\begin{center}
\begin{tabular}{c c}
Number of TVs & Frequency\\
\hline
0 & 66\\
1 & 119\\
2 & 340\\
3 & 60\\
4+ & 15
\end{tabular}
\end{center}

Using a significance level of 0.01, does it seem that the distribution for the west coast is different from the country as a whole?

\paragraph{Step 1:} State the hypotheses.
\vspace{1in}

\paragraph{Step 2:} Calculate the test statistic.

\begin{center}
\begin{tabular}{l c c c}
Number of TVs & Observed Frequency & Expected Frequency & $O - E$\\
\hline
& & &\\
0 & 66 & &\\
& & &\\
1 & 119 & &\\
& & &\\
2 & 340 & &\\
& & &\\
3 & 60 & &\\
& & &\\
4+ & 15 & &
\end{tabular}
\end{center}


\vfill
\pagebreak

\text{}
\vspace{1.5in}

\begin{center}
\begin{tikzpicture}
  \begin{axis}[no markers, axis lines*=none,
  hide y axis,xtick={13},
  xticklabels={{$\chi^2$}},width=12cm, height=6cm]
    \addplot[domain=13:15,fill=cyan!40, draw=none]
      {chisquare(x,\grauliber)} \closedcycle;
    %\addplot[domain=0.01:\chiright]
      %{chisquare(x,\grauliber)} \closedcycle;
    \addplot[samples at={0.2,0.19,...,0}, thick]
      {chisquare(x,\grauliber)} -- (0,0);
    \addplot[samples=50, thick, smooth, domain=0.2:15]
      {chisquare(x,\grauliber)};
    \draw (0,0) -- (150,0);
    \draw [yshift=0.5cm, -latex](axis cs:13,0) -- node [fill=white] {$p$} (axis cs:15,0);
  \end{axis}
\end{tikzpicture}
\end{center}

\paragraph{Step 3:} Calculate the p value that corresponds to this area.  
\vspace{2in}

\paragraph{Step 4:} Draw a conclusion.\\
\vspace{1.5in}
\end{example}
\pagebreak

\begin{example}{Casino Game}
A new casino game involves rolling 3 dice, and winnings are based on the total number of sixes rolled.  A gambler played the game 100 times, with the following results.
\begin{center}
\begin{tabular}{c c}
Number of Sixes & Frequency\\
\hline
0 & 48\\
1 & 35\\
2 & 15\\
3 & 3
\end{tabular}
\end{center}

Should the casino ban this player for using rigged dice?

\paragraph{Step 1:} State the hypotheses.
\vspace{1in}

\paragraph{Step 2:} Calculate the test statistic.
\vspace{1in}

\begin{center}
\begin{tabular}{c c}
Number of Sixes & Probability\\
\hline
& \\
0 & \\
& \\
1 & \\
& \\
2 & \\
& \\
3 & 
\end{tabular}
\end{center}

\vfill

\begin{center}
\begin{tabular}{l c c c}
Number of Sixes & Observed Frequency & Expected Frequency & $O - E$\\
\hline
& & & \\
0 & 48 & &\\
& & & \\
1 & 35 & &\\
& & & \\
2 & 15 & &\\
& & & \\
3 & 3 & &
\end{tabular}
\end{center}
\pagebreak

\text{}
\vspace{1.5in}

\begin{center}
\begin{tikzpicture}
  \begin{axis}[no markers, axis lines*=none,
  hide y axis,xtick={13},
  xticklabels={{$\chi^2$}},width=12cm, height=6cm]
    \addplot[domain=13:15,fill=cyan!40, draw=none]
      {chisquare(x,\grauliber)} \closedcycle;
    %\addplot[domain=0.01:\chiright]
      %{chisquare(x,\grauliber)} \closedcycle;
    \addplot[samples at={0.2,0.19,...,0}, thick]
      {chisquare(x,\grauliber)} -- (0,0);
    \addplot[samples=50, thick, smooth, domain=0.2:15]
      {chisquare(x,\grauliber)};
    \draw (0,0) -- (150,0);
    \draw [yshift=0.5cm, -latex](axis cs:13,0) -- node [fill=white] {$p$} (axis cs:15,0);
  \end{axis}
\end{tikzpicture}
\end{center}

\paragraph{Step 3:} Calculate the p value that corresponds to this area.  
\vspace{2in}

\paragraph{Step 4:} Draw a conclusion.
\vspace{1.5in}
\end{example}
\vfill
\pagebreak