How to calculate the Anderson Darling Test ?

I want to test the goodness of fit of the model , so I use A-D test
I am using matlab 2012a
I got the function from an exchange file.
I try:
paramEsts = gevfit(data); %estimate parameter data 453*1 double
xgrid = linspace(-40,70,453);
pdfEst = gevcdf(xgrid,paramEsts(1),paramEsts(2),paramEsts(3));
xnew=[data pdfEst'] % 453*2 double
[AD]=AnDarksamtest(xnew,0.05);
but i got an Error:
There must have at least two samples.
and sometimes
one or more samples have no observations.
How I can solve this problem, and calculate the p-value of A-D test?

 채택된 답변

Walter Roberson
Walter Roberson 2015년 11월 11일

1 개 추천

"There must have at least two samples." would imply that your xnew does not have at least two rows in those cases.
For "one or more samples have no observations.": the second column of the input is expected to be the group number, which is expected to be a positive integer 1 through the number of groups. If there are any integers in the range 1 to floor(max(xnew(:,2)) which are not present in xnew(:,2) then you would receive this message.
The column 2 data that you are passing is the cdf you have calculated, which would seldom happen to be a positive integer. Neither of your columns appear to be grouping numbers.
Notice the description in the source comments:
% The Anderson-Darling k-sample test was introduced by Scholz and Stephens
% (1987) as a generalization of the two-sample Anderson-Darling test. It is
% a nonparametric statistical procedure, i.e., a rank test, and, thus,
% requires no assumptions other than that the samples are true independent
% random samples from their respective continuous populations (although
% provisions for tied observations are made). It tests the hypothesis that
% the populations from which two or more independent samples of data were
% drawn are identical.
This requires an input that tells it which population each sample is drawn from. The program uses column 2 of the data to hold that information.
Possibly you need a different test.

댓글 수: 6

Amr Hashem
Amr Hashem 2015년 11월 11일
편집: Amr Hashem 2015년 11월 11일
but my xnew has 2 columns
xnew=[data pdfEst'] % 453*2 double
1st column is data
2nd column is CDF of Generalized extreme value of the data
Amr Hashem
Amr Hashem 2015년 11월 11일
I use K-S test and it was a good goodness of fit test.
could be my data follow K-S test and didn't follow A-D test?
What are your first (say) 5 pdfEst values? Are they positive integers that are in the range 1 to the number of populations that you have?
For the purpose of the AnDarksamtest routine that you are calling, if you want all of the items to be in the same population, then your second column should be all 1's.
Maybe what you want is
r = size(data,1);
xnew = [data, 1 * ones(r,1);
pdfEst', 2 * ones(r,1)];
this would take the data as one population and the pdf estimates as a second population.
it works, but I got a result:;
probability associated to A-D rank statistic = 0.00000000
the samples were drawn from different populations: data may be considered
Walter Roberson
Walter Roberson 2015년 11월 13일
Looking back over the way you set up the problem, I see that the difficulty is that you want the original Anderson Darling Test, but that the routine you are calling upon is the Anderson Darling K-sample Test. The original Anderson Darling test has been supported in MATLAB since R2013a
There are Anderson Darling tests in the File Exchange, but unfortunately they are limited to Normal distributon, Weibel distribution, or Exponential distribution.
Sorry, I think you are either going to need to upgrade to at least R2013a, or else find the appropriate code somewhere outside of Mathwork's site. (I just checked, the Octave version does not support Extreme Value.)
Amr Hashem
Amr Hashem 2015년 11월 17일
Thanks

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

추가 답변 (0개)

질문:

2015년 11월 11일

댓글:

2015년 11월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by