Filter löschen
Filter löschen

How to fit multivariate pdf and cdf from data

19 Ansichten (letzte 30 Tage)
supernoob
supernoob am 30 Jun. 2018
Kommentiert: Tim Fulcher am 24 Dez. 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?

Akzeptierte Antwort

Jeff Miller
Jeff Miller am 1 Jul. 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 Kommentare
supernoob
supernoob am 2 Jul. 2018
Bearbeitet: supernoob am 2 Jul. 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 am 24 Dez. 2021
Many thanks for this Jeff. Very useful.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

dpb
dpb am 30 Jun. 2018
Bearbeitet: dpb am 30 Jun. 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 Kommentar
supernoob
supernoob am 30 Jun. 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.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by