# Correlation Matrix vs Contingency Table

**URL:** <https://discourse.julialang.org/t/correlation-matrix-vs-contingency-table/36522>\
**Category:** Statistics\
**Created:** [March 25, 2020, 9:45pm UTC](https://discourse.julialang.org/t/correlation-matrix-vs-contingency-table/36522 "2020-03-25T21:45:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [March 25, 2020, 9:45pm UTC](https://discourse.julialang.org/t/correlation-matrix-vs-contingency-table/36522/1 "2020-03-25T21:45:12Z")

</div>

Is there a difference between a correlation table and a contingency matrix?

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [March 25, 2020, 10:15pm UTC](https://discourse.julialang.org/t/correlation-matrix-vs-contingency-table/36522/2 "2020-03-25T22:15:15Z")

</div>

Consider a vector w/ two random variables X= [X1 X2]’  
Example:  
X1= 1 if Left-handed, X1=2 if Right-handed  
X2= 1 if Male, X2=2 if Female

1 A correlation matrix is a matrix w/ all correlations between the variables  
-It can be based on the population, or computed from a sample just like the mean…

2 Suppose we have a sample w/ say N=100 realizations of X.  
-For N=100 ppl, we have their X1 (Left/Right hand) & X2 (Sex)  
A [contingency table](https://en.wikipedia.org/wiki/Contingency_table) displays the frequency of observations

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/6/d6e4a12a1c2e8e78e17588e099c5442a8bcaede9.png)  
From this contingency table you can compute the:  
joint distribution/marginal distributions/Means/Covariance Matrix/Correlation matrix

3a This type of question is not really a Julia discourse question, bc it is not using Julia.  
Stack overflow & other forums are great for math & these types of questions.  
3b This question is about material one learns in a class on probability/statistics & can be answered w/ a google search

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [March 25, 2020, 10:21pm UTC](https://discourse.julialang.org/t/correlation-matrix-vs-contingency-table/36522/3 "2020-03-25T22:21:57Z")

</div>

OK, so it’s the same as a croll tab. I know how to do a cross tabulation in Julia.

---

<div class="post-metadata">

**Author:** ![Albert\_Zevelev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albert_zevelev/32/11844_2.png) [@Albert\_Zevelev](https://discourse.julialang.org/u/Albert_Zevelev)\
**Post date:** [March 25, 2020, 11:26pm UTC](https://discourse.julialang.org/t/correlation-matrix-vs-contingency-table/36522/4 "2020-03-25T23:26:34Z")

</div>

Check out this post:

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [March 26, 2020, 1:06am UTC](https://discourse.julialang.org/t/correlation-matrix-vs-contingency-table/36522/5 "2020-03-26T01:06:55Z")

</div>

Ok, I can go over that again. I usually post things like that in stack overflow, but with all going on, it’s hard to get to, and it’s a simple question. Also I thought I remembered how to do cross tabs in Julia, but now I can’t remember, and I’m not sure of a package that does it.
