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