Calculating the marginal distribution from the joint distribution table
4 次查看(过去 30 天)
显示 更早的评论
I would like to write down a function that generates the marginal distribution table from the joint distribution table.
Specifically, suppose I have a table
A =
[0.1 0 0.1; 0.1 0.1 0.1; 0.2 0 0.2; 0.2 0.1 0.2; 0.2 0.2 0.2]
where the first column is denoted x and the second column is denoted y
Then I would like to create a marginal distribution table where
- the first column is the distinct values of the first column of A (that is, the distinct values of x)
- the second column is the marginal distribution of x.
For example, the first (1,2)th element is the average of the entry of the third column of A where the first column is 0.1 (i,e. the marginal distribution for 0.1)
Please advise.
1 个评论
Jan
2017-7-5
"Please advice" : The most important advice is that you should stop to remove the text of your questions, after they have been answered. This is disliked here and counterproductive. The answers are posted to let the community profit from the solution. Editing the question away converts the thread to confusing junk.
Please, skyline, stop this deleting.
回答(1 个)
Star Strider
2017-6-5
I’m not quite certain what you want.
See if this works:
A = [0.1 0 0.1; 0.1 0.1 0.1; 0.2 0 0.2; 0.2 0.1 0.2; 0.2 0.2 0.2];
[Au,~,ic] = unique(A(:,1));
Result = accumarray(ic, A(:,3), [], @mean);
Output = [Au, Result]
Output =
0.1 0.1
0.2 0.2
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!