| Title: | Tests for Departure from Normality |
| Version: | 0.0.3 |
| Description: | A toolkit for assessing data normality using a comprehensive collection of statistical methods. It includes descriptive measures and formal hypothesis tests, such as skewness and kurtosis tests, the Anderson–Darling test, the Shapiro–Wilk test, and the D'Agostino–Pearson K2 omnibus test. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/P10911004-NPUST/normality |
| BugReports: | https://github.com/P10911004-NPUST/normality/issues |
| Encoding: | UTF-8 |
| Depends: | R (≥ 3.5) |
| LazyData: | true |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.0.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-07-07 09:25:47 UTC; ABRC |
| Author: | Joon-Keat Lai |
| Maintainer: | Joon-Keat Lai <p10911004@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-07-07 09:40:02 UTC |
Anderson-Darling Normality Test
Description
Performs the Anderson–Darling (A2) normality test, an EDF-based goodness-of-fit test that gives greater weight to deviations in the tails of the distribution.
Usage
Anderson_Darling_test(
x,
alpha = 0.05,
silent = FALSE,
summary = TRUE,
misc = FALSE
)
Arguments
x |
A numeric vector, at least length of 8. |
alpha |
Numeric (default: 0.05). Significance threshold, range from 0 to 1. |
silent |
Logical (default: FALSE). If |
summary |
Logical (default: TRUE). Produce a summary table. |
misc |
Logical (default: FALSE). Output other unimportant parameters. |
Value
A list.
References
D’Agostino, R.B., 2017. Tests for the Normal Distribution. In: D’Agostino, R.B., Stephens, M.A. (Eds.), Goodness-of-Fit Techniques, 1st ed. Routledge, New York, pp. 372–373. https://doi.org/10.1201/9780203753064
Stephens, M.A., 2017. Tests Based on EDF Statistics. In: D’Agostino, R.B., Stephens, M.A. (Eds.), Goodness-of-Fit Techniques, 1st ed. Routledge, New York, pp. 126–128. https://doi.org/10.1201/9780203753064
Anderson, T.W., Darling, D.A., 1954. A Test of Goodness of Fit. J. Am. Stat. Assoc. 49, 765–769. https://doi.org/10.1080/01621459.1954.10501232
Examples
out <- Anderson_Darling_test(rnorm(10))
print(out$summary)
D'Agostino–Pearson K2 Normality Test
Description
The D'Agostino–Pearson chi-squared (K2) test is a moment-based omnibus test for normality.
Usage
D.Agostino_Pearson_test(
x,
alpha = 0.05,
alternative = c("two.sided", "less", "greater"),
silent = FALSE,
summary = TRUE,
misc = FALSE
)
Arguments
x |
Numeric vector. Must have length at least 20. |
alpha |
Numeric (default: 0.05). Significance level for hypothesis testing. Must be between 0 and 1. |
alternative |
Character (default: "two.sided"). Specifies the alternative hypothesis. Available options are c("two.sided", "less", "greater"). Note that this option is only applied to the skewness and kurtosis components of the test. |
silent |
Logical (default: FALSE). If |
summary |
Logical (default: TRUE). Produce a summary table. |
misc |
Logical (default: FALSE). Output other unimportant parameters. |
Details
It evaluates the null hypothesis that the data come from a normal distribution by combining standardized measures of skewness and kurtosis into a single chi-squared test statistic.
Value
A list
References
D’Agostino, R.B., Belanger, A., D’Agostino, R.B., 1990. A Suggestion for Using Powerful and Informative Tests of Normality. Am. Stat. 44, 316–321. https://doi.org/10.1080/00031305.1990.10475751
Examples
out <- D.Agostino_Pearson_test(rnorm(50))
print(out$summary)
Jarque-Bera Normality Test
Description
Performs the Jarque-Bera chi-squared test, a moment-based omnibus test for assessing normality.
Usage
Jarque_Bera_test(
x,
alpha = 0.05,
alternative = c("two.sided", "less", "greater"),
silent = FALSE,
summary = TRUE
)
Arguments
x |
Numeric vector. Must contain at least 20 observations. |
alpha |
Numeric (default: 0.05). Significance level for hypothesis testing. Must be between 0 and 1. |
alternative |
Character (default: |
silent |
Logical (default: |
summary |
Logical (default: TRUE). Produce a summary table. |
Details
The test evaluates the null hypothesis that the data are drawn from a normal distribution by combining standardized measures of skewness and kurtosis into a single chi-squared test statistic.
Value
A list
References
Jarque, C.M., Bera, A.K., 1987. A Test for Normality of Observations and Regression Residuals. Int. Stat. Rev. 55, 163–172. https://doi.org/10.2307/1403192
See Also
Examples
out <- Jarque_Bera_test(rnorm(50))
print(out$summary)
Lilliefors Normality Test
Description
Performs the Lilliefors normality test, which is an empirical distribution function (EDF)-based goodness-of-fit test derived from the Kolmogorov–Smirnov test, using the approximation proposed by Molin and Abdi (1998).
Usage
Lilliefors_test(x, alpha = 0.05, silent = FALSE, summary = TRUE, misc = FALSE)
Arguments
x |
A numeric vector, at least length of 8. |
alpha |
Numeric (default: 0.05). Significance threshold, range from 0 to 1. |
silent |
Logical (default: FALSE). If |
summary |
Logical (default: TRUE). Produce a summary table. |
misc |
Logical (default: FALSE). Output other unimportant parameters. |
Value
A list.
References
Molin, P., Abdi, H., 1998. New tables and numerical approximation for the Kolmogorov-Smirnov/Lillierfors/Van Soest test of normality. Technical report, University of Bourgogne.
Examples
out <- Lilliefors_test(rnorm(10))
print(out$summary)
Shapiro-Wilk normality test (coefficients)
Description
Coefficients (ai) for the W test for normality.
Usage
Shapiro_Wilk_coef_table
Format
A data frame with 50 rows and 25 variables:
rownames is the sample size (n); colnames is the corresponding coefficients (ai).
References
Shapiro, S.S., Wilk, M.B., 1965. An Analysis of Variance Test for Normality (Complete Samples). Biometrika 52, 591–611. https://doi.org/10.2307/2333709
Shapiro-Wilk normality test (p-values)
Description
The percentage points (critical values of W) of the W test for n = 3(1)50.
Usage
Shapiro_Wilk_pval_table
Format
A data frame with 50 rows and 10 variables:
rownames is the sample size (n); colnames is the corresponding p-values.
References
Shapiro, S.S., Wilk, M.B., 1965. An Analysis of Variance Test for Normality (Complete Samples). Biometrika 52, 591–611. https://doi.org/10.2307/2333709
Shapiro-Wilk Normality Test
Description
Performs the Shapiro–Wilk normality test, which assesses whether a sample originates from a normally distributed population using a regression-based correlation method.
Usage
Shapiro_Wilk_test(
x,
alpha = 0.05,
method = c("SWR", "SF", "SW"),
silent = FALSE,
summary = TRUE,
misc = FALSE,
resampling = TRUE
)
Arguments
x |
A numeric vector. |
alpha |
Significance threshold (default: 0.05). |
method |
Character (default: "SWR"). Use which modification of the test? Available options are c("SWR", "SF", "SW"). |
silent |
Logical (default: FALSE). If |
summary |
Logical (default: TRUE). Produce a summary table. |
misc |
Logical (default: FALSE). Output other unimportant parameters. |
resampling |
Logical (default: TRUE).
If |
Details
method
"SW": Shapiro–Wilk test, the original normality test proposed by Shapiro and Wilk (1965). Applicable only for sample sizes 3 <= n <= 50.
"SF": Shapiro–Francia test, proposed by Shapiro and Francia (1972) and subsequently simplified and extended by Royston (1993). Applicable only for sample sizes 5 <= n <= 5000.
"SWR": Shapiro–Wilk test with Royston's (1992) modifications for approximating the null distribution and extending the test to larger sample sizes. Applicable only for sample sizes 3 <= n <= 5000.
Value
A list.
References
Shapiro, S.S., Wilk, M.B., 1965. An Analysis of Variance Test for Normality (Complete Samples). Biometrika 52, 591–611. https://doi.org/10.2307/2333709
Shapiro, S.S., Francia, R.S., 1972. An Approximate Analysis of Variance Test for Normality. J. Am. Stat. Assoc. 67, 215–216. https://doi.org/10.1080/01621459.1972.10481232
Royston, P., 1993. A pocket-calculator algorithm for the Shapiro–Francia test for non-normality: an application to medicine. Stat. Med. 12, 181–184. https://doi.org/10.1002/sim.4780120209
Royston, P., 1992. Approximating the Shapiro–Wilk W-test for non-normality. Stat. Comput. 2, 117–119. https://doi.org/10.1007/BF01891203
Examples
sw <- Shapiro_Wilk_test(rnorm(20), method = "SW")
print(sw$summary)
sf <- Shapiro_Wilk_test(rnorm(100) ^ 2, method = "SF")
print(sf$summary)
swr <- Shapiro_Wilk_test(rnorm(1e6), method = "SWR")
print(swr$summary)
Normality test
Description
A wrapper function for the normality tests available in this package.
Usage
check_normality(
x,
alpha = 0.05,
silent = FALSE,
summary = TRUE,
method = "SWR",
...
)
Arguments
x |
A numeric vector containing the sample observations. |
alpha |
Numeric (default: |
silent |
Logical (default: |
summary |
Logical (default: |
method |
Character. Abbreviation specifying the normality test to perform.
Available options are |
... |
Additional arguments passed to the selected test function. |
Details
The method argument specifies the statistical procedure used to
assess whether a sample is consistent with a normal distribution.
Different tests emphasize different characteristics of departures
from normality, such as skewness, kurtosis, or discrepancies in the
tails of the distribution. Because no single test performs optimally
under all circumstances, the choice of method may depend on sample
size and the expected type of non-normality.
Available methods are:
-
"AD": Anderson–Darling test. A modification of the empirical distribution function (EDF) approach that gives greater weight to observations in the tails of the distribution. Compared with several alternative normality tests, the Anderson–Darling procedure is often more sensitive to deviations occurring in extreme values and tail behavior. This test is applicable only for sample sizesn >= 8. -
"DAP": D'Agostino–Pearson test. A combined omnibus moment test based on sample skewness and kurtosis. The procedure transforms the skewness and kurtosis statistics into approximately standard normal variables and combines them into a single test statistic. This method is designed to detect a broad range of departures from normality rather than emphasizing any particular feature. This test is applicable only for sample sizesn >= 20. -
"JB": Jarque–Bera test. An omnibus moment test based on sample skewness and kurtosis. The test evaluates whether the observed skewness and kurtosis differ significantly from the values expected under a normal distribution. The method is commonly used in econometrics and is generally more appropriate for moderate to large sample sizes. -
"LF": Lilliefors test. The Lilliefors test is an EDF omnibus test modified from Kolmogorov-Smirnov test for the composite hypothesis of normality. The test statistic is the maximal absolute difference between empirical and hypothetical cumulative distribution function. -
"SW": Shapiro–Wilk test. The original normality test proposed by Shapiro and Wilk (1965), based on the correlation between ordered observations and their expected values under normality. It is widely regarded as one of the most powerful tests for detecting departures from normality in small samples. Applicable only for sample sizes3 <= n <= 50. -
"SF": Shapiro–Francia test. Proposed by Shapiro and Francia (1972) and subsequently simplified and extended by Royston (1993). This method is a computationally simpler modification of the Shapiro–Wilk procedure that performs particularly well for detecting departures associated with heavier-tailed distributions. Applicable only for sample sizes5 <= n <= 5000. -
"SWR": Shapiro–Wilk test with Royston's modifications. Uses Royston's (1992) approximations for the null distribution of the Shapiro–Wilk statistic and extends applicability to larger samples while maintaining behavior similar to the original test. Applicable only for sample sizes3 <= n <= 5000.
In all methods, the null hypothesis is that the sample is drawn from a normal distribution. Small p-values indicate evidence against the assumption of normality.
Value
A list.
Examples
out_AD <- check_normality(rnorm(20), method = "AD")
out_DAP <- check_normality(rnorm(20), method = "DAP")
out_SW <- check_normality(rnorm(20), method = "SW")
Normality test
Description
A handy wrapper for data normality assessment using the Shapiro-Wilk-Royston, D'Agostino-Pearson, and Anderson-Darling tests.
Usage
is_normal(data, formula = NULL, alpha = 0.05, sensitivity = 2, summary = FALSE)
Arguments
data |
A data frame or a numeric vector. |
formula |
Formula (default: NULL).
If |
alpha |
Significance threshold, range from 0 to 1 (default: 0.05). |
sensitivity |
Numeric, range from 1 to 3 (default: 2). The greater the value, the greater chance to consider as non-normal. |
summary |
Logical (default: FALSE). If |
Value
A boolean value (or a list if summary = TRUE).
Examples
is_normal(iris, Sepal.Length ~ Species)
Tied data
Description
Tied data
Usage
is_tied(x, ratio = 0.3, remove_NA = FALSE)
Arguments
x |
A numeric vector |
ratio |
Numeric (default: 0.3). The ratio threshold of being considred as tied-data. The value range from 0 to 1. |
remove_NA |
Logical (default: TRUE). Whether or not to remove NAs. |
Value
Logical
Examples
is_tied(c(1, 1, 2, 2, 2, 3, 4, 5))
#> TRUE
Kurtosis test
Description
Performs a kurtosis test to assess whether a distribution deviates from normality in terms of tail heaviness.
Usage
kurtosis(
x,
alpha = 0.05,
alternative = c("two.sided", "less", "greater"),
method = c("G2", "b2", "g2"),
silent = FALSE,
summary = TRUE
)
Arguments
x |
Numeric vector containing the input data. |
alpha |
Numeric (default: 0.05). Significance level for hypothesis testing. Must be between 0 and 1. |
alternative |
Character (default: "two.sided"). Specifies the alternative hypothesis. Available options are c("two.sided", "less", "greater"). |
method |
Character (default: "G2"). Formula used to estimate kurtosis. Available options are c("G2", "b2", "g2"). The "g2" statistic is the classical sample kurtosis estimator, while "G2" and "b2" are bias-corrected versions of "g2". |
silent |
Logical (default: FALSE). If |
summary |
Logical (default: TRUE). Produce a summary table. |
Details
The test evaluates the null hypothesis that the population kurtosis is equal to 3, which is the kurtosis of a normal distribution. Values significantly different from 3 indicate deviations from normality, such as heavy-tailed or light-tailed behavior.
Value
A list
References
Joanes, D.N., Gill, C.A., 1998. Comparing measures of sample skewness and kurtosis. J. R. Stat. Soc. D (The Statistician) 47, 183–189. https://doi.org/10.1111/1467-9884.00122
Wright, D.B., Herrington, J.A., 2011. Problematic standard errors and confidence intervals for skewness and kurtosis. Behav. Res. Methods 43, 8–17. https://doi.org/10.3758/s13428-010-0044-x
Examples
x <- c(10:17, 12, 12, 13, 13, 13, 13, 13, 14, 14, 14, 15, 15)
kurtosis(x)
Standard output format
Description
The standard output format for normality package.
Usage
normality_standard_output(
method = "what test?",
is_normal = NA,
alpha = NA_real_,
alternative = c("two.sided", "less", "greater"),
summary = NULL,
statistic = NA_real_,
pvalue = NA_real_,
misc = NULL
)
Arguments
method |
Character. The name of the test. |
is_normal |
Logical. Is the input data normally distributed? |
alpha |
Numeric (default: 0.05). Significance threshold. |
alternative |
Character. The alternative hypothesis (H1) to test. Available options are c("two.sided", "less", "greater"). |
summary |
Statistic summary, if any. |
statistic |
Numeric. The value used to calculate p-value. |
pvalue |
Numeric. The p-value of the test. |
misc |
List. Miscellaneous elements. |
Value
A list.
Skewness test
Description
The test evaluates whether the population skewness is equal to zero. Under the null hypothesis, the data are assumed to originate from a symmetric distribution. Significant positive or negative skewness indicates asymmetry in the distribution and may suggest a departure from normality.
Usage
skewness(
x,
alpha = 0.05,
alternative = c("two.sided", "less", "greater"),
method = c("G1", "b1", "g1"),
silent = FALSE,
summary = TRUE
)
Arguments
x |
Numeric vector containing the input data. |
alpha |
Numeric (default: 0.05). Significance level for hypothesis testing. Must be between 0 and 1. |
alternative |
Character (default: "two.sided"). Specifies the alternative hypothesis. Available options are c("two.sided", "less", "greater"). |
method |
Character (default: "G1"). Formula used to estimate skewness. Available options are c("G1", "b1", "g1"). The "g1" statistic is the conventional moment-based sample skewness. The "G1" and "b1" statistics apply finite-sample corrections to reduce the bias of "g1". |
silent |
Logical (default: FALSE). If |
summary |
Logical (default: TRUE). Produce a summary table. |
Value
A list
References
Joanes, D.N., Gill, C.A., 1998. Comparing measures of sample skewness and kurtosis. J. R. Stat. Soc. D (The Statistician) 47, 183–189. https://doi.org/10.1111/1467-9884.00122
Wright, D.B., Herrington, J.A., 2011. Problematic standard errors and confidence intervals for skewness and kurtosis. Behav. Res. Methods 43, 8–17. https://doi.org/10.3758/s13428-010-0044-x
Examples
skewness(rnorm(30))