# How can I perform a chi-square test for independence on signal samples?

Let's say I have two signals $x$ and $y$, sampled $N$ times, i.e.

$$x = [ x_{1}, x_{2}, ..., x_{N} ]$$ $$y = [ y_{1}, y_{2}, ..., y_{N} ]$$

I would like to check whether $x$ and $y$ are statistically independent, with a certain level of probability.

I have been looking into the Chi-Square Test For Independence. However, since it can be applied to categorical data, I do not know how I can apply it to my signal samples.

As was suggested on this related question, once we compute the histogram for each signal, we do have categories on which a chi-squared test can be applied. But how do we use the histograms to generate the required contingency table?

For what it's worth, I am currently computing the histograms using this code:

n1 = hist(x);
n2 = hist(y);
n3 = hist3([x' y']);


Thank you for your help and suggestions.

EDIT

As an example, two signal samples would be the following:

xx = 0.2:0.2:34;
x = sin(xx);
y = randn(size(xx));

• It sounds as if the signals are measured on an interval or ratio level. If that's the case there's no benefit to converting to a categorical level in order to conduct a Chi-Square test. You can assess independence by creating a scatterplot and/or using Pearson correlation. Mar 10, 2012 at 19:37
• @rolando2 But If you were to conduct a Chi-Square test, how would you do it? I was thinking of maybe using the 2D-histogram of their joint distribution as the contingency table, but didn't know whether it made sense.. With regards to using a scatter plot, how would that work? Also, with regards to using correlation, it can easily be done but is not what I want. Although independence implies correlation, the converse is not true. Two signals can easily be uncorrelated but dependent. Mar 10, 2012 at 20:49
• Fun fact: "Chi" squared looks like this: $X^2$.
– user88
Mar 11, 2012 at 10:01
• @mbq, shouldn't it look more like this: $\chi^2$? BTW, is this a subtle hint that you want me to switch my use of the words to mathjax? Mar 11, 2012 at 13:37
• @gung Chi=$X$, chi=$\chi$.
– user88
Mar 11, 2012 at 14:03

I agree with @rolando2, if your data are continuous, a chi-square test is not really best. I would make a scatterplot and overlay a loess line on it. I don't really know MATLAB, but googling led me to these two pages. I can tell you that in R, the code would be plot(x,y); lines(lowess(y~x)). Although it's true that variables can be dependent while being uncorrelated, you should be able to assess this via your scatterplot. That is because correlation (specifically, Pearson's product-moment correlation) is a measure of linear dependence, so for example, a perfect parabola could be uncorrelated despite being dependent, or a sine wave that ran perfectly horizontally. My point is that you would be able to recognize that the correlation statistic was failing to capture the dependence by looking at your scatterplot. The smoothed fit would make this even easier to see.