Effacer les filtres
Effacer les filtres

Calculating the marginal distribution from the joint distribution table

6 vues (au cours des 30 derniers jours)
skyline
skyline le 5 Juin 2017
Commenté : Jan le 5 Juil 2017
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 commentaire
Jan
Jan le 5 Juil 2017
"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.

Connectez-vous pour commenter.

Réponses (1)

Star Strider
Star Strider le 5 Juin 2017
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

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by