inputs for pdf and mvnpdf
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Yu Jiang
am 11 Aug. 2014
Bearbeitet: Yu Jiang
am 12 Aug. 2014
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 Kommentare
John D'Errico
am 12 Aug. 2014
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.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!