# How to calculate the Anderson Darling Test ?

14 views (last 30 days)
Amr Hashem on 11 Nov 2015
Commented: Amr Hashem on 17 Nov 2015
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
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 on 11 Nov 2015
"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.
Walter Roberson on 13 Nov 2015
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 on 17 Nov 2015
Thanks