Using MATLAB's Symbolic Toolkit to explore Joint and Marginal Probability Mass Functions


One of the examples we used in the STA 341 Statistical Theory I course to illustrate joint probability mass functions and marginal probability mass functions was the following:

Let X and Y be two random variables with joint probability mass function
Find the marginal probability mass functions


and
,

the means

and
,
the variances,

and
,
the covariance , and the correlation coefficient .

All of these quantities can be computed quite easily by the paper and pencil approach. Matlab's Symbolic Toolkit can also be used in this exercise (mostly to illustrate how to use the Matlab Symbolic Toolkit). Students should not need to use Matlab to compute anything here. Computing for example, is quite easy:



Factor out the 1/32. Then add 4 copies of x to get 4x, and consecutive positive integers starting with 1 and ending with 4 (you can use 1 + 2 + ... + n = n(n+1)/2)) to get 10. So


.


At any rate, here's how to do the computations using Matlab with its Symbolic Toolkit:


>> syms x y k
>> fx=symsum( (x+y)/32, y,1,4)
 
fx =
 
1/8*x+5/16
 
 
>> fy=symsum( (x+y)/32, x,1,2)
 
fy =
 
3/32+1/16*y
 
>> mux=symsum(x*fx,x,1,2)
 
mux =
 
25/16
 
 
>> muy=symsum(y*fy,y,1,4)
 
muy =
 
45/16
 
 
>> Varx=symsum(x^2*fx,x,1,2)-mux^2
 
Varx =
 
63/256

>> Vary=symsum(y^2*fy,y,1,4)-muy^2
 
Varx =
 
295/256

>> covxy=symsum(symsum( x*y*(x+y)/32, y,1,4),x,1,2) - mux*muy
 
covxy =
 
-5/256

>> rho=covxy/sqrt(Varx*Vary)
 
rho =
 
-1/1239*2065^(1/2)
 
 
>> eval(rho)

ans =

   -0.0367

Pretty cool, huh!


Posted: Wednesday - November 23, 2005 at 08:42 AM        


©