필터 지우기
필터 지우기

How to fit multivariate pdf and cdf from data

조회 수: 19 (최근 30일)
supernoob
supernoob 2018년 6월 30일
댓글: Tim Fulcher 2021년 12월 24일
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!
Tim Fulcher
Tim Fulcher 2021년 12월 24일
Many thanks for this Jeff. Very useful.

댓글을 달려면 로그인하십시오.

추가 답변 (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