Effacer les filtres
Effacer les filtres

How to fit multivariate pdf and cdf from data

19 vues (au cours des 30 derniers jours)
supernoob
supernoob le 30 Juin 2018
Commenté : Tim Fulcher le 24 Déc 2021
I have a set of simulated data from a Monte Carlo simulation which gives me a bivariate distribution. I can plot the results using histogram2, and I expect the results to be bivariate gaussian. How can I properly fit this 'empirical' data to get a normalized pdf and cdf which I can then integrate over to get some confidence intervals?

Réponse acceptée

Jeff Miller
Jeff Miller le 1 Juil 2018
You don't need a bivariate histogram to fit the bivariate normal--just use the sample means and covariance matrix. Here's an example:
% Let's say your data are in an n,2 matrix called xy.
% Here is one randomly generated to use in the example.
muXY = [100, 200];
sigmaXY = [15^2, 5^2; 5^2, 20^2];
xy = mvnrnd(muXY,sigmaXY,10000);
% Here is your bivariate histogram:
figure; histogram2(xy(:,1),xy(:,2));
% Now estimate the parameters of the best-fitting Gaussian:
xybar = mean(xy);
xycovar=cov(xy);
% Plot the best-fitting bivariate pdf:
xsteps = min(xy(:,1)):1:max(xy(:,1)); % Adjust with step sizes appropriate for your
ysteps = min(xy(:,2)):1:max(xy(:,2)); % x and y values.
[X,Y] = meshgrid(xsteps,ysteps);
F = mvnpdf([X(:) Y(:)],xybar,xycovar); % Note that xybar and xycovar are used here.
F = reshape(F,length(ysteps),length(xsteps));
figure; surf(xsteps,ysteps,F);
caxis([min(F(:))-.5*range(F(:)),max(F(:))]);
xlabel('x'); ylabel('y'); zlabel('Probability Density');
  2 commentaires
supernoob
supernoob le 2 Juil 2018
Modifié(e) : supernoob le 2 Juil 2018
Thanks, this is really helpful. Once I have the pdf I need to integrate in polar coordinates over a chosen area. Once I have that done, this problem is solved!
Tim Fulcher
Tim Fulcher le 24 Déc 2021
Many thanks for this Jeff. Very useful.

Connectez-vous pour commenter.

Plus de réponses (1)

dpb
dpb le 30 Juin 2018
Modifié(e) : dpb le 30 Juin 2018
They're in the BinCounts property of the object or you can just use the old histcounts2.
ADDENDUM
Ah, ok. I've not tried in Matlab, seems a definite lack of no prepared function indeed...
The Answer_108846 implies one can do it with MLE using the supplied functions for pdf/cdf.
Attach your data and I'll try to see if I can give it a go later on...btw, you'll probably get much better fit using the raw data than histogram bin counts.
  1 commentaire
supernoob
supernoob le 30 Juin 2018
Thanks. I realized this shortly after posting the question and deleted that part, sorry for the confusion. I still can't figure out how to fit these values to get a bivariate gaussian pdf. gmdistribution is not the correct choice.

Connectez-vous pour commenter.

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by