title: Chi-square statistic across multiple columns of a dataframe using dplyr or reshape2
body: <p>I have a question about using <code>dplyr</code> and <code>reshape2</code> to calculate chi-square statistics across multiple columns. Below is a small dataframe...</p>
  
  <pre><code>Sat &lt;- c("Satisfied","Satisfied","Dissatisfied","Dissatisfied",
                                         "Neutral")
  
  Gender &lt;- c("Male","Male","Female","Male","Female")
  
  Ethnicity &lt;- c("Asian","White","White","Asian","White")
  
  AgeGroup &lt;- c("18-20","18-20","21-23","18-20","18-28")
  
  Example &lt;- data.frame(Sat,Gender,Ethnicity,AgeGroup)
  </code></pre>
  
  <p>How would I use <code>summarise_each</code> or <code>melt</code> to calculate the <code>Sat</code> column against each of the other variables to produce chi-square residual and p-value stats. I'm thinking there must be something like:</p>
  
  <pre><code>Example %&gt;% summarise_each(funs(chisq.test(... 
  </code></pre>
  
  <p>but I'm not sure how to finish it. Also, how would I melt the data frame and use <code>group_by</code> or <code>do()</code> to get the chi-square stats? I'm interested in seeing both methods. If there's a way to incorporate the <code>broom</code> package, that would be great too, or <code>tidyr</code> instead of <code>reshape2</code>. </p>
  
  <p>So to recap, I would like to run chi-square tests, such as </p>
  
  <pre><code>chisq.test(Example$Sat, Example$Gender)
  </code></pre>
  
  <p>but...I would like to produce chi-square stats for the <code>Sat</code> variable against <code>Gender</code>, <code>Ethnicity</code>, and <code>AgeGroup</code>. This is a small example, and I'm  hoping the methods above will allow me to create chi-square stats across many columns in a fast and efficient manner. Bonus if I can plot the residuals in a heat map with <code>ggplot2</code>, which is why I'm interested in incorporating the <code>broom</code> package into this example. </p>