How do I get marginal probability over a multidimensional array of discrete random variables?

1 view (last 30 days)
Say I have a 3x3 array which represents a joint probability distribution, P(X1, X2), over discrete random variables.
% I'm calling P(X1, X2) 'dist'in matlab
dist = [15/45, 12/45, 1/45; 12/45, 4/45, 0; 1/45,0 ,0] % X1 is the top, X2 is the side
As an example, the probability P(1,3) is the probability that under the distribution X1=1, and X2=3. Now, to find the marginal probability of P(X1 = 1), you simply sum down the column to get it.
P(X1 = 1) = 15/45 + 12/45 + 1/45 = 28/45
Easy enough. And if I want to find the marginal distribution vector for X1, I can use matlab's sum(dist).
My problem is, I have a 4-D double array representing a joint distribution over discrete random variables -- P(X1,X2,X3,X4). How do I find the marginal distribution vector of say P(X1)? I know it's a similar process as the bi-variate example, but is there a simple way to do this in matlab without having to write a whole bunch of for loops?

Answers (0)

Categories

Find more on Random Number Generation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!