inputs for pdf and mvnpdf

조회 수: 8 (최근 30일)
David
David 2014년 8월 9일
편집: Yu Jiang 2014년 8월 12일
To create a normal distribution, I used the pdf function that requires a standard deviation. To do this in 2D, I use mvnpdf where the input is stated to be the covariance matrix. However, when I create the 2D distribution and plot the midline, I do not get the same normal distribution (different sigma) that I do for the 2D case. I don't see what I'm doing wrong. I obviously want to generate a 2D pdf with the correct STD. Any help is appreciated
if true
sig0 = .75 % input STD
sigSQ = sig0^2; % variance
x1 = -3:.1:3; x2 = -3:.1:3; dx = .1;
SP3 = pdf('normal',x1,0,sig0); % 1D distribution
[X1,X2] = meshgrid(x1,x2);
mu = [0 0];
Sigma = [sigSQ 0; 0 sigSQ];
F = mvnpdf([X1(:) X2(:)],mu,Sigma);
F = reshape(F,length(x2),length(x1));
y2=F(31,:); % centerline of 2D created
[sig3,mu2]=gaussfit(x2,y2); % sigma created
end

답변 (1개)

Yu Jiang
Yu Jiang 2014년 8월 11일
편집: Yu Jiang 2014년 8월 12일
Hi David
From what I understand, you are trying to recreate the probability density function fy(y) from the joint distribution probability function f(x,y) and want to compare its standard deviation sig3 with sig0.
According to probability theory, the way to obtain the probability denitrify function fy(y) from the joint distribution probability density function f(x,y) is to integrate f(x,y) with respect to x from –inf to inf.
However, the midline F(31,:) gives you the output of the function f(0,y) which is not related to a density function.
To recreate the 1-D distribution, please use the pair (x2, sum(F,2)) instead of (x2, F(31,:)). That is to say, the line
y2 = F(31,:)
should be replaced with
y2 = sum(F,2)/10;
Notice that this is a quadrature approximation of the integral, as pointed out by John D'Errico in his comment below. But it should be enough for you to test if the way you use the function mvnpdf is correct or not. Also, even without being divided by the factor 10, y2 could still be used to give the same answer since the function gaussfit takes care of the normalization. (Assuming gaussfit is the one you found in FileExchange via the link http://www.mathworks.com/matlabcentral/fileexchange/35122-gaussian-fit )
I have tested the revised code, and found that sig3 = sig0, which seems to be what you expected.
-Yu
  댓글 수: 4
John D'Errico
John D'Errico 2014년 8월 12일
Note that the use of sum here is NOT an integration, but only an approximation, and not completely correct as it is here. Using sum creates a rectangle rule, but even so, you need to multiply by the spacing in x to turn a sum into an integration. Since dx was 0.1, there should be a factor of 10 wrong in the "integration" estimate.
Yu Jiang
Yu Jiang 2014년 8월 12일
편집: Yu Jiang 2014년 8월 12일
Hi John
Thanks for your comments. I have updated my answer accordingly.
-Yu

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

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by