%Initial setup
\documentclass[11pt]{article}
\title{EPSE592 Assignment \#4}
\author{Ed Kroc}

%Math Packages
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm,mathabx}
\usepackage{listings} 
\usepackage{hyperref}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{makecell}
\usepackage{setspace}

%General formatting Packages
\usepackage{fancyhdr} %To put headers in
\usepackage{multirow} %for tables
\usepackage{graphicx,graphpap,rotate,geometry,subfigure} 
\usepackage{enumitem} %Permits more customisation of lists than enumerate
\usepackage{tikz} %for textcolor

%Document Layout
%Text positioning
\marginparwidth 0pt %
\marginparsep 0pt  %distance between marginal notes box and main text
\oddsidemargin  0pt
\evensidemargin  0pt
\topmargin   0pt
\textwidth   6.8in %control width of text on 8.5X11 page
\textheight  9.50in %control height of text on 8.5X11 page
\voffset -0.8in

\newcommand{\pr}{\text{Pr}}
\newcommand{\e}{\mathbb{E}}
\newcommand{\var}{\text{Var}}
\newcommand{\sd}{\text{SD}}

%Header of the pages
\pagestyle{fancy}
\lhead{EPSE 592}
\rhead{Assignment 4}
\setlength{\headheight}{14pt} %to make room for the header vertically due do squashed height
\fancyhfoffset[R]{0.2in} %to stretch header to match the length of the textwidth.


%=============================
\begin{document}

\begin{center}
\textbf{WINTER 2019/20 TERM 2 \,\, EPSE 592: ASSIGNMENT 4 \\
Due: Apr. 16th}
\end{center}
\vspace{1mm}

\begin{itemize}
  \item
  Please make sure you write your answers to these questions in your own words. Even if you work with a group to formulate your responses, do not just copy someone else's sentences/words. 
  \item
  There is no need to record more than 3 decimal places for any of these problems.
  \item
  All problem data are available online in .csv format.
  \item
  All R code is available online in plain text format. Copy and paste {\em *exactly*} as recorded into the Rj editor of Jamovi. If Jamovi does not work on your computer: install base R from \begin{verbatim} https://www.r-project.org/ \end{verbatim} Then open R, copy and paste code {\em *exactly*} as recorded, and hit `enter'. {\bf In either platform, the code may take 10-30 seconds to compile.}
\end{itemize}
\vspace{1mm}

\begin{enumerate}[label=\textbf{Question \arabic*:},start=1]



%Question 1:
%===================================================
\item {\bf (Analysis of categorical data with omnibus and post hoc chi-squared statistics)} 

In the following sequence of questions, you will explore different applications of chi-squared tests for categorical data, and also investigate some of the problems with their {\em misapplication}.


\begin{enumerate}
	\item Suppose you conduct an informal poll among undergraduate students on campus about their degree goals. You are interested in determining if students from different faculties exhibit different desires to pursue graduate degrees. For each of 406 students polled, you ask them (1) what the faculty of their current degree program is, and (2) how strongly they currently want to pursue graduate studies within one year of completing their undergraduate degree. Respondents indicate the strength of their desire to pursue graduate work on a Likert scale of 1 (little or no desire) to 5 (absolutely want to pursue graduate work). You collect the following responses (data available on webpage):
\begin{table}[h!]
\begin{center}
\begin{tabular}{ c  c | c  c  c  c c | }
 & & \multicolumn{5}{c}{Faculty} \\ \cmidrule{3-7}
 &  & Arts & Science & Education & Applied Science & Business \\ 
\hline
\multirow{5}{*}{\thead{Likert\\ response}} & 1 & 9 & 18 & 22 & 25 & 27 \\
 & 2 & 13 & 14 & 21 & 33 & 17 \\ 
 & 3 & 10 & 15 & 19 & 13 & 18 \\ 
 & 4 & 20 & 11 & 11 & 17 & 7 \\ 
 & 5 & 17 & 13 & 9 & 15 & 12 \\ 
\hline
\end{tabular}
\end{center}
\end{table}

Conduct a $\chi^2$ test to see if there is evidence that students from different faculties express different desires to pursue graduate work. Report the p-value and interpret.

	\item The $\chi^2$ test above will indicate that evidence exists for a difference in desire to go to graduate school across faculties. But which faculties are different and which are alike? Before addressing this question, just how many different pairwise comparisons (across faculties) are possible?

\item Rather than running that many $\chi^2$ tests pairwise between faculties, examine the {\em proportions} of the 5 different Likert responses for each faculty. In Jamovi, you can do this quickly by clicking on the `Cells' dialogue box within your $\chi^2$ analysis, then selecting the `Column' option under `Percentages'. This will give you proportions within each cell; i.e., the {\em sample estimate} of the {\em probability distribution} of Likert responses for each faculty. To help visualize, you can also produce barplots and view the literal {\em sample frequency distributions} for interest in pursuing graduate studies (quantified by the Likert response) for each faculty. Run the following code in Jamovi's Rj-Editor to produce these plots (code available on the webpage - copy and paste from the .txt file into Jamovi):
\begin{lstlisting}
mat <- matrix(c(9,22,25,27,18, 13,21,33,17,14, 10,19,13,18,15, 
	20,11,17,7,11, 17,9,15,12,13),nrow=5,byrow=T)
