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.


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

xx = 0.2:0.2:34;
x = sin(xx);
y = randn(size(xx));
  • 1
    $\begingroup$ 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. $\endgroup$
    – rolando2
    Mar 10, 2012 at 19:37
  • $\begingroup$ @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. $\endgroup$
    – Rachel
    Mar 10, 2012 at 20:49
  • $\begingroup$ Fun fact: "Chi" squared looks like this: $X^2$. $\endgroup$
    – user88
    Mar 11, 2012 at 10:01
  • $\begingroup$ @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? $\endgroup$ Mar 11, 2012 at 13:37
  • $\begingroup$ @gung Chi=$X$, chi=$\chi$. $\endgroup$
    – user88
    Mar 11, 2012 at 14:03

1 Answer 1


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.

On the other hand, what the histograms are doing depends on how the bins are generated, and how well those bins capture the underlying continuous variable. Since you have the underlying continuous variable, why use a more or less bad approximation to it? If you wanted to know how to do this out of purely academic curiosity, you would dice up your continuous variable into bins somehow (perhaps based on theory, perhaps using the automatic binning algorithm in your software, or whatever) for each variable individually, ignoring the other variable. Then you would cross-tabulate your data by counting the number of cases that fell into each 2D bin. As a rule of thumb, you want at least 5 cases in each combination, although it's actually more complicated than that. Then you would simply run a standard chi-squared test for independence. For the record, I don't see any value in pursuing this course.

  • $\begingroup$ You ought to read over the precedinq question so you have a better sense of what the OP means by "signal": stats.stackexchange.com/questions/24214. It's not quite the same thing as a random variable. $\endgroup$
    – whuber
    Mar 12, 2012 at 17:32
  • $\begingroup$ Thank you @whuber for pointing that out. I have updated my question for the sake of clarification. $\endgroup$
    – Rachel
    Mar 12, 2012 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.