\documentclass[11pt, oneside]{article}   	% use "amsart" instead of "article" for AMSLaTeX format

\usepackage{booktabs}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\newcommand{\createcontingencytable}[4]{ %
% #1=table name
% #2=first column name
% #3=new row sum name
% #4=new column sum name
\pgfplotstablecreatecol[
    create col/assign/.code={% In each row ... 
        \def\rowsum{0}
        \pgfmathtruncatemacro\maxcolindex{\pgfplotstablecols-1}
        % ... loop over all columns, summing up the elements
        \pgfplotsforeachungrouped \col in {1,...,\maxcolindex}{
            \pgfmathsetmacro\rowsum{\rowsum+\thisrowno{\col}}
        }
        \pgfkeyslet{/pgfplots/table/create col/next content}\rowsum
    }
]{#3}{#1}%
%
% Transpose the table, so we can repeat the summation step for the columns
\pgfplotstabletranspose[colnames from={#2},input colnames to={#2}]{\intermediatetable}{#1}
%
% Sums for each column
\pgfplotstablecreatecol[
    create col/assign/.code={%
        \def\colsum{0}
        \pgfmathtruncatemacro\maxcolindex{\pgfplotstablecols-1}
        \pgfplotsforeachungrouped \col in {1,...,\maxcolindex}{
            \pgfmathsetmacro\colsum{\colsum+\thisrowno{\col}}
        }
        \pgfkeyslet{/pgfplots/table/create col/next content}\colsum
    }
]{#4}\intermediatetable
%
% Transpose back to the original form
\pgfplotstabletranspose[colnames from=#2, input colnames to=#2]{\contingencytable}{\intermediatetable}
}
%

\usepackage[top=1in]{geometry}                		% See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper}                   		% ... or a4paper or a5paper or ... 
%\geometry{landscape}                		% Activate for rotated page geometry
%\usepackage[parfill]{parskip}    		% Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}				% Use pdf, png, jpg, or eps§ with pdflatex; use eps in DVI mode
								% TeX will automatically convert eps --> pdf in pdflatex		
\usepackage{amssymb, amsmath}

%SetFonts

%SetFonts


\title{Stat 185 -Quiz 1\\
\large Friday, Sept 1}
\date{}							% Activate to display a given date or no date
\author{}

\begin{document}
\maketitle
\thispagestyle{empty}
\pagestyle{empty}
\vspace{-0.5in}

\begin{flushright}
Name:\underline{\hspace{2.2in}}
\end{flushright}

\begin{enumerate}
	\item Given the data set $\{4, 5, 6, 8, 3, 8, 9, 7, 6, 2, 3\}$,
	\begin{enumerate}
		\item Compute the corresponding five point summary
		\item Find the inter-quartile range
		\item Draw the corresponding box-plot
	\end{enumerate}
	
	\item Classify the histogram shown in figure \ref{hist} on the reverse as 
	\begin{enumerate}
		\item symmetric or skewed and
		\item  unimodal or bimodal.
	\end{enumerate}
	
	\item Students in an intro stats class were asked to classify their politics as Liberal, Moderate, or Conservative. The results are shown in table \ref{tabl1} below.
	\begin{enumerate}
		\item What percent of the class is male?
		\item What percent of the class considers themselves to be conservative?
		\item What percent of the of the men in the class consider themselves to be conservative?
		\item What percent of the class are men who consider themselves to be conservative?
	\end{enumerate}
\end{enumerate}


\begin{table}
\pgfplotstableread{
    Gender Liberal Moderate Conservative
    Female            35 36 6
    Male           50 44 21
}\chisquaredata
\createcontingencytable{\chisquaredata}{Gender}{Total by Gender}{Total by Politics}

\pgfplotstabletypeset[
  every head row/.style={%
    before row={\toprule 
        & \multicolumn{3}{c}{Politics}\\            \cmidrule{2-4}},
    after row=\midrule},
  every last row/.style={after row=\bottomrule},
  columns/Gender/.style={string type},
  columns={Gender, Liberal, Moderate, Conservative, {Total by Gender}},
]\contingencytable
\label{tabl1}
\caption{A contingency table for problem 3}
\end{table}

\begin{figure}[htbp]
\begin{center}
\includegraphics*[height=3in]{quiz1_hist.pdf}
\caption{A histogram}
\label{hist}
\end{center}
\end{figure}



\end{document}  
