Using Matlab to determine if two random variables are independent


Independence is an important concept in probability theory. Matlab can be used to determine if two random variables are independent. Let's consider the two discrete random variables in a previous posting. That is, the random variables X and Y with joint probability mass function In the earlier posting, we computed the covariance. Since the covariance was nonzero, we can conclude that X and Y are dependent. But if a covariance turns out to be zero, we can't conclude that the random variables are independent. After all, independence implies zero covariance, but the converse is not true. You need to check if . Not only can Matlab's Symbolic Toolkit be used to determine the marginal probability mass functions of X and Y, but it can also be used to check if . As noted in the earlier posting, you can find the probability mass functions as follows:

>> syms x y k fx fy fxy;
>> fxy=(x+y)/32;
>> fx=symsum( fxy,  y,1,4);
>> fy=symsum( fxy, x,1,2);
>> fxy == fx*fy

ans =

     0
>> 

The equality operator is used to determine if the symbolic expressions fxy and fx*fy are equal. The zero value of fxy == fx*fy indicates that the expression is false. (You'll actually see the value 'false' in the workspace window, assuming you're using Matlab 7.x.) So X and Y are not independent. (They are dependent.) If the expression fxy == fx*fy has a value of 1 (i.e., true), then the random variables are independent.

It seems that these tricks could be packaged in Matlab function. Perhaps I'll write one when I get the chance. If I do, I'll post it on this weblog.


Posted: Sunday - December 04, 2005 at 11:57 AM        


©