par(mfrow=c(2,3))
barplot(mat[,3],names.arg=c("1","2","3","4","5"),
	main="Likert resp for Ap. Science",ylim=c(0,30))
barplot(mat[,1],names.arg=c("1","2","3","4","5"),
	main="Likert resp for Arts",ylim=c(0,30))
barplot(mat[,4],names.arg=c("1","2","3","4","5"),
	main="Likert resp for Business",ylim=c(0,30))
barplot(mat[,2],names.arg=c("1","2","3","4","5"),
	main="Likert resp for Education",ylim=c(0,30))
barplot(mat[,5],names.arg=c("1","2","3","4","5"),
	main="Likert resp for Science",ylim=c(0,30))

\end{lstlisting}
Examining these sample distributions, which faculty seems to be the {\em most} different from the rest, in terms of overall distribution of responses?

	\item For the faculty you identified as, informally, most dislike the others, now formally compare this faculty to the others by using pairwise $\chi^2$ tests (there will be 4 pairwise tests in total). [The easiest way to do this will be to copy and paste the relevant data cells into new columns for each chi-squared test.] Report the p-values and interpret for each of these tests.

	\item Recall that when we perform multiple hypothesis tests, we need to (potentially) worry about inflating our type I error (false positive) rates. The analytical procedure you just followed should be reminiscent of an omnibus ANOVA, followed by a sequence of post hoc pairwise comparisons. Recall that we adjust for the multiple testing problem in an ANOVA framework by reporting {\em adjusted p-values}, usually using either Tukey's or Scheff\'{e}'s method. Here, there are similar adjustments that can be made, but the only way we have learned how to adjust for multiple comparisons by hand is to perform a Bonferonni-type adjustment. Do this here as follows: divide your significance threshold by the number of post hoc tests performed (4 in total), and then reinterpret your p-values from part (d) with respect to this adjusted threshold. Note that this adjustment can change your interpretation {\em regardless} of if you use the traditional threshold or the orders of magnitude approach to interpreting p-values.

\end{enumerate}



\vspace*{3mm}

%Question 2:
%===================================================
\item {\bf (Where chi-squared tests fail, Fisher's exact tests prevail)} 

The research question in Q1 is a natural one, and we had lots of data available to address it. However, in practice, it is {\em quite} challenging, in terms of money and time spent, to survey 406 people. Instead, it is far more likely that you will find yourself in a data situation as below (data on webpage). Here, we have polled 54 undergraduate students about their desire to pursue graduate studies, using a 5-point Likert survey item.
\begin{table}[h!]
\begin{center}
\begin{tabular}{ c  c | c  c  c  c c | }
 & & \multicolumn{5}{c}{Faculty} \\ \cmidrule{3-7}
 &  & Arts & Science & Education & Applied Science & Business \\ 
\hline
\multirow{5}{*}{\thead{Likert\\ response}} & 1 & 1 & 4 & 3 & 4 & 4 \\
 & 2 & 2 & 4 & 3 & 4 & 4 \\ 
 & 3 & 0 & 3 & 4 & 2 & 4 \\ 
 & 4 & 4 & 0 & 0 & 0 & 0 \\ 
 & 5 & 3 & 0 & 0 & 1 & 0 \\ 
\hline
\end{tabular}
\end{center}
\end{table}


\begin{enumerate}
	\item Plot the sample frequency distributions for these responses per faculty (use the code on the webpage). Which faculty seems to be the {\em most} different from the rest, in terms of overall distribution of responses?

	\item Conduct a $\chi^2$ test to see if there is evidence that students from different faculties express different desires to pursue graduate work. Report the p-value and interpret.

	\item Recall one of the critical assumptions of the $\chi^2$ test: cell counts should be at least 5 in most of the table's cells, and no cells should have a count of 0. Clearly, these data violate this assumption quite severely. Instead, we should be applying a {\em Fisher's exact test}, which does not rely on any assumptions about sample size (total or cell-wise). Use the code on the webpage to peform a Fisher's exact test on these data. [Note: the p-value for this test will change slightly if you run the code multiple times, since Jamovi only approximates via simulation; like approximating the probability of flipping heads by counting how many heads appear on 20 tosses of a coin.] Report the p-value and interpret. Compare with the inference you made in part (b) from (inappropriately) applying a $\chi^2$ test.

	\item Now use the code on the webpage to perform a Fisher's exact test on the large dataset (406 respondents) from Q1. Report the p-value and interpret. Compare with the inference you made in Q1(a) from (appropriately) applying a $\chi^2$ test. 

\end{enumerate}







\end{enumerate}
\end{document}



