How to Conduct an Anderson-Darling Test in R

Spread the love

The Anderson-Darling (AD) test is a statistical procedure used to test if a sample of data comes from a specific distribution. It is an alternative to the more common Kolmogorov-Smirnov (K-S) test and provides better sensitivity to departures from the hypothesized distribution at the tails. This test is often applied to check the normality assumption in many statistical models.

This article will provide an in-depth guide on how to perform the Anderson-Darling test in R, starting with an overview of the test’s theoretical underpinnings, and then providing detailed step-by-step instructions to perform the test in R.

Theoretical Overview of the Anderson-Darling Test

The Anderson-Darling test is a type of goodness-of-fit test, and its null hypothesis is that the sample data are drawn from a specific distribution. It achieves its sensitivity to the tails of the distribution by placing more weight on the observations in the tails as compared to the K-S test.

The test statistic A^2 is defined as follows:

A^2 = -n – S

where n is the sample size, and S is calculated as follows:

S = 1/n * Σ_{i=1}^{n} (2i – 1)[ln(x_i) + ln(1 – x_{n+1-i})]

Here, x_i is the ith smallest of the n ordered data points. For large sample sizes and continuous distributions, the test statistic A^2 approximately follows a chi-square distribution, which allows for hypothesis testing.

Performing the Anderson-Darling Test in R

The Anderson-Darling test is available in R through the “nortest” package. In this section, we’ll discuss how to perform this test in R.

Step-by-Step Guide

Step 1: Install and Load the Necessary Package

The “nortest” package is not a part of the base R functions, and thus, you need to install it first using the install.packages function:


Once installed, you can load the package into your workspace using the library function.


Step 2: Load Your Data

Next, you need to load your data into R. For this guide, we will use the built-in mtcars dataset:

data <- mtcars$mpg

Step 3: Perform the Anderson-Darling Test

To perform the Anderson-Darling test, you can use the ad.test function from the “nortest” package:

ad_test <- ad.test(data)

Step 4: View the Test Results

To view the results of the test, simply print the test object:


The output will include the Anderson-Darling test statistic A^2 and the corresponding p-value.

Step 5: Interpret the Test Results

The interpretation of the Anderson-Darling test follows the usual logic of hypothesis testing. If the p-value is less than your chosen significance level (typically 0.05), you reject the null hypothesis and conclude that your data do not come from the specified distribution. If the p-value is greater than your chosen significance level, you do not reject the null hypothesis and the data could be from the specified distribution.

Additional Considerations

While the Anderson-Darling test is a robust tool for assessing whether data come from a specific distribution, it’s important to keep a few things in mind:

  1. Like other goodness-of-fit tests, the Anderson-Darling test is sensitive to large sample sizes. Even minor deviations from the hypothesized distribution can lead to the rejection of the null hypothesis when your sample size is large.
  2. The test only checks the null hypothesis of whether the data could come from the specified distribution. It doesn’t tell you what distribution the data come from if the null hypothesis is rejected.
  3. As with any statistical test, the results should be interpreted in the context of your data and the research question you are trying to answer. You should consider other elements of exploratory data analysis, such as visualizing your data, to fully understand your data’s distribution.


The Anderson-Darling test provides a powerful method for testing whether a sample of data comes from a specific distribution. It offers increased sensitivity to the tails of the distribution, which can be particularly useful when you are concerned about outlier values.

By understanding the theoretical background of the Anderson-Darling test and how to conduct the test in R, you can make more informed decisions about your data and the appropriate statistical methods to use. As always, it’s important to interpret the results in the context of your research question and the nature of your data.

Posted in RTagged

Leave a Reply