Question abut the Chi-square probability density function
2 次查看(过去 30 天)
显示 更早的评论
Hi there,
I have question regarding the arguments X and V in the Chi-square probability density function.
Say for example I have a column vector, D with 1000 distance values.
Is the degrees of freedom, V, calculated by 1000-1 = 999?
So would the function be
Y = chi2pdf(D,999)
I am trying to achieve a chart like this, where the red line is the Chi-square probability density function
Many thanks for your help
0 个评论
回答(3 个)
bym
2011-12-21
no, degrees of freedom would be 1000. You are not calculating another statistic with the data ('using up a DOF') before calling the chi2pdf function
Wayne King
2011-12-22
Hi John, the chi-square density is characterized by 1 parameter, the degrees of freedom. You do not want to say that because you have 1000 values, the chi-square density has dof=999. You can have a chi-square RV with 1000 values, and varying degrees of freedom.
For example:
To simulate some chi-square random vectors:
% 2 dof
R2 = chi2rnd(2,1000,1);
% 5 dof
R5 = chi2rnd(5,1000,1);
What you want to do is take your data and estimate the dof parameter based on your data.
One thing you can do is to use fitdist() with 'gamma'.
A chi-square density is a gamma density with a=v/2 and b=2 where v is the degrees of freedom.
R2 = chi2rnd(2,1000,1);
ksd = fitdist(R2,'gamma');
You should see that ksd.b is close to 2. to get an estimate of the dof characterizing the chi-square density you can do:
round(ksd.a*2)
Wayne King
2011-12-23
Hi John, No, v is the degrees of freedom. It is a scalar. You have estimated your degrees of freedom as 2.
By the way did you also check that ksd.b is close to 2? If ksd.b is not close to 2, then your data are better approximated perhaps by a more general gamma distribution. The chi-square density is a special case of a more general gamma family. Let's assume ksd.b is close to 2.
Then construct an 'x' vector that matches the range of your data
Let's assume that your distances run from 0 to 10. The fitted pdf is:
x = 0:.01:10;
y = chi2pdf(x,2);
plot(x,y);
If ksd.b is not close to 2, then use gampdf()
x = 0:0.01:10;
y = gampdf(x,ksd.a,ksd.b);
plot(x,y);
If you want to overlay the fitted distribution over the histogram:
I'll use R as my distance measures, substitute your data.
R = gamrnd(2,2,100,1);
binWidth = 2; %These aren't hard and fast
x0 = round(min(R));
xend = ceil(max(R));
binCtrs = 1:binWidth:19; %These aren't hard and fast
n=length(R);
counts = hist(R,binCtrs);
prob = counts / (n * binWidth);
h = bar(binCtrs,prob,'hist');
set(h,'FaceColor',[.9 .9 .9]);
x=x0:.01:xend; hold on;
ksd = fitdist(R,'gamma');
y = gampdf(x,ksd.a,ksd.b); %gamma pdf
plot(x,y,'k','linewidth',2);
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!