I would like to create a matrix of marginal distributions from a matrix of joint distributions.
As a specific example, suppose
A=[0 0 a b; 0.1 0 c d; 0.1 0.1 e f; 0.2 0 g h; 0.2 0.1 i j;0.2 0.2 k l]
I want to create the following matrix B such that
- the first column of B collects unique elements of the entries in the first column and the second column of A (assume that entries in the first column of A are the same with entries in the second column of A). So the first column of B is
- the second column of B: for each entry of the first column of B, find rows of A where the first entry of A is equal to that entry of B, and then take averages of the third entries of A (marginal distribution) Thus it will be
B(:,2)=[a; (c+e)/2; (g+i+k)/3]
- the third column of B: for each entry of the second column of B, find row of A where the second entry of A is equal to that entry of B, and then take average of the fourth entries of A. Thus it will be
B(:,3)=[(b+d+h)/3; (f+j)/2; l]
Please advise the steps. Thank you.