I'm really rusty at statistics and I'm trying to write some C# code where I feed in a list of numbers and it tells me whether or not the numbers are normally distributed. I generated 50 numbers from the following site with a mean of 0 and a variance of 1.


The algorithm I'm trying to use is the Anderson-Darling test (http://en.wikipedia.org/wiki/Anderson%E2%80%93Darling_test). I implemented

 A^2 = -N - 1 / N * sum(1, N)( (2*i - 1) * (ln Phi(Y[i]) + ln (1-Phi(Y[n+1-i]) ) ) ) 

(It's about half-way down the page, the case where the mean and variance are both known.)

The Phi function comes from http://www.johndcook.com/csharp_phi.html

When I run the code I wrote on an actual normal distribution, I get a value of -3.05 back.

Is the next step to look this number up in a table of normal distribution critical values to get the associated probability? -3.05 maps to 0.0011. Does this mean that my data has a .11% chance of coming from a normal distribution (assuming my code is correct)

  • 1
    $\begingroup$ "I feed in a list of numbers and it tells me whether or not the numbers are normally distributed" -- no hypothesis test can tell you if data is normally distributed. It can sometimes tell you if it is reasonably clearly not, but failure to reject doesn't say the null is actually true - it almost certainly isn't (except in some very limited circumstances). ... why do you want to test normality? $\endgroup$
    – Glen_b
    Mar 25, 2014 at 22:21
  • $\begingroup$ I'm playing around with some financial analysis and I want to see if purchase amounts (the raw dollar amount) follows a normal distribution. My objective is to prune columns from a database out that do follow a normal distribution because I'm betting that these columns are "uninteresting" for my purposes. I'm exploring first and foremost. "Reasonably clearly not" is perfectly acceptable. $\endgroup$
    – mj_
    Mar 26, 2014 at 0:45
  • $\begingroup$ Why test goodness of fit for this, rather than look at say a QQ plot, or some other assessment of distributional shape? Your test will be responsive to sample size (very small deviations from normality is detected at large sample size, very large deviations are not detected at small sample size), but your question of interest seems to relate to an effect-size ("how non-normal is it"), instead. Hypothesis tests seem to answer the wrong question here. $\endgroup$
    – Glen_b
    Mar 26, 2014 at 1:04
  • $\begingroup$ I want a programmatic solution to this because I have hundreds of columns that range from tens of thousands to hundreds of thousands of rows. Is there another approach you would suggest? I'm open to everything. $\endgroup$
    – mj_
    Mar 26, 2014 at 1:51
  • $\begingroup$ If you're interested in particular kinds of deviation from normality, a form of test statistic, as a measure of discrepancy from normality might be a suitable way to do that. The simplest example is the Komogorov-Smirnov test statistic, which itself measures discrepancy from a normal cdf in a very direct way. Or if one considers, for example, the close relationship between a Shapiro-Wilk and a Shapiro Francia test, the correlation between values and their normal scores (or perhaps $1-r^2$ as a measure of deviation), that might be more suitable as a measure of effect-size than p-values are. $\endgroup$
    – Glen_b
    Mar 26, 2014 at 2:16

1 Answer 1


The next step is to compare your value to a critical value for the test-statistic. From the same Wikipedia page:

If $A^{*2}$ exceeds a given critical value, then the hypothesis of normality is rejected with some significance level.

Meaning, your null hypothesis is that the data are generated from a normal distribution, and an $A^{*2}$ exceeding the critical value implies non-normality at that level of significance. But, the $A^{*2}$ statistic for a normal distribution is not itself normally distributed, per this resource:

The Anderson-Darling test makes use of the specific distribution in calculating critical values. This has the advantage of allowing a more sensitive test and the disadvantage that critical values must be calculated for each distribution.

The same source points to books and papers for these critical values. Perhaps you might be able to find CDFs for each $A^2$ statistic, and implement the p-value.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.