How to fit multivariate pdf and cdf from data

21 次查看(过去 30 天)
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?

采纳的回答

Jeff Miller
Jeff Miller 2018-7-1
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 个评论
supernoob
supernoob 2018-7-2
编辑:supernoob 2018-7-2
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!

请先登录,再进行评论。

更多回答(1 个)

dpb
dpb 2018-6-30
编辑:dpb 2018-6-30
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 个评论
supernoob
supernoob 2018-6-30
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.

请先登录,再进行评论。

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by