Statistics::Normality - test whether an empirical distribution can be taken as being drawn from a normally-distributed population
use Statistics::Normality ':all'; use Statistics::Normality 'shapiro_wilk_test'; use Statistics::Normality 'dagostino_k_square_test';
Various situations call for testing whether an empirical sample can be presumed to have been drawn from a normally (Gaussian) distributed population, especially because many downstream significance tests depend upon the assumption of normality. This package implements some of the more well-known tests from the mathematical statistics literature, though there are also others that are not included. The tests here are all so-called omnibus tests that find departures from normality on the basis of skewness and/or kurtosis [Dagostino71]. Note that, although the Kolmogorov-Smirnov test can also be used in this capacity, it is a distance test and therefore not advisable [Dagostino71]. This, and other distance tests (e.g. Chi-square) are not implemented here.
The subtleties and esoterica of various statistical tests for normality require some familiarity with the mathematical statistics literature. We give rules-of-thumb for specific tests, where they exist, but it may be advisable to try several different tests to check the consistency of the conclusion. It is probably also a good idea to check results graphically, either by direct plotting or by a Q-Q plot. In general, small samples will often pass a normality test suggesting the possibility that there is insufficient information to detect departure from normal for such cases, should it exist.
Each of the methods here is a frequentist test, i.e. one that tests against the null-hypothesis that the sample is normal. In other words, a low p-value recommends rejecting the null.
A list of functions that can be exported. You can delete this section if you don't export anything, such as for a purely object-oriented module.
The Shapiro-Wilk W-Statistic test [Shapiro65] is considered to be among the most objective tests of normality [Royston92] and also one of the most powerful ones for detecting non-normality [Chen71]. Its statistic is essentially the roughly best unbiased estimator of population standard deviation to the sample variance [Dagostino71]. The test is mathematically complex and most implementations use several conventional approximations (as we do here), including Blom's formula for the expected value of the order statistics [Harter61] and transformation to standard normal distribution for evaluation, especially for large samples [Royston92].
$pval = shapiro_wilk_test ([0.34, -0.2, 0.8, ...]); ($pval, $w_statistic) = shapiro_wilk_test ([0.34, -0.2, 0.8, ...]);
This test may not be the best if there are many repeated values in the test distribution or when the number of points in the test distribution is very large, e.g. more than 5000. The routine will carp about the latter, but not the former. This particular implementation of the test also requires at least 6 data points in the sample distribution and will croak otherwise.
$pval = dagostino_k_square_test ([0.34, -0.2, ...]); ($pval, $ksq_statistic) = dagostino_k_square_test ([0.34, -0.2, ...]);
The test statistic depends upon both the sample kurtosis and skewness, as well as the moments of these parameters from a normal population, as quantified by Pearson's coefficients [Pearson31]. These are transformed [Dagostino70,Anscombe83] to expressions that sum to the K-squared statistic, which is essentially chi-square-distributed with 2 degrees of freedom [Dagostino90]. The kurtosis transform, and thus the overall test, generally works best when the sample distribution has at least 20 data points [Anscombe83] and the routine will carp otherwise.
<mwendl at genome.wustl.edu>
Please report any bugs or feature requests to
bug-statistics-normality at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Statistics-Normality. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
You can also look for information at:
Copyright (C) 2011 Washington University
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.