Normality Test
Tests a sample for normality using the Shapiro–Wilk, Kolmogorov–Smirnov (including the Lilliefors correction), and Anderson–Darling tests, plus a histogram and Q–Q plot.
This online calculator checks whether a sample is consistent with a normal distribution. It calculates the Shapiro–Wilk, Kolmogorov–Smirnov (including the Lilliefors correction), and Anderson–Darling tests, and also draws a histogram with a normal curve and a normal Q–Q plot.
You can find the formulas and some theory below the calculator.
What Exactly Is Being Tested
The normal distribution (normal law, Gaussian distribution) is a continuous distribution with the density
where is the mean,
is the standard deviation, and
. Its graph is a symmetric bell curve centered at
. A separate calculator for the normal distribution density and cumulative distribution function is available here: Normal distribution.
Suppose we weigh the same calibration weight twenty times. The scale readings vary slightly: 999.8 g, 1000.1 g, 1000.0 g, and so on. We may assume that the scale's random error is normally distributed. But twenty numbers cannot show us the distribution itself — they can only show how strongly the observations contradict it.
We therefore formulate the null hypothesis : the sample comes from a normal distribution. The alternative hypothesis
states the opposite. For the classical Kolmogorov–Smirnov test with specified parameters, the hypothesis is narrower: it tests the particular distribution
, rather than just any normal distribution.
Each test produces a statistic and a p-value. In other words, the p-value is the probability, assuming is true, of obtaining a departure from normality as strong as or stronger than the one observed in our sample. It is not the probability that the normality hypothesis is true.
But how do we get a probability from a single number — the test statistic? We need to know the statistic's null distribution, that is, the distribution of values it would have if were true. Imagine repeatedly drawing new samples of the same size
from a normal distribution and recalculating the statistic each time. We then find the proportion of these values that contradict normality at least as strongly as the value from our sample. That proportion is the p-value.
The direction of the inequality depends on the test: small values are suspicious for Shapiro–Wilk, whereas large
and
values are suspicious for Kolmogorov–Smirnov and Anderson–Darling. We therefore cannot simply take the area under an ordinary normal curve to the right of every statistic. Each statistic has its own null distribution, which depends on
; for Kolmogorov–Smirnov, it also depends on whether the parameters were estimated from the sample. In practice, the calculator does not simulate thousands of samples: it uses exact formulas where available and published approximations to the null distributions where exact calculation is too difficult. The method used to obtain the p-value is described below for each test.
The p-value is then compared with the chosen significance level :
- If
, the normality hypothesis is rejected. Under the chosen conditions, the discrepancy is too large to be considered a plausible random fluctuation.
- If
, the normality hypothesis is not rejected. But neither is it proved: a departure may exist, and the sample may simply be too small to detect it.
What does this mean in practice? If and
, normality is rejected. If
, this does not mean a 91% probability of normality. It only means that discrepancies like this one, or more pronounced ones, occur quite often when the null hypothesis is true.
Sample Mean and Two Standard Deviations
For a sample , the calculator computes the sample mean
and the corrected sample standard deviation
where is the sample size. The divisor
is used in the Lilliefors and Anderson–Darling tests.
To draw the normal curve over the histogram, the calculator uses the maximum likelihood estimate of :
Thus and
differ in their divisors:
and
. The calculator displays both values. For large
, the difference almost disappears, but for small samples it is better not to sweep it under the rug.
Shapiro–Wilk Test
The Shapiro–Wilk test is designed specifically to test normality. First, the sample values are ordered: . Then the following statistic is calculated1
where are the ordered sample values,
is the sample mean, and
are coefficients that depend on the sample size and are derived from the properties of order statistics of a normal distribution.
The numerator compares the ordered sample with the pattern expected for normal data, while the denominator measures its overall spread. Values of lie between zero and one; small
values indicate a departure from normality. However, the decision is not based on an arbitrary threshold such as "
means normal"; it is based on the p-value.
Because departures from normality correspond to small values, the p-value here is the left tail of the null distribution:
where is the value calculated for our sample. For example,
means that if
is true, only 1% of samples of the same size will produce a
value this small or smaller.
The calculator applies this test when . The exact null distribution of
is very cumbersome, so Royston's approximation is used:
is transformed using a logarithm and coefficients that depend on
onto a normal scale, which is then used to calculate the left-tail probability.2 For
, the test row shows a dash, while the other checks continue to run.
Kolmogorov–Smirnov Test and the Lilliefors Correction
The empirical distribution function is the proportion of observations not exceeding :
where equals one if the condition is true and zero otherwise, and
is the sample size.
The Kolmogorov–Smirnov test (KS) compares the empirical function with the theoretical normal distribution function
:
Here is the largest vertical distance between the two distribution functions, and
means that the maximum is taken over all possible
. The larger
is, the greater the discrepancy.
And here is an important nuance. Where do the mean and standard deviation for come from?
- The parameters are known in advance. The specified
and
are used, giving the classical Kolmogorov–Smirnov test. For example, the technical specification for an instrument may require an error with mean 0 and standard deviation 0.1 g. We are testing this particular model, not fitting it to fresh measurements. For
, the calculator uses an exact p-value; for larger samples, it uses numerical approximations.
- The parameters are estimated from the same sample. Instead of
and
, we substitute
and
. In this case, the Lilliefors test applies. The statistic
looks the same, but its distribution under the null hypothesis is different, and so is the p-value.3 The ordinary Kolmogorov–Smirnov p-value must not be used after fitting parameters; that calculation would be too lenient with the data.
For both versions of the test, large values are suspicious, so the right tail of the null distribution is used:
where is the observed maximum discrepancy between the distribution functions. But the null distributions are different. In the classical test, the parameters
and
are fixed. In the Lilliefors test, the parameters are estimated anew for each hypothetical normal sample, and the distance
is usually smaller because the curve is fitted specifically to that sample. The same numerical value of
can therefore produce different p-values in the two modes.
In other words, the Lilliefors correction does not adjust the number itself; it corrects the way a decision is obtained from that number. In the calculator, the Lilliefors test is calculated for
, and its right tail and p-value are found using analytical approximations.
Anderson–Darling Test
The Anderson–Darling test also compares a sample with a theoretical distribution, but gives more weight to its tails. For a normal distribution with the mean and standard deviation estimated from the sample, the statistic is
where are the ordered sample values,
is the normal distribution function with parameters
and
, and
is the sample size.
Before calculating the p-value, the statistic is corrected for sample size:
The calculator displays the original in the table but obtains the p-value from the corrected statistic. Large
values speak against normality, so the right tail is needed again:
The null distribution of is not normal. Stephens' piecewise approximation is used for it: depending on the interval containing
, one of five formulas approximates the required probability.4 The test is calculated for
.
Histogram with a Normal Curve
A histogram shows how observations are distributed across intervals. The calculator plots it in density units: the height of each bar is
where is the number of observations in the interval,
is the sample size, and
is the interval width. The area of each bar therefore equals the proportion of observations in it, and the total area of the histogram equals one. This allows the density of the normal distribution
to be superimposed — both quantities use the same scale.
Here is an example. If 4 out of 20 measurements fall into an interval 0.4 g wide, the bar height is . Its area is
, so the interval contains 20% of the sample.
The interval width is selected automatically using the Freedman–Diaconis rule:
where is the interquartile range, and
and
are the first and third sample quartiles. If this width cannot be obtained, for example when the interquartile range is zero, the number of intervals is chosen as
.5
What should you look for? Noticeable asymmetry, several separate peaks, large gaps, and outliers. But do not demand a perfect bell: a small sample from a strictly normal distribution can produce a rather crooked histogram. Randomness is entitled to a few irregularities.
Normal Q–Q Plot
A Q–Q plot (quantile–quantile plot) compares sample quantiles with the quantiles of a theoretical distribution. For a normal Q–Q plot, the calculator plots the points
where is the inverse standard normal distribution function and
is the ordered sample. The probabilities
are called plotting positions: they specify which theoretical quantile should be paired with the
-th smallest observation.
This formula is the rule proposed by Swedish statistician Gunnar Blom.6 Why the strange numbers 0.375 and 0.25? The simplest choice, , would give
for the last observation, and the corresponding normal quantile
would be infinite — a point like that cannot be plotted. Blom's positions stay away from zero and one, are symmetric about
, and closely approximate the expected positions of order statistics from a normal sample.
For example, with , we get
,
,
, and
. Thus the minimum is paired with approximately the 14.7th percentile and the maximum with the 85.3rd percentile, rather than an infinite point at the end of the distribution.
The reference line passes through the corresponding first and third quartiles of the theoretical and sample quantiles. This choice is more robust to outliers than a line based only on the mean and standard deviation.
How to read the plot:
- Points close to the line — no serious visual contradictions to normality. Exact agreement is not required, of course.
- A smooth bend — the distribution may be asymmetric.
- An S-shaped departure — the sample tails differ from normal tails: they are heavier or lighter.
- Individual points far from the overall pattern — possible outliers.
- Steps — the data contain many repeated values or the quantity is inherently discrete.
The Q–Q plot is especially useful where a histogram depends on the choice of intervals. It does not replace the tests, but it helps explain how exactly the data differ from normal data.
Calculation Example
Let us keep the calculator's 20 default values — hypothetical measurements of a quantity close to 5. Select and the mode that estimates parameters from the sample. The results are as follows:
| Test | Statistic | p-value | Decision |
|---|---|---|---|
| Shapiro–Wilk | 0.911875 | Normality is not rejected | |
| Lilliefors | 0.840087 | Normality is not rejected | |
| Anderson–Darling | 0.819790 | Normality is not rejected |
All p-values are well above 0.05. These data therefore provide no grounds to reject normality. That is not the same as saying that the numbers are known to be normal. The default values can be deleted; they are for illustration only.
What if one test rejects normality and the other two do not? This is no reason to hold a two-to-one vote. Tests differ in their sensitivity to skewness, tails, and other departures, and they have different sample-size restrictions. Look at the Q–Q plot, the histogram, and the nature of the data. The calculator's summary only reports whether at least one applicable test rejects normality; it is a summary of results, not a fourth test with its own p-value.
Applicability Conditions
- Observations must be independent. If each measurement depends on the previous one, ordinary p-values may be misleading. For time series, their structure must be taken into account first.
- Sample size matters. With small
, a test may miss a real departure from normality. With very large
, it may reject normality because of a departure that is practically insignificant for your task. Consider p-values together with the plots and common sense.
- The tests have numerical limits. In this calculator, Shapiro–Wilk applies for
, Lilliefors for
, and Anderson–Darling for
. Classical Kolmogorov–Smirnov requires
and
to be specified in advance. Some p-values are calculated using approximations, as stated in the notes in the results table.
- Identical values are not suitable. If the entire sample consists of one repeated number, the standard deviation is zero and no fitted normal distribution exists. The calculator reports an error in this case.
- Do not delete outliers merely to obtain an attractive p-value. First check whether an outlier is a measurement or data-entry error. If the observation is genuine, deleting it changes the original problem.
- Rejecting normality is not the end of the analysis. A data transformation, a different distribution model, or nonparametric methods may help. For estimating a mean with a large sample, the central limit theorem often helps. Its connection with confidence intervals is discussed in Constructing confidence intervals.
-
NIST/SEMATECH. e-Handbook of Statistical Methods. Section “Anderson-Darling and Shapiro-Wilk tests”. NIST ↩
-
Royston P. Remark AS R94: A Remark on Algorithm AS 181: The W-test for Normality. Applied Statistics, 1995, vol. 44, pp. 547–551. DOI ↩
-
Dallal G. E., Wilkinson L. An Analytic Approximation to the Distribution of Lilliefors’ Test Statistic for Normality. The American Statistician, 1986, vol. 40, pp. 294–296. DOI ↩
-
Stephens M. A. EDF Statistics for Goodness of Fit and Some Comparisons. Journal of the American Statistical Association, 1974, vol. 69, pp. 730–737. DOI ↩
-
Freedman D., Diaconis P. On the Histogram as a Density Estimator:
Theory. Zeitschrift für Wahrscheinlichkeitstheorie und Verwandte Gebiete, 1981, vol. 57, pp. 453–476. DOI ↩
-
Blom G. Statistical Estimates and Transformed Beta-Variables. New York: John Wiley & Sons, 1958. ↩
Comments